-
• #2
If you're writing binary data into a file with an offset, you need to tell Espruino the size of the file you want first so it can allocate space - see https://www.espruino.com/Reference#l_Storage_write
What you were doing storing individual files for acceleration data looks good - I guess it's just the hit of loading the data back.
One thing you might want to consider is to encode the arrays as base64 and put that in JSON with
btoa(accelx.buffer)
and thennew Int16Array(E.toArrayBuffer(atob(str)))
.The reason is that Espruino stores arrays way more efficiently in IntXArrays, but when you write to JSON it has to convert those arrays into normal JS arrays, which use a lot more memory. If you write as base64 it avoids all that and will load everything far more efficiently.
-
• #3
True, I can save the temporary throw as base64 format.
The problem is that, if I want to use offset option, I have to know how big the csv file will be. I understood that if I don't define the file size in the beginning, then I can't use offset option, right? I think, I need to estimate its size and make it big enough.
-
• #4
I understood that if I don't define the file size in the beginning, then I can't use offset option, right?
Correct, yes. However if you were to write the raw buffer from the Uint16Array I guess you know its size? 3 buffers of 2*SAMPLES bytes?
But if you're planning on writing CSV maybe check out StorageFile - that provides a file that you can keep appending to (but it's text only, not binary): https://www.espruino.com/Reference#StorageFile
The problem with writing CSV is you have to be able to load it back in - if you do
str.split(",")
that's going to create a huge array of numbers anyway, which is pretty much the same as using JSON.parse -
• #5
Thanks, the StrageFile solved that problem. Now back to testing.
-
• #6
Now I have made first throw app. Can you guys give me a feedback, how to make it smoother or faster or better? Here is link to my repo https://github.com/pinq-/BangleApps/blob/master/apps/Kyykka_throw/Kyykka.app.js
So I'm building this throwing app and I have option, that you can record every throws acceleration data, if you want. The record is 2 s long and every axis has a 200 points.
This is not yet a problem, the problem is how to save this data. In one game you can have 20-30 throws, so I can not store all the throws in a array. If I just push all throw data to a array, I will run out of memory. So that's not an option.
Now I'm trying to save every throw to json file and at the end of the game, the throw app will collect all the json files and write that to the one csv file.
But I will have the same problem: if I read all the json files, I need to temporarily hold the data somewhere, before I write the csv file. So thats not good option also.
Now I'm trying to out this "offset" option on the write file, maybe that is my solution. I will past my code in here. I know it doesn't work yet, because I misunderstood "offset" option in write command.
But before I continue, is this the right ( only?) solution or is there a better way?