Skip to content

Commit 45df9b3

Browse files
authored
Update widget.js
1 parent c09e29b commit 45df9b3

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

apps/widsmartbatt/widget.js

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
(function(){
2-
WIDGETS["widsmartbatt"] = {
3-
area: "tr",
4-
width: 30,
5-
draw: draw
6-
};
2+
73
const intervalLow = 30000; // update interval when not charging
84
const intervalHigh = 30000; // faster update when charging
95
var showPercent = false;
@@ -25,42 +21,49 @@
2521
};
2622

2723
function draw() {
28-
let batt=E.getBattery();
29-
let data = require("smartbatt").get();
30-
let hrsLeft=data.hrsLeft;
31-
let days = hrsLeft / 24;
32-
33-
let txt = showPercent
34-
? batt
35-
: (days >= 1
36-
? Math.round(Math.min(days, 99)) + "d"
37-
: Math.round(hrsLeft) + "h");
38-
if(Bangle.isCharging()) txt=E.getBattery();
39-
let s = 29;
40-
let x = this.x, y = this.y;
41-
let xl = x + 4 + batt * (s - 12) / 100;
24+
let batt=E.getBattery();
25+
let data = require("smartbatt").get();
26+
let hrsLeft=data.hrsLeft;
27+
let days = hrsLeft / 24;
4228

43-
// Drawing code follows...
44-
g.setColor(COLORS.bg);
45-
g.fillRect(x + 2, y + 5, x + s - 6, y + 18);
46-
47-
g.setColor(levelColor(batt));
48-
g.fillRect(x + 1, y + 3, x + s - 5, y + 4);
49-
g.fillRect(x + 1, y + 19, x + s - 5, y + 20);
50-
g.fillRect(x, y + 4, x + 1, y + 19);
51-
g.fillRect(x + s - 5, y + 4, x + s - 4, y + 19);
52-
g.fillRect(x + s - 3, y + 8, x + s - 2, y + 16);
53-
g.fillRect(x + 4, y + 15, xl, y + 16);
54-
55-
g.setColor(COLORS.fg);
56-
g.setFontAlign(0, 0);
57-
g.setFont('6x8');
58-
g.drawString(txt, x + 14, y + 10);
59-
60-
if (Bangle.isCharging()) changeInterval(id, intervalHigh);
61-
else changeInterval(id, intervalLow);
29+
let txt = showPercent
30+
? batt
31+
: (days >= 1
32+
? Math.round(Math.min(days, 99)) + "d"
33+
: Math.round(hrsLeft) + "h");
34+
if(Bangle.isCharging()) txt=E.getBattery();
35+
let s = 29;
36+
let x = this.x, y = this.y;
37+
let xl = x + 4 + batt * (s - 12) / 100;
38+
39+
// Drawing code follows...
40+
g.setColor(COLORS.bg);
41+
g.fillRect(x + 2, y + 5, x + s - 6, y + 18);
42+
43+
g.setColor(levelColor(batt));
44+
g.fillRect(x + 1, y + 3, x + s - 5, y + 4);
45+
g.fillRect(x + 1, y + 19, x + s - 5, y + 20);
46+
g.fillRect(x, y + 4, x + 1, y + 19);
47+
g.fillRect(x + s - 5, y + 4, x + s - 4, y + 19);
48+
g.fillRect(x + s - 3, y + 8, x + s - 2, y + 16);
49+
g.fillRect(x + 4, y + 15, xl, y + 16);
50+
51+
g.setColor(COLORS.fg);
52+
g.setFontAlign(0, 0);
53+
g.setFont('6x8');
54+
g.drawString(txt, x + 14, y + 10);
55+
56+
if (Bangle.isCharging()) changeInterval(id, intervalHigh);
57+
else changeInterval(id, intervalLow);
6258
}
63-
59+
WIDGETS["widsmartbatt"] = {
60+
area: "tr",
61+
width: 30,
62+
draw: function() {
63+
// Call your drawing function
64+
draw();
65+
}
66+
};
6467

6568
// Touch to temporarily show battery percent
6669
Bangle.on("touch", function (_btn, xy) {

0 commit comments

Comments
 (0)