diff --git a/apps.json b/apps.json index 2e338a432..bca8d6cbd 100644 --- a/apps.json +++ b/apps.json @@ -4557,5 +4557,20 @@ { "name": "sensible.app.js", "url": "sensible.js" }, { "name": "sensible.img", "url": "sensible-icon.js", "evaluate": true } ] -} +}, + { + "id": "widbars", + "name": "Bars Widget", + "version": "0.01", + "description": "Display several measurements as vertical bars.", + "icon": "icon.png", + "screenshots": [{"url":"screenshot.png"}], + "readme": "README.md", + "type": "widget", + "tags": "widget", + "supports": ["BANGLEJS","BANGLEJS2"], + "storage": [ + {"name":"widbars.wid.js","url":"widget.js"} + ] + } ] diff --git a/apps/widbars/ChangeLog b/apps/widbars/ChangeLog new file mode 100644 index 000000000..4c21f3ace --- /dev/null +++ b/apps/widbars/ChangeLog @@ -0,0 +1 @@ +0.01: New Widget! diff --git a/apps/widbars/README.md b/apps/widbars/README.md new file mode 100644 index 000000000..eba5cc347 --- /dev/null +++ b/apps/widbars/README.md @@ -0,0 +1,14 @@ +# Bars Widget + +A simple widget that display several measurements as vertical bars. + +![Screenshot](screenshot.png) + +## Measurements from left to right: + +- Current heart rate, on a scale from 0-200 bpm (*red*)
+ Only if available: this widget does not turn on HRM monitoring by itself. +- Device temperature, on a scale from 0-50 °C (*yellow*) +- Flash storage space used (*blue/cyan*) +- Memory usage (*magenta*) +- Battery charge (*green*) \ No newline at end of file diff --git a/apps/widbars/icon.png b/apps/widbars/icon.png new file mode 100644 index 000000000..59f78d666 Binary files /dev/null and b/apps/widbars/icon.png differ diff --git a/apps/widbars/screenshot.png b/apps/widbars/screenshot.png new file mode 100644 index 000000000..146e085e3 Binary files /dev/null and b/apps/widbars/screenshot.png differ diff --git a/apps/widbars/widget.js b/apps/widbars/widget.js new file mode 100644 index 000000000..18d1712c6 --- /dev/null +++ b/apps/widbars/widget.js @@ -0,0 +1,62 @@ +(() => { + const h=24, // widget height + w=3, // width of single bar + bars=3; // number of bars + + // We show HRM if available, but don't turn it on + let bpm,rst,con=10; // always ignore HRM with confidence below 10% + function noHrm() { // last value is no longer valid + if (rst) clearTimeout(rst); + rst=bpm=undefined; con=10; + WIDGETS["bars"].draw(); + } + Bangle.on('HRM', hrm=>{ + if (hrm.confidence>con || hrm.confidence>=80) { + bpm=hrm.confidence; + con=hrm.confidence; + WIDGETS["bars"].draw(); + if (rst) clearTimeout(rst); + rst = setTimeout(noHrm, 10*60*1000); // forget HRM after 10 minutes + } + }); + + /** + * Draw a bar + * + * @param {int} x left + * @param {int} y top (of full bar) + * @param {string} col Color + * @param {number} f Fraction of bar to draw + */ + function bar(x,y, col,f) { + if (!f) f = 0; // for f=NaN: set it to 0 -> don't even draw the bottom pixel + if (f>1) f = 1; + if (f<0) f = 0; + const top = Math.round((h-1)*(1-f)); + // use Math.min/max to make sure we stay within widget boundaries for f=0/f=1 + if (top) g .clearRect(x,y, x+w-1,y+top-1); // erase above bar + if (f) g.setColor(col).fillRect(x,y+top, x+w-1,y+h-1); // even for f=0.001 this is still 1 pixel high + } + function draw() { + g.reset(); + const x = this.x, y = this.y, + m = process.memory(); + let b=0; + bar(x+(w*b++),y,'#f00'/*red */,bpm/200); // >200 seems very unhealthy; if we have no valid bpm this will just be empty space + bar(x+(w*b++),y,'#ff0'/*yellow */,E.getTemperature()/50); // you really don't want to wear a watch that's hotter than 50°C + bar(x+(w*b++),y,g.theme.dark?'#0ff':'#00f'/*cyan/blue*/,1-(require('Storage').getFree() / process.env.STORAGE)); + bar(x+(w*b++),y,'#f0f'/*magenta*/,m.usage/m.total); + bar(x+(w*b++),y,'#0f0'/*green */,E.getBattery()/100); + } + + let redraw; + Bangle.on('lcdPower', on => { + if (redraw) clearInterval(redraw) + redraw = undefined; + if (on) { + WIDGETS["bars"].draw(); + redraw = setInterval(()=>WIDGETS["bars"].draw, 10*1000); // redraw every 10 seconds + } + }); + WIDGETS["bars"]={area:"tr",width: bars*w,draw:draw}; +})()