2022-06-11 13:23:47 +00:00
|
|
|
(function(){
|
2022-06-23 14:53:06 +00:00
|
|
|
const intervalLow = 60000; // update time when not charging
|
2022-06-11 15:46:36 +00:00
|
|
|
const intervalHigh = 2000; // update time when charging
|
|
|
|
var old_l;
|
|
|
|
|
2022-06-23 14:53:06 +00:00
|
|
|
var old_x = this.x;
|
|
|
|
var old_y = this.y;
|
2022-06-23 13:49:09 +00:00
|
|
|
|
|
|
|
|
2022-06-11 15:46:36 +00:00
|
|
|
let COLORS = {
|
|
|
|
'white': g.theme.dark ? "#000" : "#fff",
|
|
|
|
'black': g.theme.dark ? "#fff" : "#000",
|
|
|
|
'charging': "#08f",
|
|
|
|
'high': g.theme.dark ? "#fff" : "#000",
|
|
|
|
'low': "#f00",
|
|
|
|
};
|
|
|
|
|
|
|
|
const levelColor = (l) => {
|
|
|
|
if (Bangle.isCharging()) return COLORS.charging;
|
|
|
|
if (l >= 30) return COLORS.high;
|
|
|
|
return COLORS.low;
|
|
|
|
};
|
|
|
|
|
|
|
|
function draw() {
|
2022-06-23 14:53:06 +00:00
|
|
|
if (typeof old_x === 'undefined') old_x = this.x;
|
|
|
|
if (typeof old_y === 'undefined') old_y = this.y;
|
2022-06-11 15:46:36 +00:00
|
|
|
var s = 29;
|
2022-06-23 13:49:09 +00:00
|
|
|
var x = this.x;
|
|
|
|
var y = this.y;
|
2022-06-23 15:05:08 +00:00
|
|
|
if ((typeof x === 'undefined') || (typeof y === 'undefined')) {
|
|
|
|
} else {
|
2022-08-11 12:56:37 +00:00
|
|
|
const l = E.getBattery(); // debug: Math.floor(Math.random() * 101);
|
2022-06-23 15:05:08 +00:00
|
|
|
let xl = x+4+l*(s-12)/100;
|
2022-08-11 12:56:37 +00:00
|
|
|
if ((l != old_l) && (typeof old_l != 'undefined') ){ // Delete the old value from screen
|
2022-06-23 15:05:08 +00:00
|
|
|
let xl_old = x+4+old_l*(s-12)/100;
|
|
|
|
g.setColor(COLORS.white);
|
|
|
|
// g.fillRect(x+2,y+5,x+s-6,y+18);
|
|
|
|
g.fillRect(x,y,xl+4,y+16+3); //Clear
|
|
|
|
g.setFontAlign(0,0);
|
|
|
|
g.setFont('Vector',16);
|
|
|
|
//g.fillRect(old_x,old_y,old_x+4+l*(s-12)/100,old_y+16+3); // clear (lazy)
|
|
|
|
g.drawString(old_l, old_x + 14, old_y + 10);
|
|
|
|
g.fillRect(x+4,y+14+3,xl_old,y+16+3); // charging bar
|
2022-08-11 12:56:37 +00:00
|
|
|
|
2022-06-23 15:05:08 +00:00
|
|
|
}
|
2022-08-11 12:56:37 +00:00
|
|
|
old_l = l;
|
2022-06-23 15:05:08 +00:00
|
|
|
//console.log(old_x);
|
2022-06-23 13:49:09 +00:00
|
|
|
|
2022-06-23 15:05:08 +00:00
|
|
|
g.setColor(levelColor(l));
|
|
|
|
g.fillRect(x+4,y+14+3,xl,y+16+3); // charging bar
|
|
|
|
g.fillRect((x+4+100*(s-12)/100)-1,y+14+3,x+4+100*(s-12)/100,y+16+3); // charging bar "full mark"
|
|
|
|
// Show percentage
|
|
|
|
g.setColor(COLORS.black);
|
2022-06-11 15:46:36 +00:00
|
|
|
g.setFontAlign(0,0);
|
|
|
|
g.setFont('Vector',16);
|
2022-06-23 15:05:08 +00:00
|
|
|
g.drawString(l, x + 14, y + 10);
|
|
|
|
|
2022-06-11 15:46:36 +00:00
|
|
|
}
|
2022-06-23 15:05:08 +00:00
|
|
|
old_x = this.x;
|
|
|
|
old_y = this.y;
|
2022-06-23 14:53:06 +00:00
|
|
|
|
2022-06-11 15:46:36 +00:00
|
|
|
if (Bangle.isCharging()) changeInterval(id, intervalHigh);
|
|
|
|
else changeInterval(id, intervalLow);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bangle.on('charging',function(charging) { draw(); });
|
2022-08-11 12:56:37 +00:00
|
|
|
var id = setInterval(()=>WIDGETS["hwid_a_battery_widget"].draw(), intervalLow);
|
2022-06-11 15:46:36 +00:00
|
|
|
|
2022-08-11 12:56:37 +00:00
|
|
|
WIDGETS["hwid_a_battery_widget"]={area:"tr",width:30,draw:draw};
|
2022-06-11 13:23:47 +00:00
|
|
|
})();
|