From 75a26826f3cd03c8ac1c082929d04e35f46c4959 Mon Sep 17 00:00:00 2001 From: poolitzer Date: Wed, 19 Jun 2024 18:11:28 +0200 Subject: [PATCH] Feat: Added battery estimate in hs --- apps/daisy/ChangeLog | 1 + apps/daisy/README.md | 3 ++- apps/daisy/app.js | 25 ++++++++++++++++++++++++- apps/daisy/metadata.json | 2 +- apps/daisy/settings.js | 11 ++++++++++- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/apps/daisy/ChangeLog b/apps/daisy/ChangeLog index e9568acfc..af2e21ae8 100644 --- a/apps/daisy/ChangeLog +++ b/apps/daisy/ChangeLog @@ -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 diff --git a/apps/daisy/README.md b/apps/daisy/README.md index 491ed697f..5599d313c 100644 --- a/apps/daisy/README.md +++ b/apps/daisy/README.md @@ -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. @@ -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 diff --git a/apps/daisy/app.js b/apps/daisy/app.js index cba3e762d..d64c9b31e 100644 --- a/apps/daisy/app.js +++ b/apps/daisy/app.js @@ -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(); } @@ -112,13 +113,35 @@ 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 > 99) { + rounded = Math.round(batt_usage); + } + else if (batt_usage > 9) { + rounded = Math.round(200000/E.getPowerUsage().total * 10) / 10; + } + else { + rounded = Math.round(200000/E.getPowerUsage().total * 100) / 100; + } + 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 } }; diff --git a/apps/daisy/metadata.json b/apps/daisy/metadata.json index a292ef777..81a1e593b 100644 --- a/apps/daisy/metadata.json +++ b/apps/daisy/metadata.json @@ -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", diff --git a/apps/daisy/settings.js b/apps/daisy/settings.js index 6397a81f4..b1cb6b4b3 100644 --- a/apps/daisy/settings.js +++ b/apps/daisy/settings.js @@ -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 @@ -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(); + }, } }); }) +