|
1 | 1 | (function(){ |
2 | | - WIDGETS["widsmartbatt"] = { |
3 | | - area: "tr", |
4 | | - width: 30, |
5 | | - draw: draw |
6 | | - }; |
| 2 | + |
7 | 3 | const intervalLow = 30000; // update interval when not charging |
8 | 4 | const intervalHigh = 30000; // faster update when charging |
9 | 5 | var showPercent = false; |
|
25 | 21 | }; |
26 | 22 |
|
27 | 23 | 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; |
42 | 28 |
|
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); |
62 | 58 | } |
63 | | - |
| 59 | + WIDGETS["widsmartbatt"] = { |
| 60 | + area: "tr", |
| 61 | + width: 30, |
| 62 | + draw: function() { |
| 63 | + // Call your drawing function |
| 64 | + draw(); |
| 65 | + } |
| 66 | + }; |
64 | 67 |
|
65 | 68 | // Touch to temporarily show battery percent |
66 | 69 | Bangle.on("touch", function (_btn, xy) { |
|
0 commit comments