Skip to content

Commit

Permalink
Merge pull request #3462 from Poolitzer/master
Browse files Browse the repository at this point in the history
Update Daisy clock to add battery estimate in hs
  • Loading branch information
bobrippling authored Jun 28, 2024
2 parents 664a5b1 + 54b1f3f commit 98e10cd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/daisy/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
0.09: Use 'modules/suncalc.js' to avoid it being copied 8 times for different apps
0.10: Use widget_utils.
0.11: Minor code improvements
0.12: Added setting to change Battery estimate to hours
3 changes: 2 additions & 1 deletion apps/daisy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Forum](http://forum.espruino.com/microcosms/1424/)

* Derived from [The Ring](https://banglejs.com/apps/?id=thering) proof of concept and the [Pastel clock](https://banglejs.com/apps/?q=pastel)
* Includes the [Lazybones](https://banglejs.com/apps/?q=lazybones) Idle warning timer
* Touch the top right/top left to cycle through the info display (Day, Date, Steps, Sunrise, Sunset, Heart Rate)
* Touch the top right/top left to cycle through the info display (Day, Date, Steps, Sunrise, Sunset, Heart Rate, Battery Estimate)
* The heart rate monitor is turned on only when Heart rate is selected and will take a few seconds to settle
* The heart value is displayed in RED if the confidence value is less than 50%
* NOTE: The heart rate monitor of Bangle JS 2 is not very accurate when moving about.
Expand All @@ -20,6 +20,7 @@ See [#1248](https://github.com/espruino/BangleApps/issues/1248)
[MyLocation](https://banglejs.com/apps/?id=mylocation)
* The screen is updated every minute to save battery power
* Uses the [BloggerSansLight](https://www.1001fonts.com/rounded-fonts.html?page=3) font, which if free for commercial use
* You need to run >2V22 to show the battery estimate in hours

## Future Development
* Use mini icons in the information line rather that text
Expand Down
29 changes: 28 additions & 1 deletion apps/daisy/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function loadSettings() {
settings.gy = settings.gy||'#020';
settings.fg = settings.fg||'#0f0';
settings.idle_check = (settings.idle_check === undefined ? true : settings.idle_check);
settings.batt_hours = (settings.batt_hours === undefined ? true : settings.batt_hours);
assignPalettes();
}

Expand Down Expand Up @@ -112,13 +113,39 @@ function updateSunRiseSunSet(now, lat, lon, line){
sunSet = extractTime(times.sunset);
}

function batteryString(){
let stringToInsert;
if (settings.batt_hours) {
var batt_usage = 200000/E.getPowerUsage().total;
let rounded;
if (batt_usage > 24) {
var days = Math.floor(batt_usage/24);
var hours = Math.round((batt_usage/24 - days) * 24);
stringToInsert = '\n' + days + ((days < 2) ? 'd' : 'ds') + ' ' + hours + ((hours < 2) ? 'h' : 'hs');
}
else if (batt_usage > 9) {
rounded = Math.round(200000/E.getPowerUsage().total * 10) / 10;
}
else {
rounded = Math.round(200000/E.getPowerUsage().total * 100) / 100;
}
if (batt_usage < 24) {
stringToInsert = '\n' + rounded + ' ' + ((batt_usage < 2) ? 'h' : 'hs');
}
}
else{
stringToInsert = ' ' + E.getBattery() + '%';
}
return 'BATTERY' + stringToInsert;
}

const infoData = {
ID_DATE: { calc: () => {var d = (new Date()).toString().split(" "); return d[2] + ' ' + d[1] + ' ' + d[3];} },
ID_DAY: { calc: () => {var d = require("locale").dow(new Date()).toLowerCase(); return d[0].toUpperCase() + d.substring(1);} },
ID_SR: { calc: () => 'SUNRISE ' + sunRise },
ID_SS: { calc: () => 'SUNSET ' + sunSet },
ID_STEP: { calc: () => 'STEPS ' + getSteps() },
ID_BATT: { calc: () => 'BATTERY ' + E.getBattery() + '%' },
ID_BATT: { calc: batteryString},
ID_HRM: { calc: () => hrmCurrent }
};

Expand Down
2 changes: 1 addition & 1 deletion apps/daisy/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ "id": "daisy",
"name": "Daisy",
"version": "0.11",
"version": "0.12",
"dependencies": {"mylocation":"app"},
"description": "A beautiful digital clock with large ring guage, idle timer and a cyclic information line that includes, day, date, steps, battery, sunrise and sunset times",
"icon": "app.png",
Expand Down
11 changes: 10 additions & 1 deletion apps/daisy/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
let s = {'gy' : '#020',
'fg' : '#0f0',
'color': 'Green',
'check_idle' : true};
'check_idle' : true,
'batt_hours' : false};

// ...and overwrite them with any saved values
// This way saved values are preserved if a new version adds more settings
Expand Down Expand Up @@ -45,6 +46,14 @@
s.idle_check = v;
save();
},
},
'Expected Battery Life In Hours': {
value: !!s.batt_hours,
onchange: v => {
s.batt_hours = v;
save();
},
}
});
})

0 comments on commit 98e10cd

Please sign in to comment.