Skip to content

Commit b967a6d

Browse files
authored
Add update interval setting to smartbatt
1 parent 443b6f1 commit b967a6d

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

apps/smartbatt/settings.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
21
(function(back) {
32
var FILE = "smartbatt.settings.json";
4-
// Load settings
53
var settings = Object.assign({
6-
//Record Interval stored in ms
7-
doLogging:false
4+
doLogging:false,
5+
updateInterval:18000000
86
}, require('Storage').readJSON(FILE, true) || {});
97

108
function writeSettings() {
119
require('Storage').writeJSON(FILE, settings);
1210
}
1311

14-
// Show the menu
1512
E.showMenu({
16-
"" : { "title" : "Smart Day Battery" },
13+
"" : { "title" : "Smart Battery" },
1714
"< Back" : () => back(),
1815

1916
'Clear Data': function () {
@@ -28,15 +25,33 @@
2825
}
2926
});
3027
},
31-
'Log Battery': {
32-
value: !!settings.doLogging, // !! converts undefined to false
28+
'Update Interval': {
29+
value: 0|settings.updateInterval,
30+
min:1800000,
31+
max:172800000,
32+
step:1800000,
33+
format: v=>{
34+
var totalMinutes = Math.floor(v / 60000);
35+
var h = Math.floor(totalMinutes / 60);
36+
var m = totalMinutes % 60;
37+
38+
let result = '';
39+
if (h > 0) result += `${h}h${m > 0 ? ' ' : ''}`;
40+
if (m > 0) result += `${m}m`;
41+
42+
return result || '0m';
43+
},
44+
onchange: v => {
45+
settings.updateInterval = v;
46+
writeSettings();
47+
}
48+
},
49+
'Log Battery': {
50+
value: !!settings.doLogging,
3351
onchange: v => {
3452
settings.doLogging = v;
3553
writeSettings();
3654
}
37-
// format: ... may be specified as a function which converts the value to a string
38-
// if the value is a boolean, showMenu() will convert this automatically, which
39-
// keeps settings menus consistent
40-
},
55+
}
4156
});
4257
})

0 commit comments

Comments
 (0)