diff --git a/apps.json b/apps.json index 28798fa12..94609831a 100644 --- a/apps.json +++ b/apps.json @@ -2880,5 +2880,17 @@ {"name":"helloworld.app.js","url":"app.js"}, {"name":"helloworld.img","url":"app-icon.js","evaluate":true} ] +}, +{ "id": "widcom", + "name": "Compass Widget", + "icon": "widget.png", + "version":"0.01", + "description": "Tiny widget to show the power on/off status of the Compass. Requires firmware v2.08.167 or later", + "tags": "widget, compass", + "type":"widget", + "readme": "README.md", + "storage": [ + {"name":"widcom.wid.js","url":"widget.js"} + ] } ] diff --git a/apps/widcom/README.md b/apps/widcom/README.md new file mode 100644 index 000000000..1e45d9090 --- /dev/null +++ b/apps/widcom/README.md @@ -0,0 +1,11 @@ +# Compass Power Status Widget + +A simple widget that shows the on/off status of the compass. + +The compass draws around 1mA when on. Whilst this is not a big draw +on the battery it is still easy to have it switched on and not be +aware. + +- Uses Bangle.isCompassOn(), requires firmware v2.08.167 or later +- Shows in grey when the compass is off +- Shows in amber when the compass is on diff --git a/apps/widcom/widget.js b/apps/widcom/widget.js new file mode 100644 index 000000000..b9c911dbf --- /dev/null +++ b/apps/widcom/widget.js @@ -0,0 +1,30 @@ +(function(){ + //var img = E.toArrayBuffer(atob("FBSBAAAAAAAAA/wAf+AP/wH/2D/zw/w8PwfD9nw+b8Pg/Dw/w8/8G/+A//AH/gA/wAAAAAAA")); + //var img = E.toArrayBuffer(atob("GBiBAAB+AAP/wAeB4A4AcBgAGDAADHAADmABhmAHhsAfA8A/A8BmA8BmA8D8A8D4A2HgBmGABnAADjAADBgAGA4AcAeB4AP/wAB+AA==")); + var img = E.toArrayBuffer(atob("FBSBAAH4AH/gHAODgBwwAMYABkAMLAPDwPg8CYPBkDwfA8PANDACYABjAAw4AcHAOAf+AB+A")); + + function draw() { + g.reset(); + if (Bangle.isCompassOn()) { + g.setColor(1,0.8,0); // on = amber + } else { + g.setColor(0.3,0.3,0.3); // off = grey + } + g.drawImage(img, 10+this.x, 2+this.var); + } + + var timerInterval; + Bangle.on('lcdPower', function(on) { + if (on) { + WIDGETS.compass.draw(); + if (!timerInterval) timerInterval = setInterval(()=>WIDGETS.compass.draw(), 2000); + } else { + if (timerInterval) { + clearInterval(timerInterval); + timerInterval = undefined; + } + } + }); + + WIDGETS.compass={area:"tr",width:24,draw:draw}; +})(); diff --git a/apps/widcom/widget.png b/apps/widcom/widget.png new file mode 100644 index 000000000..6c50374a3 Binary files /dev/null and b/apps/widcom/widget.png differ