From bc92e0c8c6e301fbe22b061fff3ca901547a67e3 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 19 Aug 2023 20:10:13 +0200 Subject: [PATCH 1/3] widbat: Use flash, not fork to indicate charging Green fork is not easily visible, which can be confusing. --- apps/widbat/ChangeLog | 1 + apps/widbat/metadata.json | 2 +- apps/widbat/widget.js | 11 +++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/widbat/ChangeLog b/apps/widbat/ChangeLog index cb11b1be9a..9577d952b3 100644 --- a/apps/widbat/ChangeLog +++ b/apps/widbat/ChangeLog @@ -8,3 +8,4 @@ 0.09: Misc speed/memory tweaks 0.10: Color changes due to the battery level 0.11: Change level for medium charge (50% -> 40%), and darken color on light themes as yellow was almost invisible +0.12: Use black flash instead of green fork to indicate charging diff --git a/apps/widbat/metadata.json b/apps/widbat/metadata.json index 0151fcbd73..7f0d99f097 100644 --- a/apps/widbat/metadata.json +++ b/apps/widbat/metadata.json @@ -1,7 +1,7 @@ { "id": "widbat", "name": "Battery Level Widget", - "version": "0.11", + "version": "0.12", "description": "Show the current battery level and charging status in the top right of the clock", "icon": "widget.png", "type": "widget", diff --git a/apps/widbat/widget.js b/apps/widbat/widget.js index 98eb092279..f874528936 100644 --- a/apps/widbat/widget.js +++ b/apps/widbat/widget.js @@ -26,16 +26,19 @@ var s = 39; var x = this.x, y = this.y; g.reset(); - if (Bangle.isCharging()) { - g.setColor("#0f0").drawImage(atob("DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y); - x+=16; - } g.setColor(g.theme.fg).fillRect(x,y+2,x+s-4,y+21).clearRect(x+2,y+4,x+s-6,y+19).fillRect(x+s-3,y+10,x+s,y+14); var battery = E.getBattery(); if(battery < 20) {g.setColor("#f00");} else if (battery < 40) {g.setColor(g.theme.dark ? "#ff0" : "#f80");} else {g.setColor("#0f0");} g.fillRect(x+4,y+6,x+4+battery*(s-12)/100,y+17); + if (Bangle.isCharging()) { + let hy = y+11; + let hx = x+s/2; + let flash = [x+5,hy, hx-4,hy-1, hx,y+6, x+s-7,y+hy, + hx+4,y+hy+1, hx,y+17]; + g.setColor(g.theme.fg).fillPoly(flash); + } }}; setWidth(); })() From 60a99aae53cc28436d6eac7bd086138eb3e5dfb0 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 2 Sep 2023 23:25:54 +0200 Subject: [PATCH 2/3] Widget size no longer changes, so remove associated code. --- apps/widbat/widget.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/apps/widbat/widget.js b/apps/widbat/widget.js index f874528936..8262537e8a 100644 --- a/apps/widbat/widget.js +++ b/apps/widbat/widget.js @@ -1,10 +1,6 @@ (function(){ - function setWidth() { - WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0); - } Bangle.on('charging',function(charging) { if(charging) Bangle.buzz(); - setWidth(); Bangle.drawWidgets(); // re-layout widgets g.flip(); }); @@ -40,5 +36,4 @@ g.setColor(g.theme.fg).fillPoly(flash); } }}; - setWidth(); })() From 337bf47354aad7cc6ea859e43075dc77fa53b249 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Wed, 13 Sep 2023 09:18:37 +0100 Subject: [PATCH 3/3] Use more lightningy bitmap, now we're not resizing don't redraw all widgets, use let scoping(faster), and hard-code 's' to make rendering quicker --- apps/widbat/widget.js | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/apps/widbat/widget.js b/apps/widbat/widget.js index 8262537e8a..e9ab66c2a4 100644 --- a/apps/widbat/widget.js +++ b/apps/widbat/widget.js @@ -1,10 +1,10 @@ -(function(){ +{ Bangle.on('charging',function(charging) { if(charging) Bangle.buzz(); - Bangle.drawWidgets(); // re-layout widgets + WIDGETS["bat"].draw(); g.flip(); }); - var batteryInterval = Bangle.isLCDOn() ? setInterval(()=>WIDGETS["bat"].draw(), 60000) : undefined; + let batteryInterval = Bangle.isLCDOn() ? setInterval(()=>WIDGETS["bat"].draw(), 60000) : undefined; Bangle.on('lcdPower', function(on) { if (on) { WIDGETS["bat"].draw(); @@ -19,21 +19,14 @@ } }); WIDGETS["bat"]={area:"tr",width:40,draw:function() { - var s = 39; var x = this.x, y = this.y; - g.reset(); - g.setColor(g.theme.fg).fillRect(x,y+2,x+s-4,y+21).clearRect(x+2,y+4,x+s-6,y+19).fillRect(x+s-3,y+10,x+s,y+14); + g.reset().setColor(g.theme.fg).fillRect(x,y+2,x+35,y+21).clearRect(x+2,y+4,x+33,y+19).fillRect(x+36,y+10,x+39,y+14); var battery = E.getBattery(); - if(battery < 20) {g.setColor("#f00");} - else if (battery < 40) {g.setColor(g.theme.dark ? "#ff0" : "#f80");} - else {g.setColor("#0f0");} - g.fillRect(x+4,y+6,x+4+battery*(s-12)/100,y+17); - if (Bangle.isCharging()) { - let hy = y+11; - let hx = x+s/2; - let flash = [x+5,hy, hx-4,hy-1, hx,y+6, x+s-7,y+hy, - hx+4,y+hy+1, hx,y+17]; - g.setColor(g.theme.fg).fillPoly(flash); - } + if(battery < 20) g.setColor("#f00"); + else if (battery < 40) g.setColor(g.theme.dark ? "#ff0" : "#f80"); + else g.setColor("#0f0"); + g.fillRect(x+4,y+6,x+4+battery*27/100,y+17); + if (Bangle.isCharging()) + g.reset().drawImage(atob("FAqBAAHAAA8AAPwAB/D4f8P+Hw/gAD8AAPAAA4A="),x+8,y+7); }}; -})() +}