I'm trying to see if I can develop a minimal pedometer widget based on using Bangle.getHealthStatus("day").steps
Minimal in the sense that it does 1 thing really well, no settings, simple code that will avoid dependancies. Also want the lowest power drain whilst being useful.
My code appears to be working but am noticing a few issues:
1) If you reboot (long BTN1 reset) then Bangle.getHealthStatus("day").steps resets to 0 - you have lost your days step count. This does not happen with widpedom with stores the stepcount to storage using the on.('kill') event.
2) Noticing throughout the day that Bangle.getHealthStatus("day").steps is a 10, 20, 30 steps ahead of widpedom, this could be me doing lots of code installs , resets etc. To really observe properly I will need to soak test it on a watch that I do nothing but wear for 36-48 hours.
3) I am showing a 6x8 font version below, but I really want to a nicer small font. Lato comes out at about 500 bytes - which is quite large, even just with the numeric numbers only. What are the factors that mean a font comes out low in bytes - is this just trial and error ?
4) @ Gordon - is calling Bangle.drawWidgets() - safe in the draw function ? I copied it from widpedom. I tried running from setTimeout that lead to issues.
5) Is it better to use setInterval(...) or Bangle.on('step',) to trigger redraws.
setInterval will be predictive, but will it still draw when the LCD is off on a Bangle 1?
Bangle.on('step',) will redraw when LCD is as well ?
I am looking for simplest, lowest power drain solution.
setInterval(()=>WIDGETS["bata"].draw(), 5000);
Bangle.on('lcdPower', function(on) {
if (on) WIDGETS["bata"].draw();
});
WIDGETS["bata"]={area:"tl",width:12,draw:function() {
var steps = Bangle.getHealthStatus("day").steps;
var w = (steps.toString().length)*12;
if (w > this.width) {this.width = w; Bangle.drawWidgets();}
g.reset();
g.setColor(g.theme.bg);
g.fillRect(this.x, this.y, this.x + this.width, this.y + 23); // erase background
g.setColor(g.theme.fg);
g.setFont('6x8',2);
g.setFontAlign(-1, 0);
g.drawString(steps, this.x, this.y + 12);
}};
Note in the above code I have just hijacked widbata so I dont have to wait for the App Loader to update after a push.
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.
I'm trying to see if I can develop a minimal pedometer widget based on using
Bangle.getHealthStatus("day").steps
Minimal in the sense that it does 1 thing really well, no settings, simple code that will avoid dependancies. Also want the lowest power drain whilst being useful.
My code appears to be working but am noticing a few issues:
1) If you reboot (long BTN1 reset) then Bangle.getHealthStatus("day").steps resets to 0 - you have lost your days step count. This does not happen with widpedom with stores the stepcount to storage using the on.('kill') event.
2) Noticing throughout the day that Bangle.getHealthStatus("day").steps is a 10, 20, 30 steps ahead of widpedom, this could be me doing lots of code installs , resets etc. To really observe properly I will need to soak test it on a watch that I do nothing but wear for 36-48 hours.
3) I am showing a 6x8 font version below, but I really want to a nicer small font. Lato comes out at about 500 bytes - which is quite large, even just with the numeric numbers only. What are the factors that mean a font comes out low in bytes - is this just trial and error ?
4) @ Gordon - is calling Bangle.drawWidgets() - safe in the draw function ? I copied it from widpedom. I tried running from setTimeout that lead to issues.
5) Is it better to use setInterval(...) or Bangle.on('step',) to trigger redraws.
setInterval will be predictive, but will it still draw when the LCD is off on a Bangle 1?
Bangle.on('step',) will redraw when LCD is as well ?
I am looking for simplest, lowest power drain solution.
Note in the above code I have just hijacked widbata so I dont have to wait for the App Loader to update after a push.