Update widget.js

master^2
RKBoss6 2025-07-26 09:55:52 -04:00 committed by GitHub
parent c09e29b478
commit 45df9b3cfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 42 additions and 39 deletions

View File

@ -1,9 +1,5 @@
(function(){ (function(){
WIDGETS["widsmartbatt"] = {
area: "tr",
width: 30,
draw: draw
};
const intervalLow = 30000; // update interval when not charging const intervalLow = 30000; // update interval when not charging
const intervalHigh = 30000; // faster update when charging const intervalHigh = 30000; // faster update when charging
var showPercent = false; var showPercent = false;
@ -25,42 +21,49 @@
}; };
function draw() { function draw() {
let batt=E.getBattery(); let batt=E.getBattery();
let data = require("smartbatt").get(); let data = require("smartbatt").get();
let hrsLeft=data.hrsLeft; let hrsLeft=data.hrsLeft;
let days = hrsLeft / 24; let days = hrsLeft / 24;
let txt = showPercent
? batt
: (days >= 1
? Math.round(Math.min(days, 99)) + "d"
: Math.round(hrsLeft) + "h");
if(Bangle.isCharging()) txt=E.getBattery();
let s = 29;
let x = this.x, y = this.y;
let xl = x + 4 + batt * (s - 12) / 100;
// Drawing code follows... let txt = showPercent
g.setColor(COLORS.bg); ? batt
g.fillRect(x + 2, y + 5, x + s - 6, y + 18); : (days >= 1
? Math.round(Math.min(days, 99)) + "d"
g.setColor(levelColor(batt)); : Math.round(hrsLeft) + "h");
g.fillRect(x + 1, y + 3, x + s - 5, y + 4); if(Bangle.isCharging()) txt=E.getBattery();
g.fillRect(x + 1, y + 19, x + s - 5, y + 20); let s = 29;
g.fillRect(x, y + 4, x + 1, y + 19); let x = this.x, y = this.y;
g.fillRect(x + s - 5, y + 4, x + s - 4, y + 19); let xl = x + 4 + batt * (s - 12) / 100;
g.fillRect(x + s - 3, y + 8, x + s - 2, y + 16);
g.fillRect(x + 4, y + 15, xl, y + 16); // Drawing code follows...
g.setColor(COLORS.bg);
g.setColor(COLORS.fg); g.fillRect(x + 2, y + 5, x + s - 6, y + 18);
g.setFontAlign(0, 0);
g.setFont('6x8'); g.setColor(levelColor(batt));
g.drawString(txt, x + 14, y + 10); g.fillRect(x + 1, y + 3, x + s - 5, y + 4);
g.fillRect(x + 1, y + 19, x + s - 5, y + 20);
if (Bangle.isCharging()) changeInterval(id, intervalHigh); g.fillRect(x, y + 4, x + 1, y + 19);
else changeInterval(id, intervalLow); g.fillRect(x + s - 5, y + 4, x + s - 4, y + 19);
g.fillRect(x + s - 3, y + 8, x + s - 2, y + 16);
g.fillRect(x + 4, y + 15, xl, y + 16);
g.setColor(COLORS.fg);
g.setFontAlign(0, 0);
g.setFont('6x8');
g.drawString(txt, x + 14, y + 10);
if (Bangle.isCharging()) changeInterval(id, intervalHigh);
else changeInterval(id, intervalLow);
} }
WIDGETS["widsmartbatt"] = {
area: "tr",
width: 30,
draw: function() {
// Call your drawing function
draw();
}
};
// Touch to temporarily show battery percent // Touch to temporarily show battery percent
Bangle.on("touch", function (_btn, xy) { Bangle.on("touch", function (_btn, xy) {