Skip to content

Commit 2b56b2e

Browse files
authored
remove variables from memory, increase redraw time to conserve battery life
1 parent d132ab0 commit 2b56b2e

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

apps/smartbatt/clkinfo.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
(function() {
22
var img;
3-
var v;
4-
var data;
5-
var hrLeft = 0;
6-
var daysLeft = 0;
7-
var showPercent=false;
3+
var batt;
84
//updates values
9-
function updateValues(){
10-
v = E.getBattery();
11-
data = require("smartbatt").get();
12-
hrLeft = data.hrsLeft;
13-
daysLeft = hrLeft / 24;
145

15-
hrLeft = Math.round(hrLeft);
6+
7+
function getHrsFormatted(hrsLeft){
8+
9+
var daysLeft = hrsLeft / 24;
1610
daysLeft = Math.round(daysLeft);
17-
}
11+
if (Bangle.isCharging()) {
12+
return batt+"%";
13+
}
14+
else if(daysLeft >= 1) {
15+
return daysLeft+"d";
16+
}
1817

18+
else {
19+
return Math.round(hrsLeft)+"h";
20+
}
21+
}
1922

2023
//draws battery icon and fill bar
2124
function drawBatt(){
22-
v =E.getBattery();
25+
batt =E.getBattery();
2326
var s=24,g=Graphics.createArrayBuffer(24,24,1,{msb:true});
2427
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);
2528
g.transparent=0;
@@ -29,7 +32,6 @@
2932
//calls both updates for values and icons.
3033
//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.
3134
function updateDisplay(){
32-
updateValues();
3335
drawBatt();
3436
}
3537

@@ -38,27 +40,24 @@
3840
items: [
3941
{ name : "BattStatus",
4042
get : () => {
41-
updateValues();
42-
drawBatt();
4343

44+
drawBatt();
45+
var data=require("smartbatt").get();
46+
4447
//update clock info according to batt state
4548
if (Bangle.isCharging()) {
46-
return { text: v+"%", img : img};
49+
return { text: batt+"%", img : img};
4750
}
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};
5453
}
5554
},
5655

5756
show : function() {
5857
this.interval = setInterval(()=>{
5958
updateDisplay();
6059
this.emit('redraw');
61-
}, 60000);
60+
}, 300000);
6261
},
6362

6463
hide : function() {
@@ -76,7 +75,7 @@
7675
show : function() {
7776
this.interval = setInterval(()=>{
7877
this.emit('redraw');
79-
}, 60000);
78+
}, 300000);
8079
},
8180

8281
hide : function() {

0 commit comments

Comments
 (0)