From b8e0222315e9ae5d5976d3c17e3ffac3759bd739 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 26 Feb 2023 10:06:43 +0100 Subject: [PATCH 1/2] widbatpc: Only redraw when values change --- apps/widbatpc/ChangeLog | 1 + apps/widbatpc/metadata.json | 2 +- apps/widbatpc/widget.js | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/widbatpc/ChangeLog b/apps/widbatpc/ChangeLog index 97da2cba6..3592656a9 100644 --- a/apps/widbatpc/ChangeLog +++ b/apps/widbatpc/ChangeLog @@ -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 diff --git a/apps/widbatpc/metadata.json b/apps/widbatpc/metadata.json index cb47475cb..d361da442 100644 --- a/apps/widbatpc/metadata.json +++ b/apps/widbatpc/metadata.json @@ -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", diff --git a/apps/widbatpc/widget.js b/apps/widbatpc/widget.js index 7f483c960..eff619f0e 100644 --- a/apps/widbatpc/widget.js +++ b/apps/widbatpc/widget.js @@ -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(); From c835650c4422e7fc166e3e1ac0d8aae61bbd100c Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 26 Feb 2023 10:28:18 +0100 Subject: [PATCH 2/2] widbatpc fixes --- apps/widbatpc/widget.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/widbatpc/widget.js b/apps/widbatpc/widget.js index eff619f0e..b508cce8b 100644 --- a/apps/widbatpc/widget.js +++ b/apps/widbatpc/widget.js @@ -86,7 +86,7 @@ return changed; } - function draw(fromIntervall) { + function draw(fromInterval) { // if hidden, don't draw if (!WIDGETS["batpc"].width) return; // else... @@ -104,7 +104,7 @@ } } - if (fromIntervall === true && this.prevLevel === l && this.prevCharging === Bangle.isCharging()) { + if (fromInterval === true && this.prevLevel === l && this.prevCharging === Bangle.isCharging()) { return; // unchanged, do nothing } @@ -157,8 +157,6 @@ // can affect the width and mess with the whole widget layout setWidth(); g.clear(); - WIDGETS["batpc"].prevLevel = undefined; - WIDGETS["batpc"].prevCharging = undefined; Bangle.drawWidgets(); }