diff --git a/apps/widdevst/ChangeLog b/apps/widdevst/ChangeLog new file mode 100644 index 000000000..7f837e50e --- /dev/null +++ b/apps/widdevst/ChangeLog @@ -0,0 +1 @@ +0.01: First version diff --git a/apps/widdevst/README.md b/apps/widdevst/README.md new file mode 100644 index 000000000..49affc78d --- /dev/null +++ b/apps/widdevst/README.md @@ -0,0 +1,15 @@ +# Device Status Widget + +This widget shows a rectangle containing + +- `B` if Bluetooth is on +- `C` if the compass is on +- `G` if GPS is on +- `H` if the heart rate monitor is on + +at fixed positions, and two bars + +- left to right: usage of Flash storage +- bottom to top: usage of RAM + +in green if below 50%, orange if between 50% and 80%, and red if above 80%. diff --git a/apps/widdevst/icon.png b/apps/widdevst/icon.png new file mode 100644 index 000000000..be242e1e1 Binary files /dev/null and b/apps/widdevst/icon.png differ diff --git a/apps/widdevst/metadata.json b/apps/widdevst/metadata.json new file mode 100644 index 000000000..41cbdc028 --- /dev/null +++ b/apps/widdevst/metadata.json @@ -0,0 +1,13 @@ +{ "id": "widdevst", + "name": "Device Status Widget", + "version": "0.01", + "description": "Shows power status of Bluetooth, Compass, GPS and Heart Rate Monitor as well as storage and memory usage.", + "icon": "icon.png", + "type": "widget", + "tags": "widget,bluetooth,compass,gps,hrm", + "supports": ["BANGLEJS"], + "readme": "README.md", + "storage": [ + {"name": "widdevst.wid.js", "url": "wid.js"} + ] +} diff --git a/apps/widdevst/wid.js b/apps/widdevst/wid.js new file mode 100644 index 000000000..9920be404 --- /dev/null +++ b/apps/widdevst/wid.js @@ -0,0 +1,34 @@ +(() => { + WIDGETS.stat = {area: "tr", width: 21, draw: function() { + var x = this.x; + var y = this.y; + g.reset(); + g.clearRect(x, y, x + 20, y + 23); + g.drawRect(x + 1, y + 1, x + 19, y + 22); + g.setFont('6x8', 1); + if (NRF.getSecurityStatus().connected) g.drawString('B', x + 4, y + 3); + if (Bangle.isCompassOn()) g.drawString('C', x + 12, y + 3); + if (Bangle.isGPSOn()) g.drawString('G', x + 4, y + 13); + if (Bangle.isHRMOn()) g.drawString('H', x + 12, y + 13); + var t = require('Storage').getStats(); + var u = t.fileBytes / t.totalBytes; + g.setColor(col(u)); g.drawRect(x + 1, y + 22, x + 1 + u * 18, y + 23); + t = process.memory(false); + u = t.usage / t.total; + g.setColor(col(u)); g.drawRect(x, y + 22 - u * 21, x + 1, y + 22); + }}; + + function col(p) { + return p < 0.5 ? '#0f0' : (p < 0.8 ? '#f80' : '#f00'); + } + + var draw = WIDGETS.stat.draw.bind(WIDGETS.stat); + var iid = setInterval(draw, 2000); + + Bangle.on('lcdPower', (on) => { + if (on) { + draw(); + if (!iid) iid = setInterval(draw, 2000); + } else if (iid) iid = clearInterval(iid); + }); +})();