Merge pull request #2811 from bobrippling/hank-batt-highmark

Battery Widget - Hanks Mod, add setting to hide high-mark
pull/2813/head
Gordon Williams 2023-06-12 09:29:15 +01:00 committed by GitHub
commit 03f18dacb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 25 deletions

View File

@ -5,4 +5,5 @@
0.05: Deleting Background - making Font larger
0.06: Fixing refresh issues
0.07: Fixed position after unlocking
0.08: Handling exceptions
0.08: Handling exceptions
0.09: Add option for showing battery high mark

View File

@ -8,6 +8,8 @@ Show the current battery level and charging status in the top right of the clock
* Blue when charging
* 40 pixels wide
The high-level marker (a little bar at the 100% point) can be toggled in settings.
![](a_battery_widget-pic.jpg)
## Creator

View File

@ -3,7 +3,7 @@
"name": "A Battery Widget (with percentage) - Hanks Mod",
"shortName":"H Battery Widget",
"icon": "widget.png",
"version":"0.08",
"version":"0.09",
"type": "widget",
"supports": ["BANGLEJS", "BANGLEJS2"],
"readme": "README.md",

View File

@ -1,7 +1,6 @@
(function(){
const intervalLow = 60000; // update time when not charging
const intervalHigh = 2000; // update time when charging
var old_l;
var old_x = this.x;
var old_y = this.y;
@ -22,49 +21,36 @@
};
function draw() {
if (typeof old_x === 'undefined') old_x = this.x;
if (typeof old_y === 'undefined') old_y = this.y;
var s = 29;
var s = width - 1;
var x = this.x;
var y = this.y;
if ((typeof x === 'undefined') || (typeof y === 'undefined')) {
} else {
g.clearRect(old_x, old_y, old_x + width, old_y + height);
const l = E.getBattery(); // debug: Math.floor(Math.random() * 101);
let xl = x+4+l*(s-12)/100;
if ((l != old_l) && (typeof old_l != 'undefined') ){ // Delete the old value from screen
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
}
old_l = l;
//console.log(old_x);
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);
g.setFontAlign(0,0);
g.setFont('Vector',16);
g.drawString(l, x + 14, y + 10);
}
old_x = this.x;
old_y = this.y;
old_y = this.y;
if (Bangle.isCharging()) changeInterval(id, intervalHigh);
else changeInterval(id, intervalLow);
}
Bangle.on('charging',function(charging) { draw(); });
var id = setInterval(()=>WIDGETS["hwid_a_battery_widget"].draw(), intervalLow);
var width = 30;
var height = 19;
WIDGETS["hwid_a_battery_widget"]={area:"tr",width:30,draw:draw};
WIDGETS["hwid_a_battery_widget"]={area:"tr",width,draw:draw};
})();