getStats gives you a bunch of other info, not just free space.
getStats/getFree can be slow since it scans all of storage to work out how much data there is - maybe think about just calling it every minute, or even better call it once at startup to work out how much free there is, and keep track of how much you're writing. It won't be exact because there can be some overheads but since you're leaving 0.75MB of leeway you'll be fine
It's worth doing as few calls to .write as possible to make it a bit faster - so try and do rawData.write([....].map((o)=>parseInt(o*1000)/1000).join(",")+"\n");
So maybe more like:
var memory = require("Storage").getFree();
Bangle.on('HRM-raw', function(hrm) {
// ...
var line = [Math.floor(Date.now()),a.x,a.y,a.z,c.x,c.y,c.z,c.dx,c.dy,c.dz,hrm.raw,hrm.filt,hrm.bpm,hrm.confidence].map((o)=>parseInt(o*1000)/1000).join(",")+"\n";
memory -= line.length;
rawData.write(line);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Looks like @rigrig's got you sorted.
Just some notes though:
getStats
gives you a bunch of other info, not just free space.getStats/getFree
can be slow since it scans all of storage to work out how much data there is - maybe think about just calling it every minute, or even better call it once at startup to work out how much free there is, and keep track of how much you're writing. It won't be exact because there can be some overheads but since you're leaving 0.75MB of leeway you'll be fine.write
as possible to make it a bit faster - so try and dorawData.write([....].map((o)=>parseInt(o*1000)/1000).join(",")+"\n");
So maybe more like: