From 5e63154be66e965b5e1c3fb892ff6841799a3893 Mon Sep 17 00:00:00 2001 From: RKBoss6 Date: Tue, 30 Sep 2025 21:46:40 -0400 Subject: [PATCH 1/9] Refactor health status logic in boot.js --- apps/sleeplog/boot.js | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/apps/sleeplog/boot.js b/apps/sleeplog/boot.js index b7cd11d2b7..03241f7ae2 100644 --- a/apps/sleeplog/boot.js +++ b/apps/sleeplog/boot.js @@ -151,38 +151,34 @@ if (global.sleeplog.conf.enabled) { // define health listener function // - called by event listener: "this"-reference points to global health: function(data) { + print("Health data acquired"); // check if global variable accessable if (!global.sleeplog) return new Error("sleeplog: Can't process health event, global object missing!"); - + // check if movement is available if (!data.movement) return; - + // add timestamp rounded to 10min, corrected to 10min ago data.timestamp = data.timestamp || ((Date.now() / 6E5 | 0) - 1) * 6E5; // add preliminary status depending on charging and movement thresholds // 1 = not worn, 2 = awake, 3 = light sleep, 4 = deep sleep if(data.hrm){ - - if (!Bangle.isCharging()) { - if (data.heartRate <= global.sleeplog.conf.hrmDeepTh) { - data.status = 4; // deep sleep - } else if (data.heartRate <= global.sleeplog.conf.hrmLightTh) { - data.status = 3; // light sleep - } else { - data.status = 2; // awake - } - } else { - data.status = 1; // not worn - } - - - }else{ - data.status = Bangle.isCharging() ? 1 : - data.movement <= global.sleeplog.conf.deepTh ? 4 : - data.movement <= global.sleeplog.conf.lightTh ? 3 : 2; + if (!Bangle.isCharging()) { + if (data.heartRate <= global.sleeplog.conf.hrmDeepTh) data.status = 4; + else if (data.heartRate <= global.sleeplog.conf.hrmLightTh) data.status = 3; + else data.status = 2; + } else data.status = 1; + } else { + if (!Bangle.isCharging()) { + if (data.movement <= global.sleeplog.conf.deepTh) data.status = 4; + else if (data.movement <= global.sleeplog.conf.lightTh) data.status = 3; + else data.status = 2; + } else data.status = 1; } - + + console.log("HRM:", data.hrm, "HR:", data.heartRate, "Movement:", data.movement, "Status:", data.status); + // check if changing to deep sleep from non sleeping if (data.status === 4 && global.sleeplog.status <= 2) { @@ -303,7 +299,7 @@ if (global.sleeplog.conf.enabled) { timestamp: new Date(data.timestamp), status: data.status, consecutive: data.consecutive, - prevStatus: data.status === this.status ? undefined : this.status, + prevStatus: this.status, prevConsecutive: data.consecutive === this.consecutive ? undefined : this.consecutive }, (e => {delete e.fn; return e;})(entry.clone())); }); From 6fa781687f196ed022a501b2b24f1d8526708c23 Mon Sep 17 00:00:00 2001 From: RKBoss6 Date: Tue, 30 Sep 2025 21:47:17 -0400 Subject: [PATCH 2/9] Update version number to 0.23 in metadata.json --- apps/sleeplog/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sleeplog/metadata.json b/apps/sleeplog/metadata.json index 893d1811d1..b9fd239ad6 100644 --- a/apps/sleeplog/metadata.json +++ b/apps/sleeplog/metadata.json @@ -2,7 +2,7 @@ "id":"sleeplog", "name":"Sleep Log", "shortName": "SleepLog", - "version": "0.22", + "version": "0.23", "description": "Log and view your sleeping habits. This app uses built in movement calculations, or HRM data, if enabled. View data from Bangle.js, or from the web app.", "icon": "app.png", "type": "app", From 90e6ecf22353bedc530047a091be78dcd3ad739d Mon Sep 17 00:00:00 2001 From: RKBoss6 Date: Tue, 30 Sep 2025 21:47:47 -0400 Subject: [PATCH 3/9] Update ChangeLog for version 0.23 --- apps/sleeplog/ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/sleeplog/ChangeLog b/apps/sleeplog/ChangeLog index 03571a8450..8c56350430 100644 --- a/apps/sleeplog/ChangeLog +++ b/apps/sleeplog/ChangeLog @@ -18,3 +18,4 @@ 0.20: Increase default sleep thresholds, tweak settings to allow higher ones to be chosen 0.21: Use HRM data is polling is enabled, and add appropriate thresholds in settings. Change settings to feel more intuitive, rather than copied settings in different pages. 0.22: Fix bug with HRM threshold not updating +0.23: Fix bug with movement data not being pulled in. From 375ca0b4f66ffaaea68cc29203486f67d727c5f9 Mon Sep 17 00:00:00 2001 From: RKBoss6 Date: Tue, 30 Sep 2025 22:01:11 -0400 Subject: [PATCH 4/9] Update heart rate monitoring logic in boot.js --- apps/sleeplog/boot.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/sleeplog/boot.js b/apps/sleeplog/boot.js index 03241f7ae2..048b726a5e 100644 --- a/apps/sleeplog/boot.js +++ b/apps/sleeplog/boot.js @@ -163,10 +163,10 @@ if (global.sleeplog.conf.enabled) { // add preliminary status depending on charging and movement thresholds // 1 = not worn, 2 = awake, 3 = light sleep, 4 = deep sleep - if(data.hrm){ + if(data.bpm){ if (!Bangle.isCharging()) { - if (data.heartRate <= global.sleeplog.conf.hrmDeepTh) data.status = 4; - else if (data.heartRate <= global.sleeplog.conf.hrmLightTh) data.status = 3; + if (data.bpm <= global.sleeplog.conf.hrmDeepTh) data.status = 4; + else if (data.bpm <= global.sleeplog.conf.hrmLightTh) data.status = 3; else data.status = 2; } else data.status = 1; } else { @@ -177,7 +177,7 @@ if (global.sleeplog.conf.enabled) { } else data.status = 1; } - console.log("HRM:", data.hrm, "HR:", data.heartRate, "Movement:", data.movement, "Status:", data.status); + // check if changing to deep sleep from non sleeping From b64639dd83715b54117d1645db548593506a9ae4 Mon Sep 17 00:00:00 2001 From: RKBoss6 Date: Tue, 7 Oct 2025 10:07:09 -0400 Subject: [PATCH 5/9] Update ChangeLog --- apps/sleeplog/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sleeplog/ChangeLog b/apps/sleeplog/ChangeLog index 8c56350430..a432018153 100644 --- a/apps/sleeplog/ChangeLog +++ b/apps/sleeplog/ChangeLog @@ -18,4 +18,4 @@ 0.20: Increase default sleep thresholds, tweak settings to allow higher ones to be chosen 0.21: Use HRM data is polling is enabled, and add appropriate thresholds in settings. Change settings to feel more intuitive, rather than copied settings in different pages. 0.22: Fix bug with HRM threshold not updating -0.23: Fix bug with movement data not being pulled in. +0.23: Fix important bug with HRM data being undefined, fix bug with movement thresholds being compared against the HRM thresholds. From 53c300588319df94ea81c32b84511c05e247c2df Mon Sep 17 00:00:00 2001 From: RKBoss6 Date: Tue, 7 Oct 2025 10:18:37 -0400 Subject: [PATCH 6/9] Update health log message for clarity --- apps/sleeplog/boot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sleeplog/boot.js b/apps/sleeplog/boot.js index 048b726a5e..e5fcc287ec 100644 --- a/apps/sleeplog/boot.js +++ b/apps/sleeplog/boot.js @@ -151,7 +151,7 @@ if (global.sleeplog.conf.enabled) { // define health listener function // - called by event listener: "this"-reference points to global health: function(data) { - print("Health data acquired"); + print("Sleep Log - Health Data Acquired"); // check if global variable accessable if (!global.sleeplog) return new Error("sleeplog: Can't process health event, global object missing!"); From 050d58d31c818fb9d0fe59afe2ceae0e0919ea51 Mon Sep 17 00:00:00 2001 From: RKBoss6 Date: Tue, 7 Oct 2025 10:20:20 -0400 Subject: [PATCH 7/9] Clean up health function in boot.js Removed unnecessary whitespace and comments in health function. --- apps/sleeplog/boot.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apps/sleeplog/boot.js b/apps/sleeplog/boot.js index e5fcc287ec..e7468de53f 100644 --- a/apps/sleeplog/boot.js +++ b/apps/sleeplog/boot.js @@ -154,13 +154,10 @@ if (global.sleeplog.conf.enabled) { print("Sleep Log - Health Data Acquired"); // check if global variable accessable if (!global.sleeplog) return new Error("sleeplog: Can't process health event, global object missing!"); - // check if movement is available if (!data.movement) return; - // add timestamp rounded to 10min, corrected to 10min ago data.timestamp = data.timestamp || ((Date.now() / 6E5 | 0) - 1) * 6E5; - // add preliminary status depending on charging and movement thresholds // 1 = not worn, 2 = awake, 3 = light sleep, 4 = deep sleep if(data.bpm){ @@ -177,9 +174,6 @@ if (global.sleeplog.conf.enabled) { } else data.status = 1; } - - - // check if changing to deep sleep from non sleeping if (data.status === 4 && global.sleeplog.status <= 2) { global.sleeplog.checkIsWearing((isWearing, data) => { From 4f109e7d7914dd17d66d6a6e3b30023aa7a18a61 Mon Sep 17 00:00:00 2001 From: RKBoss6 Date: Wed, 8 Oct 2025 17:22:43 -0400 Subject: [PATCH 8/9] Update ChangeLog --- apps/sleeplog/ChangeLog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/sleeplog/ChangeLog b/apps/sleeplog/ChangeLog index a432018153..3526f443d8 100644 --- a/apps/sleeplog/ChangeLog +++ b/apps/sleeplog/ChangeLog @@ -17,5 +17,5 @@ 0.19: Write sleep state into health event's .activity field 0.20: Increase default sleep thresholds, tweak settings to allow higher ones to be chosen 0.21: Use HRM data is polling is enabled, and add appropriate thresholds in settings. Change settings to feel more intuitive, rather than copied settings in different pages. -0.22: Fix bug with HRM threshold not updating -0.23: Fix important bug with HRM data being undefined, fix bug with movement thresholds being compared against the HRM thresholds. +0.22: Fix bug with HRM threshold not updating, fix bug with movement thresholds being compared against the HRM thresholds. +0.23: Fix important bug with HRM data being undefined From 9489c19a0d328b789cfed44018d34d8edb7846bd Mon Sep 17 00:00:00 2001 From: RKBoss6 Date: Thu, 9 Oct 2025 17:20:53 -0400 Subject: [PATCH 9/9] Change hrm step to 1 for finer tuning --- apps/sleeplog/settings.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/sleeplog/settings.js b/apps/sleeplog/settings.js index 9086210c7f..164866b672 100644 --- a/apps/sleeplog/settings.js +++ b/apps/sleeplog/settings.js @@ -13,9 +13,9 @@ maxAwake: 36E5, // [ms] maximal awake time to count for consecutive sleep minConsec: 18E5, // [ms] minimal time to count for consecutive sleep deepTh: 150, // threshold for deep sleep - lightTh: 300,// threshold for light sleep - hrmLightTh: 74,// threshold for light sleep - hrmDeepTh:60,// threshold for deep sleep + lightTh: 300, + hrmLightTh: 74, + hrmDeepTh:60,// threshold for light sleep wearTemp: 19.5, // temperature threshold to count as worn // app settings breakToD: 12, // [h] time of day when to start/end graphs @@ -302,7 +302,7 @@ }, /*LANG*/"Deep Sleep": { value: settings.hrmDeepTh, - step: 2, + step: 1, min: 30, max: 100, wrap: true, @@ -314,7 +314,7 @@ }, /*LANG*/"Light Sleep": { value: settings.hrmLightTh, - step: 2, + step: 1, min: 30, max: 100, wrap: true, @@ -399,7 +399,7 @@ } else { /*menu =*/ E.showMenu(thresholdsMenu); } - } + }; function showOtherSettings() { // setup logging menu