- added app widdevst

pull/2583/head
notEvil 2023-02-19 12:53:07 +01:00
parent 716af7c18b
commit 01eeff6fe4
5 changed files with 63 additions and 0 deletions

1
apps/widdevst/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: First version

15
apps/widdevst/README.md Normal file
View File

@ -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%.

BIN
apps/widdevst/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -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"}
]
}

34
apps/widdevst/wid.js Normal file
View File

@ -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);
});
})();