1
0
Fork 0

Battery widget now updates every minute with screen on, or whenever the screen first turns on

master
Gordon Williams 2020-02-13 09:14:10 +00:00
parent 6e6d078a9b
commit 0590c1eec1
1 changed files with 16 additions and 2 deletions

View File

@ -13,13 +13,27 @@ function draw() {
x+=16; x+=16;
s-=16; s-=16;
} }
g.setColor(1,1,1); g.setColor(-1);
g.fillRect(x,y+2,x+s-4,y+21); g.fillRect(x,y+2,x+s-4,y+21);
g.clearRect(x+2,y+4,x+s-6,y+19); g.clearRect(x+2,y+4,x+s-6,y+19);
g.fillRect(x+s-3,y+10,x+s,y+14); g.fillRect(x+s-3,y+10,x+s,y+14);
g.setColor(CHARGING).fillRect(x+4,y+6,x+4+E.getBattery()*(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,1,1); g.setColor(-1);
} }
Bangle.on('charging',function(charging) { draw(); g.flip(); if(charging)Bangle.buzz(); }); Bangle.on('charging',function(charging) { draw(); g.flip(); if(charging)Bangle.buzz(); });
var batteryInterval;
Bangle.on('lcdPower', function(on) {
if (on) {
draw();
// refresh once a minute if LCD on
if (!batteryInterval)
batteryInterval = setInterval(draw, 60000);
} else {
if (batteryInterval) {
clearInterval(batteryInterval);
batteryInterval = undefined;
}
}
});
WIDGETS["battery"]={draw:draw}; WIDGETS["battery"]={draw:draw};
})() })()