From 257a8b26626b34db7f874b8ef379849977ec6534 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Thu, 2 Apr 2020 08:34:47 +0100 Subject: [PATCH] Copied widbat changes to new widget --- apps.json | 13 ++++++++- apps/widbat/ChangeLog | 2 -- apps/widbat/widget.js | 22 ++------------- apps/widbatpc/ChangeLog | 5 ++++ apps/widbatpc/widget.js | 59 +++++++++++++++++++++++++++++++++++++++ apps/widbatpc/widget.png | Bin 0 -> 297 bytes 6 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 apps/widbatpc/ChangeLog create mode 100644 apps/widbatpc/widget.js create mode 100644 apps/widbatpc/widget.png diff --git a/apps.json b/apps.json index 8c819298d..019573266 100644 --- a/apps.json +++ b/apps.json @@ -326,7 +326,7 @@ { "id": "widbat", "name": "Battery Level Widget", "icon": "widget.png", - "version":"0.06", + "version":"0.04", "description": "Show the current battery level and charging status in the top right of the clock", "tags": "widget,battery", "type":"widget", @@ -334,6 +334,17 @@ {"name":"widbat.wid.js","url":"widget.js"} ] }, + { "id": "widbatpc", + "name": "Battery Level Widget (with percentage)", + "icon": "widget.png", + "version":"0.06", + "description": "Show the current battery level and charging status in the top right of the clock, with charge percentage", + "tags": "widget,battery", + "type":"widget", + "storage": [ + {"name":"widbatpc.wid.js","url":"widget.js"} + ] + }, { "id": "widbt", "name": "Bluetooth Widget", "icon": "widget.png", diff --git a/apps/widbat/ChangeLog b/apps/widbat/ChangeLog index 55464e390..cd9993c02 100644 --- a/apps/widbat/ChangeLog +++ b/apps/widbat/ChangeLog @@ -1,5 +1,3 @@ 0.02: Now refresh battery monitor every minute if LCD on 0.03: Tweaks for variable size widget system 0.04: Ensure redrawing works with variable size widget system -0.05: Change color depending on battery level -0.06: Show battery percentage as text diff --git a/apps/widbat/widget.js b/apps/widbat/widget.js index 7100dc111..2f1f29802 100644 --- a/apps/widbat/widget.js +++ b/apps/widbat/widget.js @@ -1,10 +1,5 @@ (function(){ -const levelColor = (l) => { - if (Bangle.isCharging()) return 0x07E0; // "Green" - if (l >= 50) return 0x05E0; // slightly darker green - if (l >= 15) return 0xFD20; // "Orange" - return 0xF800; // "Red" -} +var CHARGING = 0x07E0; function setWidth() { WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0); @@ -12,27 +7,16 @@ function setWidth() { function draw() { var s = 39; var x = this.x, y = this.y; - const l = E.getBattery(), c = levelColor(l); if (Bangle.isCharging()) { - g.setColor(c).drawImage(atob( - "DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y); + g.setColor(CHARGING).drawImage(atob("DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y); x+=16; } g.setColor(-1); g.fillRect(x,y+2,x+s-4,y+21); g.clearRect(x+2,y+4,x+s-6,y+19); g.fillRect(x+s-3,y+10,x+s,y+14); - g.setColor(c).fillRect(x+4,y+6,x+4+l*(s-12)/100,y+17); + g.setColor(CHARGING).fillRect(x+4,y+6,x+4+E.getBattery()*(s-12)/100,y+17); g.setColor(-1); - g.setFontAlign(-1,-1); - if (l >= 100) { - g.setFont('4x6', 2); - g.drawString(l, x + 6, y + 7); - } else { - if (l < 10) x+=6; - g.setFont('6x8', 2); - g.drawString(l, x + 6, y + 4); - } } Bangle.on('charging',function(charging) { if(charging) Bangle.buzz(); diff --git a/apps/widbatpc/ChangeLog b/apps/widbatpc/ChangeLog new file mode 100644 index 000000000..3988729c3 --- /dev/null +++ b/apps/widbatpc/ChangeLog @@ -0,0 +1,5 @@ +0.02: Now refresh battery monitor every minute if LCD on +0.03: Tweaks for variable size widget system +0.04: Ensure redrawing works with variable size widget system +0.05: Change color depending on battery level, cloned from widbat +0.06: Show battery percentage as text diff --git a/apps/widbatpc/widget.js b/apps/widbatpc/widget.js new file mode 100644 index 000000000..7100dc111 --- /dev/null +++ b/apps/widbatpc/widget.js @@ -0,0 +1,59 @@ +(function(){ +const levelColor = (l) => { + if (Bangle.isCharging()) return 0x07E0; // "Green" + if (l >= 50) return 0x05E0; // slightly darker green + if (l >= 15) return 0xFD20; // "Orange" + return 0xF800; // "Red" +} + +function setWidth() { + WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0); +} +function draw() { + var s = 39; + var x = this.x, y = this.y; + const l = E.getBattery(), c = levelColor(l); + if (Bangle.isCharging()) { + g.setColor(c).drawImage(atob( + "DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y); + x+=16; + } + g.setColor(-1); + g.fillRect(x,y+2,x+s-4,y+21); + g.clearRect(x+2,y+4,x+s-6,y+19); + g.fillRect(x+s-3,y+10,x+s,y+14); + g.setColor(c).fillRect(x+4,y+6,x+4+l*(s-12)/100,y+17); + g.setColor(-1); + g.setFontAlign(-1,-1); + if (l >= 100) { + g.setFont('4x6', 2); + g.drawString(l, x + 6, y + 7); + } else { + if (l < 10) x+=6; + g.setFont('6x8', 2); + g.drawString(l, x + 6, y + 4); + } +} +Bangle.on('charging',function(charging) { + if(charging) Bangle.buzz(); + setWidth(); + Bangle.drawWidgets(); // relayout widgets + g.flip(); +}); +var batteryInterval; +Bangle.on('lcdPower', function(on) { + if (on) { + WIDGETS["bat"].draw(); + // refresh once a minute if LCD on + if (!batteryInterval) + batteryInterval = setInterval(draw, 60000); + } else { + if (batteryInterval) { + clearInterval(batteryInterval); + batteryInterval = undefined; + } + } +}); +WIDGETS["bat"]={area:"tr",width:40,draw:draw}; +setWidth(); +})() diff --git a/apps/widbatpc/widget.png b/apps/widbatpc/widget.png new file mode 100644 index 0000000000000000000000000000000000000000..630692e38e3b9ba5fbb62b2bc3a33cd61be04836 GIT binary patch literal 297 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCwj^(N7l!{JxM1({$v}~No-U3d z8I5l*8*&|T5O90A-O*#FR_q#)BTkNvUwGt>Trz%PXw%s%enD+*Q(4(O$7{!;ZftnH z;OBlT>zT*Z6fWiIJ=^fB#+Gq&KYwNU9G>d#i1%lbc&mQzv1$1Hd4@jEzQ$ig(U1P} ztw_>iy0bUgRQAhv#r8w_3THnth|Y_Bu~2P(K-W{of(yL1!oTHzSg}U@{@LL7qVaI@ z+@$_vb^q8z5_}o2;UU)6GFFD!1nXQXDJyW8*}q*=>C>8uX+JZBtJj^_U(L8LQa1YE T%Q{h@PZ>O2{an^LB{Ts5c#wMk literal 0 HcmV?d00001