diff --git a/apps/sleeplog/ChangeLog b/apps/sleeplog/ChangeLog index 03571a8450..3526f443d8 100644 --- a/apps/sleeplog/ChangeLog +++ b/apps/sleeplog/ChangeLog @@ -17,4 +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.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 diff --git a/apps/sleeplog/boot.js b/apps/sleeplog/boot.js index b7cd11d2b7..e7468de53f 100644 --- a/apps/sleeplog/boot.js +++ b/apps/sleeplog/boot.js @@ -151,39 +151,29 @@ if (global.sleeplog.conf.enabled) { // define health listener function // - called by event listener: "this"-reference points to global health: function(data) { + 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.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(data.bpm){ + if (!Bangle.isCharging()) { + 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 { + 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; } - - + // check if changing to deep sleep from non sleeping if (data.status === 4 && global.sleeplog.status <= 2) { global.sleeplog.checkIsWearing((isWearing, data) => { @@ -303,7 +293,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())); }); 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", 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