From e046a975ae8bee5050b25f0d56a8d95498eb9de4 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Thu, 6 Mar 2025 06:28:12 -0500 Subject: [PATCH] The displayed info index remains when leaving and re-entering the screen --- apps/daisy/app.js | 36 +++++++++++++++++++----------------- apps/daisy/settings.js | 3 ++- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/apps/daisy/app.js b/apps/daisy/app.js index 4e7e8dbcf..38d2d3185 100644 --- a/apps/daisy/app.js +++ b/apps/daisy/app.js @@ -1,4 +1,5 @@ var SunCalc = require("suncalc"); // from modules folder +const storage = require('Storage') const widget_utils = require('widget_utils'); const SETTINGS_FILE = "daisy.json"; const LOCATION_FILE = "mylocation.json"; @@ -86,6 +87,7 @@ function loadSettings() { settings.batt_hours = (settings.batt_hours === undefined ? false : settings.batt_hours); settings.hr_12 = (settings.hr_12 === undefined ? false : settings.hr_12); settings.ring = settings.ring||'Steps'; + settings.idxInfo = settings.idxInfo||0; assignPalettes(); } @@ -190,28 +192,21 @@ const infoData = { }; const infoList = Object.keys(infoData).sort(); -let infoMode = infoList[0]; -function nextInfo() { - let idx = infoList.indexOf(infoMode); +function nextInfo(idx) { if (idx > -1) { - if (idx === infoList.length - 1) infoMode = infoList[0]; - else infoMode = infoList[idx + 1]; + if (idx === infoList.length - 1) idx = 0; + else idx += 1; } - // power HRM on/off accordingly - Bangle.setHRMPower(infoMode == "ID_HRM" ? 1 : 0); - resetHrm(); + return idx; } -function prevInfo() { - let idx = infoList.indexOf(infoMode); +function prevInfo(idx) { if (idx > -1) { - if (idx === 0) infoMode = infoList[infoList.length - 1]; - else infoMode = infoList[idx - 1]; + if (idx === 0) idx = infoList.length - 1; + else idx -= 1; } - // power HRM on/off accordingly - Bangle.setHRMPower(infoMode == "ID_HRM" ? 1 : 0); - resetHrm(); + return idx; } function clearInfo() { @@ -706,13 +701,20 @@ Bangle.on('lcdPower',on=>{ }); Bangle.setUI("clockupdown", btn=> { - if (btn<0) prevInfo(); - if (btn>0) nextInfo(); + if (btn<0) settings.idxInfo = prevInfo(settings.idxInfo); + if (btn>0) settings.idxInfo = nextInfo(settings.idxInfo); + // power HRM on/off accordingly + infoMode = infoList[settings.idxInfo]; + Bangle.setHRMPower(infoMode == "ID_HRM" ? 1 : 0); + resetHrm(); + log_debug("idxInfo=" + settings.idxInfo); draw(); + storage.write(SETTINGS_FILE, settings); // Retains idxInfo when leaving the face }); loadSettings(); loadLocation(); +var infoMode = infoList[settings.idxInfo]; updateSunRiseSunSet(new Date(), location.lat, location.lon, true); g.clear(); diff --git a/apps/daisy/settings.js b/apps/daisy/settings.js index e07685d37..277a5743a 100644 --- a/apps/daisy/settings.js +++ b/apps/daisy/settings.js @@ -8,7 +8,8 @@ 'check_idle' : true, 'batt_hours' : false, 'hr_12' : false, - 'ring' : 'Steps'}; + 'ring' : 'Steps', + 'idxInfo' : 0}; // ...and overwrite them with any saved values // This way saved values are preserved if a new version adds more settings