-
Hello again,
it might not be related to my previous post which is why I created another one.
StorageFile.read() seems to always expect a
length
argument - but how do I then read a whole file? there is nosize
method?But there is another problem: when I try
const Storage = require('Storage'); function compareFileWith (expectedContent) { let readText = Storage.open('4testing','r').read(1000); if (readText != expectedContent) { print('>>>> file does not look as expected'); print('>>>> expected "' + expectedContent + '"'); print('>>>> got "' + readText + '"'); } } /**** create file ****/ if (Storage.write('4testing','Hello, World!')) { print('file "4testing" was successfully created'); } else { print('file "4testing" could not be created'); } compareFileWith('Hello, World!'); print('finished');
the file "4testing" is successfully created - but reading it using
StorageFile.read
produces a strange result:file "4testing" was successfully created >>>> file does not look as expected >>>> expected "Hello, World!" >>>> got "4testing4testing4testing" finished
What am I doing wrong?
BTW: I am using the "cutting edge" distribution of today
-
Good morning!
I still have my problems working with StorageFiles.
When I try
const Storage = require('Storage'); function compareFileWith (expectedContent) { let readText = Storage.open('4testing','r').read(); if (readText != expectedContent) { print('>>>> file does not look as expected'); print('>>>> expected "' + expectedContent + '"'); print('>>>> got "' + readText + '"'); } } /**** create file ****/ let TestFile = Storage.open('4testing','w'); if (TestFile.write('4testing','Hello, World!')) { print('file "4testing" was successfully created'); } else { print('file "4testing" could not be created'); } compareFileWith('Hello, World!'); print('finished');
I only get the following output
file "4testing" could not be created >>>> file does not look as expected >>>> expected "Hello, World!" >>>> got "undefined" finished
Thus, how can I create a new file if I must not mix Storage methods with StorageFile ones?
-
-
Just to let you know: I've meanwhile uploaded my rerendered web pages with notes on the Bangle.js.
If you find any mistakes or have any other complaints, please tell me.
I still have to translate all that stuff, though.
-
-
-
I do not seem to be able to read a file after opening it - what am I doing wrong?
const Storage = require('Storage'); function compareFileWith (expectedContent) { if (''+Storage.read('4testing') !== expectedContent) { print('>>>> file does not look as expected'); print('>>>> expected "' + expectedContent + '"'); print('>>>> got "' + Storage.read('4testing') + '"'); } } /**** create file ****/ if (Storage.write('4testing','Hello, World!')) { print('file "4testing" was successfully created'); } else { print('file "4testing" could not be created'); } compareFileWith('Hello, World!'); let TestFile; /**** read file ****/ TestFile = Storage.open('4testing','r'); let readText = TestFile.read(4); if (readText !== 'Hello') { print('>>>> reading "4testing" failed'); print('>>>> expected "Hello", got "' + readText + '"'); }
readText
turns out to beundefined
-
That's what looked so weird: "!==" was true (mind the extra "=" which means "without any conversion"), but when comparing lengths and character codes, everything was equal.
Thus, I could
- not compare the outcome of Storage.read with a string, but
- use .length and .charCodeAt of the outcome of Storage.read without any problems and
- compare the outcome of Storage.read with a string after appending to ''
- not compare the outcome of Storage.read with a string, but
-
Well,
I just found a solution: if I replace
if (Storage.read('4testing') !== FileContent_1) {
by
if (''+Storage.read('4testing') !== FileContent_1) {
(and similar for the second read operation) everything runs as expected...
@Gordon may it be that I found a severe bug?
-
Good morning!
I must be completely blind or dumb in a different way, but when I write a string into a file, read it back into another string and then compare both strings with "!==", they are reported as different!
Then, if I compare them character by character, no difference is found (as expected).
Does anybody have a solution for this puzzle?
The gist may be directly loaded and run on a connected watch through the IDE. Here comes the code:
const Storage = require('Storage'); function compareStrings (Original,Candidate) { let OriginalLength = Original.length; let CandidateLength = Candidate.length; if (CandidateLength > OriginalLength) { print('>>>> more characters read than written'); print('>>>> first additional character: ' + Candidate.charCodeAt(OriginalLength)); return; } if (CandidateLength < OriginalLength) { print('>>>> less characters read than written'); print('>>>> first missing character: ' + Original.charCodeAt(CandidateLength)); return; } for (let i = 0; i < OriginalLength; i++) { if (Original[i] !== Candidate[i]) { print('>>>> different characters read than written'); print('>>>> first mismatch at #' + i + ': expected ' + Original.charCodeAt(i) + ', got ' + Candidate.charCodeAt(i)); return; } } print('>>>> same characters read as written'); } const FileContent_1 = 'this file exists for testing purposes only'; const FileContent_2 = 'this file still exists for testing purposes only'; if (Storage.write('4testing',FileContent_1)) { print('file "4testing" was successfully created'); } else { print('file "4testing" could not be written'); } if (Storage.read('4testing') !== FileContent_1) { print('contents of file "4testing" do not look as expected'); print('(namely "' + Storage.read('4testing') + '")'); compareStrings(FileContent_1,Storage.read('4testing')); } if (Storage.write('4testing',FileContent_2)) { print('file "4testing" was successfully overwritten'); } else { print('file "4testing" could not be overwritten'); } if (Storage.read('4testing') !== FileContent_2) { print('contents of file "4testing" do no longer look as expected'); print('(namely "' + Storage.read('4testing') + '")'); compareStrings(FileContent_2,Storage.read('4testing')); } Storage.erase('4testing'); print('file "4testing" has finally been deleted');
-
Hmm, let me see if I can find a better solution. The technical trick behind those folded sections is that they do not require any JavaScript. I.e., you will get the same experience even with JavaScript disabled.
In addition, I will also have to find a solution for smartphones and tablets which do not have the notion of "hovering".
Ok, I just added some downwards pointing triangles to the chips and removed the cursor from expanded sections - better now?
-
Hovering - good idea!
Ok, try and reload the main page for Bangle.js - those "chips" now show a "pointer" cursor when hovering over them.
Again, the other pages will follow tomorrow.
-
Ok, try and reload the main page for Bangle.js - what do you think? I can definitely live with that color choice.
The other pages will follow by tomorrow.
-
You mean the gray "chips" you may click on?
Well, actually I wanted them to stay a bit away from ordinary text to give you kind of a TL;DR when collapsed and more details when expanded.
Let me see what I can do about the contrast. Wait for an announcement in this thread to check again.
Thanks anyway for the positive review!
-
-
-
-
Good morning!
My intent is to get a screenshot of the emulated Bangle.js display only, not an entire PC screen or an entire browser window.
To illustrate it a bit: my current approach is:
- load Bangle.js emulator
- open browser console
run the following command
$('<a id="ScreenshotButton" class="icon-save lrg"></a>').on('click', () => { window.open('','Bangle.js Emulator Screenshot').document.write('<a href="' + $('#gfxcanvas')[0].toDataURL().replace(/^data:image\/png/,'data:application/octet-stream') + '" download="Bangle-Screenshot.png">click to download</a>') }).insertAfter('#icon-clearScreen');
This adds another button on the left side (with a floppy disk icon) which, when pressed, opens a new tab with a download link. Clicking that link saves the requested screenshot to disk.
That's definitely a hacker-like approach - but it gives me the possibility to quickly get screenshots of running Bangle.js programs...
- load Bangle.js emulator
-
Hopefully, its not so "ridiculous"...
But, to be honest, I have my own kind of Wiki which makes generating and maintaining my web site (hopefully) relatively easy.
And, concerning the contents: it's so incredibly (ridiculously?) easy to work with the Bangle.js, that it's just fun to produce these contents (and I have by no means documented everything yet!)
How's your family?
-
In the last few days I had some spare time - so I played around with my developer unit and wrote down what I did and found.
If anyone is interested, look at my web page related to Bangle.js. It's currently in German, but I hope to be able to translate it until end of this week.
Kudos to Gordon for his marvellous work - it's fun working with Bangle.js!
-
-
-
-
Hello!
In order to produce screenshots, I tried to read the contents of the screen, pixel per pixel.
But when I try
g.setPixel(0,0, 14); print(g.getPixel(0,0));
all I receive is 0 - when running in resolutions 240x240 and 240x160 (aka 'doublebuffered')
How can I get the contents of a higher resolving display?
Oops - I found my mistake: I should replace
with
shouldn't I?
Sorry for bothering you!