Skip to content

Commit ffc8d20

Browse files
authored
Fix draw define first
1 parent 274b518 commit ffc8d20

File tree

1 file changed

+34
-38
lines changed

1 file changed

+34
-38
lines changed

apps/widsmartbatt/widget.js

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function(){
2-
2+
33
var showPercent = false;
44
const width = 40;
55
const height = 24;
@@ -19,47 +19,44 @@
1919
};
2020

2121
function draw() {
22-
let batt=E.getBattery();
23-
let data = require("smartbatt").get();
24-
let hrsLeft=data.hrsLeft;
25-
let days = hrsLeft / 24;
26-
27-
let txt = showPercent
28-
? batt
29-
: (days >= 1
30-
? Math.round(Math.min(days, 99)) + "d"
31-
: Math.round(hrsLeft) + "h");
32-
if(Bangle.isCharging()) txt=E.getBattery();
33-
let s = 29;
34-
let x = this.x, y = this.y;
35-
let xl = x + 4 + batt * (s - 12) / 100;
36-
37-
// Drawing code follows...
38-
g.setColor(COLORS.bg);
39-
g.fillRect(x + 2, y + 5, x + s - 6, y + 18);
40-
41-
g.setColor(levelColor(batt));
42-
g.fillRect(x + 1, y + 3, x + s - 5, y + 4);
43-
g.fillRect(x + 1, y + 19, x + s - 5, y + 20);
44-
g.fillRect(x, y + 4, x + 1, y + 19);
45-
g.fillRect(x + s - 5, y + 4, x + s - 4, y + 19);
46-
g.fillRect(x + s - 3, y + 8, x + s - 2, y + 16);
47-
g.fillRect(x + 4, y + 15, xl, y + 16);
22+
let batt=E.getBattery();
23+
let data = require("smartbatt").get();
24+
let hrsLeft=data.hrsLeft;
25+
let days = hrsLeft / 24;
26+
27+
let txt = showPercent
28+
? batt
29+
: (days >= 1
30+
? Math.round(Math.min(days, 99)) + "d"
31+
: Math.round(hrsLeft) + "h");
32+
if(Bangle.isCharging()) txt=E.getBattery();
33+
let s = 29;
34+
let x = this.x, y = this.y;
35+
let xl = x + 4 + batt * (s - 12) / 100;
4836

49-
g.setColor(COLORS.fg);
50-
g.setFontAlign(0, 0);
51-
g.setFont('6x8');
52-
g.drawString(txt, x + 14, y + 10);
37+
// Drawing code follows...
38+
g.setColor(COLORS.bg);
39+
g.fillRect(x + 2, y + 5, x + s - 6, y + 18);
40+
41+
g.setColor(levelColor(batt));
42+
g.fillRect(x + 1, y + 3, x + s - 5, y + 4);
43+
g.fillRect(x + 1, y + 19, x + s - 5, y + 20);
44+
g.fillRect(x, y + 4, x + 1, y + 19);
45+
g.fillRect(x + s - 5, y + 4, x + s - 4, y + 19);
46+
g.fillRect(x + s - 3, y + 8, x + s - 2, y + 16);
47+
g.fillRect(x + 4, y + 15, xl, y + 16);
48+
49+
g.setColor(COLORS.fg);
50+
g.setFontAlign(0, 0);
51+
g.setFont('6x8');
52+
g.drawString(txt, x + 14, y + 10);
53+
5354

54-
5555
}
5656
WIDGETS["widsmartbatt"] = {
5757
area: "tr",
5858
width: 30,
59-
draw: function() {
60-
// Call your drawing function
61-
draw();
62-
}
59+
draw: draw
6360
};
6461

6562
// Touch to temporarily show battery percent
@@ -73,7 +70,6 @@
7370
if (w.x - oversize <= x && x < w.x + width + oversize
7471
&& w.y - oversize <= y && y < w.y + height + oversize) {
7572
E.stopEventPropagation && E.stopEventPropagation();
76-
Bangle.buzz(20);
7773
showPercent = true;
7874
setTimeout(() => {
7975
showPercent = false;
@@ -87,7 +83,7 @@
8783
Bangle.on('charging', function () {
8884
WIDGETS["widsmartbatt"].draw();
8985
});
90-
//draw once per minute...
86+
9187
var id = setInterval(() => WIDGETS["widsmartbatt"].draw(), 60000);
9288

9389

0 commit comments

Comments
 (0)