hwid_batt: restore (forked to widbattpwr)
parent
82f4832aff
commit
1658636ad0
|
|
@ -9,4 +9,3 @@
|
||||||
0.09: Add option for showing battery high mark
|
0.09: Add option for showing battery high mark
|
||||||
0.10: Fix background color
|
0.10: Fix background color
|
||||||
0.11: Minor code improvements
|
0.11: Minor code improvements
|
||||||
0.12: Show power consumption and hours remaining via percentage shading and colour
|
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,14 @@ Show the current battery level and charging status in the top right of the clock
|
||||||
|
|
||||||
* Works with Bangle 2
|
* Works with Bangle 2
|
||||||
* Simple design, no settings
|
* Simple design, no settings
|
||||||
* Red when the battery level is below 30%
|
* Red when the batterly level is below 30%
|
||||||
* Blue when charging
|
* Blue when charging
|
||||||
* 40 pixels wide
|
* 40 pixels wide
|
||||||
|
|
||||||
This is a copy of `wid_a_battery_widget`, with the main changes being:
|
The high-level marker (a little bar at the 100% point) can be toggled in settings.
|
||||||
* Reduced constants in code
|
|
||||||
* Reduced `fillRect` calls / improved efficiency
|
|
||||||
* Removal of the high-level marker
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Creator
|
## Creator
|
||||||
[@alainsaas](https://github.com/alainsaas)
|
[@alainsaas](https://github.com/alainsaas)
|
||||||
Mod by Hank
|
Mod by Hank
|
||||||
Mod again by bobrippling
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "A Battery Widget (with percentage) - Hanks Mod",
|
"name": "A Battery Widget (with percentage) - Hanks Mod",
|
||||||
"shortName":"H Battery Widget",
|
"shortName":"H Battery Widget",
|
||||||
"icon": "widget.png",
|
"icon": "widget.png",
|
||||||
"version":"0.12",
|
"version":"0.11",
|
||||||
"type": "widget",
|
"type": "widget",
|
||||||
"supports": ["BANGLEJS", "BANGLEJS2"],
|
"supports": ["BANGLEJS", "BANGLEJS2"],
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
var old_x = this.x;
|
var old_x = this.x;
|
||||||
var old_y = this.y;
|
var old_y = this.y;
|
||||||
|
|
||||||
|
|
||||||
let COLORS = {
|
let COLORS = {
|
||||||
'white': g.theme.dark ? "#000" : "#fff",
|
'white': g.theme.dark ? "#000" : "#fff",
|
||||||
'black': g.theme.dark ? "#fff" : "#000",
|
'black': g.theme.dark ? "#fff" : "#000",
|
||||||
|
|
@ -20,24 +21,24 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
let x = this.x;
|
var s = width - 1;
|
||||||
let y = this.y;
|
var x = this.x;
|
||||||
if (x != null && y != null) {
|
var y = this.y;
|
||||||
g.reset();
|
if (x !== undefined && y !== undefined) {
|
||||||
g.setBgColor(COLORS.white);
|
g.setBgColor(COLORS.white);
|
||||||
g.clearRect(old_x, old_y, old_x + width, old_y + height - 1);
|
g.clearRect(old_x, old_y, old_x + width, old_y + height);
|
||||||
|
|
||||||
const l = E.getBattery();
|
const l = E.getBattery(); // debug: Math.floor(Math.random() * 101);
|
||||||
|
let xl = x+4+l*(s-12)/100;
|
||||||
|
|
||||||
// Charging bar
|
|
||||||
g.setColor(levelColor(l));
|
g.setColor(levelColor(l));
|
||||||
const xl = x+1+(width - 1)*l/100;
|
g.fillRect(x+4,y+14+3,xl,y+16+3); // charging bar
|
||||||
g.fillRect(x+1,y+height-3,xl,y+height-1);
|
|
||||||
|
|
||||||
// Show percentage
|
// Show percentage
|
||||||
|
g.setColor(COLORS.black);
|
||||||
g.setFontAlign(0,0);
|
g.setFontAlign(0,0);
|
||||||
g.setFont('Vector',16);
|
g.setFont('Vector',16);
|
||||||
this.drawText(l);
|
g.drawString(l, x + 14, y + 10);
|
||||||
|
|
||||||
}
|
}
|
||||||
old_x = this.x;
|
old_x = this.x;
|
||||||
old_y = this.y;
|
old_y = this.y;
|
||||||
|
|
@ -46,51 +47,10 @@
|
||||||
else changeInterval(id, intervalLow);
|
else changeInterval(id, intervalLow);
|
||||||
}
|
}
|
||||||
|
|
||||||
const drawString = function(l) {
|
Bangle.on('charging',function(charging) { draw(); });
|
||||||
g.drawString(l, this.x + 14, this.y + 10);
|
var id = setInterval(()=>WIDGETS["hwid_a_battery_widget"].draw(), intervalLow);
|
||||||
};
|
|
||||||
let drawText;
|
|
||||||
|
|
||||||
if(E.getPowerUsage){
|
|
||||||
drawText = function(batt) {
|
|
||||||
const pwr = E.getPowerUsage();
|
|
||||||
let total = 0;
|
|
||||||
for(const key in pwr.device){
|
|
||||||
if(!/^(LCD|LED)/.test(key))
|
|
||||||
total += pwr.device[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
const hrs = 200000 / total;
|
|
||||||
const days = hrs / 24;
|
|
||||||
const txt = days >= 1 ? `${Math.round(days)}d` : `${Math.round(hrs)}h`;
|
|
||||||
|
|
||||||
// draw time left, then shade it based on batt %
|
|
||||||
const th = 14;
|
|
||||||
g.setColor(COLORS.black);
|
|
||||||
g.setClipRect(this.x, this.y, this.x + width, this.y + th);
|
|
||||||
drawString.call(this, txt);
|
|
||||||
|
|
||||||
g.setClipRect(this.x, this.y + th * (1 - batt / 100), this.x + width, this.y + th);
|
|
||||||
if(total >= 23000)
|
|
||||||
g.setColor("#f00"); // red, e.g. GPS ~20k
|
|
||||||
else if(total > 2000)
|
|
||||||
g.setColor("#fc0"); // yellow, e.g. CPU ~1k, HRM ~700
|
|
||||||
else
|
|
||||||
g.setColor("#0f0"); // green: ok
|
|
||||||
drawString.call(this, txt);
|
|
||||||
};
|
|
||||||
}else{
|
|
||||||
drawText = function(batt) {
|
|
||||||
g.setColor(COLORS.black);
|
|
||||||
drawString.call(this, batt);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const d = () => WIDGETS["hwid_a_battery_widget"].draw();
|
|
||||||
Bangle.on('charging', d);
|
|
||||||
var id = setInterval(d, intervalLow);
|
|
||||||
var width = 30;
|
var width = 30;
|
||||||
var height = 24;
|
var height = 19;
|
||||||
|
|
||||||
WIDGETS["hwid_a_battery_widget"]={area:"tr",width,draw,drawText};
|
WIDGETS["hwid_a_battery_widget"]={area:"tr",width,draw:draw};
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue