Skip to content

Commit

Permalink
Use more lightningy bitmap, now we're not resizing don't redraw all w…
Browse files Browse the repository at this point in the history
…idgets, use let scoping(faster), and hard-code 's' to make rendering quicker
  • Loading branch information
gfwilliams authored Sep 13, 2023
1 parent 60a99aa commit 337bf47
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions apps/widbat/widget.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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);
}};
})()
}

0 comments on commit 337bf47

Please sign in to comment.