Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

widbat: Use flash, not fork to indicate charging #2984

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/widbat/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion apps/widbat/metadata.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
31 changes: 11 additions & 20 deletions apps/widbat/widget.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
(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
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();
Expand All @@ -23,19 +19,14 @@
}
});
WIDGETS["bat"]={area:"tr",width:40,draw:function() {
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);
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(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);
}};
setWidth();
})()
}