Merge pull request #3397 from bobrippling/feat/widdevst-drawing
widdevst: add ability to only redraw when a peripheral changes This change tweaks the drawing of `widdevst` to be fired by a change of a peripheral (such as a HRM event), so that: - if peripherals are on, it'll redraw as regularly as it did before this change - if periperhals are off, it'll redraw at the same (lower) frequency, or possibly not at all if the next option is enabled (saving draw time & battery) The setting change allows us to configure the widget to only draw when a peripheral changes, at the cost of not having directly up-to-date bars for storage & memory.master
commit
95a57aa4e1
|
|
@ -1,3 +1,4 @@
|
||||||
0.01: First version
|
0.01: First version
|
||||||
0.02: Support for Bangle.js 2
|
0.02: Support for Bangle.js 2
|
||||||
0.03: Update storage usage and perform GC every minute
|
0.03: Update storage usage and perform GC every minute
|
||||||
|
0.04: Add ability to only redraw when a peripheral state changes
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,7 @@ at fixed positions, and two bars
|
||||||
- bottom to top: usage of RAM
|
- bottom to top: usage of RAM
|
||||||
|
|
||||||
in green if below 50%, orange if between 50% and 80%, and red if above 80%.
|
in green if below 50%, orange if between 50% and 80%, and red if above 80%.
|
||||||
|
|
||||||
|
The widget will redraw more frequently when unlocked.
|
||||||
|
|
||||||
|
It can be configured to avoid redrawing if all monitored peripherals are off, waiting until it hears from them (meaning you won't see regular RAM/Storage updates, but save battery by avoiding drawing). This can be configured by writing `{"redrawBars":0}` to `widdevst.settings.json`.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{ "id": "widdevst",
|
{ "id": "widdevst",
|
||||||
"name": "Device Status Widget",
|
"name": "Device Status Widget",
|
||||||
"version": "0.03",
|
"version": "0.04",
|
||||||
"description": "Shows power status of Bluetooth, Compass, GPS and Heart Rate Monitor as well as storage and memory usage.",
|
"description": "Shows power status of Bluetooth, Compass, GPS and Heart Rate Monitor as well as storage and memory usage.",
|
||||||
"icon": "icon.png",
|
"icon": "icon.png",
|
||||||
"type": "widget",
|
"type": "widget",
|
||||||
|
|
@ -9,5 +9,8 @@
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name": "widdevst.wid.js", "url": "wid.js"}
|
{"name": "widdevst.wid.js", "url": "wid.js"}
|
||||||
|
],
|
||||||
|
"data":[
|
||||||
|
{"name": "widdevst.settings.json"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
(() => {
|
(() => {
|
||||||
var stat = {date: 0};
|
var stat = {date: 0};
|
||||||
|
var d = Date.now();
|
||||||
|
var settings = require("Storage").readJSON("widdevst.settings.json", 1)||{};
|
||||||
|
var redrawBars = "redrawBars" in settings ? settings.redrawBars : false;
|
||||||
|
delete settings;
|
||||||
|
|
||||||
WIDGETS.devst = {area: "tr", width: 22, draw: function() {
|
WIDGETS.devst = {area: "tr", width: 22, draw: function() {
|
||||||
|
d = Date.now();
|
||||||
if (WIDGETS.devst._draw) return;
|
if (WIDGETS.devst._draw) return;
|
||||||
var d = new Date();
|
|
||||||
var t;
|
var t;
|
||||||
if ((d - stat.date) < 6e4) {
|
if ((d - stat.date) < 6e4) {
|
||||||
t = process.memory(false);
|
t = process.memory(false);
|
||||||
|
|
@ -20,12 +24,15 @@
|
||||||
g.clearRect(x, y, x + 21, y + 23);
|
g.clearRect(x, y, x + 21, y + 23);
|
||||||
g.drawRect(x + 2, y + 1, x + 20, y + 21);
|
g.drawRect(x + 2, y + 1, x + 20, y + 21);
|
||||||
g.setFont('6x8', 1);
|
g.setFont('6x8', 1);
|
||||||
if (NRF.getSecurityStatus().connected) g.drawString('B', x + 5, y + 3);
|
var again = false;
|
||||||
if (Bangle.isCompassOn()) g.drawString('C', x + 13, y + 3);
|
if (NRF.getSecurityStatus().connected) g.drawString('B', x + 5, y + 3), again = true;
|
||||||
if (Bangle.isGPSOn()) g.drawString('G', x + 5, y + 12);
|
if (Bangle.isCompassOn()) g.drawString('C', x + 13, y + 3), again = true;
|
||||||
if (Bangle.isHRMOn()) g.drawString('H', x + 13, y + 12);
|
if (Bangle.isGPSOn()) g.drawString('G', x + 5, y + 12), again = true;
|
||||||
|
if (Bangle.isHRMOn()) g.drawString('H', x + 13, y + 12), again = true;
|
||||||
g.setColor(col(stat.sto)); g.drawRect(x + 2, y + 21, x + 2 + stat.sto * 18, y + 22);
|
g.setColor(col(stat.sto)); g.drawRect(x + 2, y + 21, x + 2 + stat.sto * 18, y + 22);
|
||||||
g.setColor(col(t)); g.drawRect(x + 1, y + 21 - t * 20, x + 2, y + 21);
|
g.setColor(col(t)); g.drawRect(x + 1, y + 21 - t * 20, x + 2, y + 21);
|
||||||
|
// if there's nothing active, don't queue a redraw (rely on Bangle.on(...) below)
|
||||||
|
if (redrawBars || again) setTimeout(draw, drawTime());
|
||||||
}};
|
}};
|
||||||
|
|
||||||
function col(p) {
|
function col(p) {
|
||||||
|
|
@ -33,18 +40,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var draw = WIDGETS.devst.draw.bind(WIDGETS.devst);
|
var draw = WIDGETS.devst.draw.bind(WIDGETS.devst);
|
||||||
var iid = setInterval(draw, Bangle.isLocked() ? 6e4 : 2e3);
|
|
||||||
|
|
||||||
Bangle.on('lcdPower', (on) => {
|
var drawTime = () => Bangle.isLocked() ? 6e4 : 2e3;
|
||||||
if (on) {
|
var throttledDraw = () => Date.now() - d > drawTime() && draw();
|
||||||
draw();
|
|
||||||
if (!iid) iid = setInterval(draw, Bangle.isLocked() ? 6e4 : 2e3);
|
Bangle.on("HRM", throttledDraw);
|
||||||
} else if (iid) iid = clearInterval(iid);
|
Bangle.on("GPS", throttledDraw);
|
||||||
});
|
Bangle.on("mag", throttledDraw);
|
||||||
Bangle.on('lock', (on) => {
|
NRF.on("connect", throttledDraw);
|
||||||
if (iid) {
|
draw();
|
||||||
clearInterval(iid);
|
|
||||||
iid = setInterval(draw, on ? 6e4 : 2e3);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue