2019-11-06 17:25:02 +00:00
|
|
|
(function(){
|
2020-04-01 22:12:48 +00:00
|
|
|
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"
|
|
|
|
}
|
2019-11-06 17:25:02 +00:00
|
|
|
|
2020-03-05 13:15:27 +00:00
|
|
|
function setWidth() {
|
|
|
|
WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0);
|
|
|
|
}
|
2019-11-06 17:25:02 +00:00
|
|
|
function draw() {
|
2020-03-05 13:15:27 +00:00
|
|
|
var s = 39;
|
|
|
|
var x = this.x, y = this.y;
|
2020-04-01 22:12:48 +00:00
|
|
|
const l = E.getBattery(), c = levelColor(l);
|
2019-11-06 17:25:02 +00:00
|
|
|
if (Bangle.isCharging()) {
|
2020-04-01 22:12:48 +00:00
|
|
|
g.setColor(c).drawImage(atob(
|
|
|
|
"DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y);
|
2019-11-06 17:25:02 +00:00
|
|
|
x+=16;
|
|
|
|
}
|
2020-02-13 09:14:10 +00:00
|
|
|
g.setColor(-1);
|
2019-11-06 17:25:02 +00:00
|
|
|
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);
|
2020-04-01 22:12:48 +00:00
|
|
|
g.setColor(c).fillRect(x+4,y+6,x+4+l*(s-12)/100,y+17);
|
2020-02-13 09:14:10 +00:00
|
|
|
g.setColor(-1);
|
2020-04-01 22:16:46 +00:00
|
|
|
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);
|
|
|
|
}
|
2019-11-06 17:25:02 +00:00
|
|
|
}
|
2020-03-05 13:15:27 +00:00
|
|
|
Bangle.on('charging',function(charging) {
|
|
|
|
if(charging) Bangle.buzz();
|
|
|
|
setWidth();
|
|
|
|
Bangle.drawWidgets(); // relayout widgets
|
|
|
|
g.flip();
|
|
|
|
});
|
2020-02-13 09:14:10 +00:00
|
|
|
var batteryInterval;
|
|
|
|
Bangle.on('lcdPower', function(on) {
|
|
|
|
if (on) {
|
2020-03-09 14:30:56 +00:00
|
|
|
WIDGETS["bat"].draw();
|
2020-02-13 09:14:10 +00:00
|
|
|
// refresh once a minute if LCD on
|
|
|
|
if (!batteryInterval)
|
|
|
|
batteryInterval = setInterval(draw, 60000);
|
|
|
|
} else {
|
|
|
|
if (batteryInterval) {
|
|
|
|
clearInterval(batteryInterval);
|
|
|
|
batteryInterval = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-03-05 13:15:27 +00:00
|
|
|
WIDGETS["bat"]={area:"tr",width:40,draw:draw};
|
|
|
|
setWidth();
|
2019-11-06 17:25:02 +00:00
|
|
|
})()
|