|
1 | 1 | (function() { |
2 | 2 | var img; |
3 | | - var v; |
4 | | - var data; |
5 | | - var hrLeft = 0; |
6 | | - var daysLeft = 0; |
7 | | - var showPercent=false; |
| 3 | + var batt; |
8 | 4 | //updates values |
9 | | - function updateValues(){ |
10 | | - v = E.getBattery(); |
11 | | - data = require("smartbatt").get(); |
12 | | - hrLeft = data.hrsLeft; |
13 | | - daysLeft = hrLeft / 24; |
14 | 5 |
|
15 | | - hrLeft = Math.round(hrLeft); |
| 6 | + |
| 7 | + function getHrsFormatted(hrsLeft){ |
| 8 | + |
| 9 | + var daysLeft = hrsLeft / 24; |
16 | 10 | daysLeft = Math.round(daysLeft); |
17 | | - } |
| 11 | + if (Bangle.isCharging()) { |
| 12 | + return batt+"%"; |
| 13 | + } |
| 14 | + else if(daysLeft >= 1) { |
| 15 | + return daysLeft+"d"; |
| 16 | + } |
18 | 17 |
|
| 18 | + else { |
| 19 | + return Math.round(hrsLeft)+"h"; |
| 20 | + } |
| 21 | + } |
19 | 22 |
|
20 | 23 | //draws battery icon and fill bar |
21 | 24 | function drawBatt(){ |
22 | | - v =E.getBattery(); |
| 25 | + batt =E.getBattery(); |
23 | 26 | var s=24,g=Graphics.createArrayBuffer(24,24,1,{msb:true}); |
24 | 27 | g.fillRect(0,6,s-3,18).clearRect(2,8,s-5,16).fillRect(s-2,10,s,15).fillRect(3,9,3+v*(s-9)/100,15); |
25 | 28 | g.transparent=0; |
|
29 | 32 | //calls both updates for values and icons. |
30 | 33 | //might split in the future since values updates once every five minutes so we dont need to call it in every minute while the battery can be updated once a minute. |
31 | 34 | function updateDisplay(){ |
32 | | - updateValues(); |
33 | 35 | drawBatt(); |
34 | 36 | } |
35 | 37 |
|
|
38 | 40 | items: [ |
39 | 41 | { name : "BattStatus", |
40 | 42 | get : () => { |
41 | | - updateValues(); |
42 | | - drawBatt(); |
43 | 43 |
|
| 44 | + drawBatt(); |
| 45 | + var data=require("smartbatt").get(); |
| 46 | + |
44 | 47 | //update clock info according to batt state |
45 | 48 | if (Bangle.isCharging()) { |
46 | | - return { text: v+"%", img : img}; |
| 49 | + return { text: batt+"%", img : img}; |
47 | 50 | } |
48 | | - else if(daysLeft >= 1) { |
49 | | - return { text: daysLeft+"d", img : img}; |
50 | | - } |
51 | | - |
52 | | - else { |
53 | | - return {text: hrLeft+"h", img: img}; |
| 51 | + else{ |
| 52 | + return { text: getHrsFormatted(data.hrsLeft), img : img}; |
54 | 53 | } |
55 | 54 | }, |
56 | 55 |
|
57 | 56 | show : function() { |
58 | 57 | this.interval = setInterval(()=>{ |
59 | 58 | updateDisplay(); |
60 | 59 | this.emit('redraw'); |
61 | | - }, 60000); |
| 60 | + }, 300000); |
62 | 61 | }, |
63 | 62 |
|
64 | 63 | hide : function() { |
|
76 | 75 | show : function() { |
77 | 76 | this.interval = setInterval(()=>{ |
78 | 77 | this.emit('redraw'); |
79 | | - }, 60000); |
| 78 | + }, 300000); |
80 | 79 | }, |
81 | 80 |
|
82 | 81 | hide : function() { |
|
0 commit comments