widbatpc: Only redraw when values change

master
Erik Andresen 2023-02-26 10:06:43 +01:00
parent fb1518f6b8
commit b8e0222315
3 changed files with 14 additions and 3 deletions

View File

@ -15,3 +15,4 @@
0.16: Increase screen update rate when charging
0.17: Add option 'Remove Jitter'='Drop only' to prevent percentage from getting up again when not charging
Add option to disable vibration when charger connects
0.18: Only redraw when values change

View File

@ -2,7 +2,7 @@
"id": "widbatpc",
"name": "Battery Level Widget (with percentage)",
"shortName": "Battery Widget",
"version": "0.17",
"version": "0.18",
"description": "Show the current battery level and charging status in the top right of the clock, with charge percentage",
"icon": "widget.png",
"type": "widget",

View File

@ -86,7 +86,7 @@
return changed;
}
function draw() {
function draw(fromIntervall) {
// if hidden, don't draw
if (!WIDGETS["batpc"].width) return;
// else...
@ -103,6 +103,14 @@
l = prevMin;
}
}
if (fromIntervall === true && this.prevLevel === l && this.prevCharging === Bangle.isCharging()) {
return; // unchanged, do nothing
}
this.prevLevel = l;
this.prevCharging = Bangle.isCharging();
const c = levelColor(l);
if (Bangle.isCharging() && setting('charger')) {
@ -149,6 +157,8 @@
// can affect the width and mess with the whole widget layout
setWidth();
g.clear();
WIDGETS["batpc"].prevLevel = undefined;
WIDGETS["batpc"].prevCharging = undefined;
Bangle.drawWidgets();
}
@ -173,7 +183,7 @@
if (on) update();
});
var id = setInterval(()=>WIDGETS["batpc"].draw(), intervalLow);
var id = setInterval(()=>WIDGETS["batpc"].draw(true), intervalLow);
WIDGETS["batpc"]={area:"tr",width:40,draw:draw,reload:reload};
setWidth();