widdevst: add option to draw only when peripherals are on

pull/3397/head
Rob Pilling 2024-05-02 18:28:02 +01:00
parent 535335f065
commit 79a5632be4
3 changed files with 11 additions and 1 deletions

View File

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

View File

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

View File

@ -1,6 +1,9 @@
(() => { (() => {
var stat = {date: 0}; var stat = {date: 0};
var d = Date.now(); 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(); d = Date.now();
@ -29,7 +32,7 @@
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 there's nothing active, don't queue a redraw (rely on Bangle.on(...) below)
if (again) setTimeout(draw, drawTime()); if (redrawBars || again) setTimeout(draw, drawTime());
}}; }};
function col(p) { function col(p) {