|
1 | 1 | (function(){ |
2 | | - |
| 2 | + |
3 | 3 | var showPercent = false; |
4 | 4 | const width = 40; |
5 | 5 | const height = 24; |
|
19 | 19 | }; |
20 | 20 |
|
21 | 21 | 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; |
48 | 36 |
|
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 | + |
53 | 54 |
|
54 | | - |
55 | 55 | } |
56 | 56 | WIDGETS["widsmartbatt"] = { |
57 | 57 | area: "tr", |
58 | 58 | width: 30, |
59 | | - draw: function() { |
60 | | - // Call your drawing function |
61 | | - draw(); |
62 | | - } |
| 59 | + draw: draw |
63 | 60 | }; |
64 | 61 |
|
65 | 62 | // Touch to temporarily show battery percent |
|
73 | 70 | if (w.x - oversize <= x && x < w.x + width + oversize |
74 | 71 | && w.y - oversize <= y && y < w.y + height + oversize) { |
75 | 72 | E.stopEventPropagation && E.stopEventPropagation(); |
76 | | - Bangle.buzz(20); |
77 | 73 | showPercent = true; |
78 | 74 | setTimeout(() => { |
79 | 75 | showPercent = false; |
|
87 | 83 | Bangle.on('charging', function () { |
88 | 84 | WIDGETS["widsmartbatt"].draw(); |
89 | 85 | }); |
90 | | - //draw once per minute... |
| 86 | + |
91 | 87 | var id = setInterval(() => WIDGETS["widsmartbatt"].draw(), 60000); |
92 | 88 |
|
93 | 89 |
|
|
0 commit comments