Skip to content

Commit 0bfa101

Browse files
authored
Merge pull request #4023 from RKBoss6/sleeplogbuxfix
[SleepLog] Fix important bugs with HRM being undefined
2 parents 26b4fe1 + 1a4e3e8 commit 0bfa101

File tree

4 files changed

+14
-27
lines changed

4 files changed

+14
-27
lines changed

apps/sleeplog/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
0.19: Write sleep state into health event's .activity field
1818
0.20: Increase default sleep thresholds, tweak settings to allow higher ones to be chosen
1919
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.
20-
0.22: Fix bug with HRM threshold not updating
20+
0.22: Fix bug with HRM threshold not updating due to movement thresholds being incorrectly compared against the HRM thresholds.
21+
0.23: Fix important bug with HRM data being undefined when compared - broken apps should work properly now

apps/sleeplog/boot.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,39 +151,25 @@ if (global.sleeplog.conf.enabled) {
151151
// define health listener function
152152
// - called by event listener: "this"-reference points to global
153153
health: function(data) {
154+
print("Sleep Log - Health Data Acquired");
154155
// check if global variable accessable
155156
if (!global.sleeplog) return new Error("sleeplog: Can't process health event, global object missing!");
156-
157157
// check if movement is available
158-
if (!data.movement) return;
159-
158+
if (!data.movement&&!data.bpm) return;
160159
// add timestamp rounded to 10min, corrected to 10min ago
161160
data.timestamp = data.timestamp || ((Date.now() / 6E5 | 0) - 1) * 6E5;
162-
163161
// add preliminary status depending on charging and movement thresholds
164162
// 1 = not worn, 2 = awake, 3 = light sleep, 4 = deep sleep
165-
if(data.hrm){
166-
167-
if (!Bangle.isCharging()) {
168-
if (data.heartRate <= global.sleeplog.conf.hrmDeepTh) {
169-
data.status = 4; // deep sleep
170-
} else if (data.heartRate <= global.sleeplog.conf.hrmLightTh) {
171-
data.status = 3; // light sleep
172-
} else {
173-
data.status = 2; // awake
174-
}
175-
} else {
176-
data.status = 1; // not worn
177-
}
178-
179-
163+
if(data.bpm){
164+
data.status = Bangle.isCharging() ? 1 :
165+
data.bpm <= global.sleeplog.conf.hrmDeepTh ? 4 :
166+
data.bpm <= global.sleeplog.conf.hrmLightTh ? 3 : 2;
180167
}else{
181168
data.status = Bangle.isCharging() ? 1 :
182169
data.movement <= global.sleeplog.conf.deepTh ? 4 :
183170
data.movement <= global.sleeplog.conf.lightTh ? 3 : 2;
184171
}
185-
186-
172+
187173
// check if changing to deep sleep from non sleeping
188174
if (data.status === 4 && global.sleeplog.status <= 2) {
189175
global.sleeplog.checkIsWearing((isWearing, data) => {

apps/sleeplog/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id":"sleeplog",
33
"name":"Sleep Log",
44
"shortName": "SleepLog",
5-
"version": "0.22",
5+
"version": "0.23",
66
"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.",
77
"icon": "app.png",
88
"type": "app",

apps/sleeplog/settings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
minConsec: 18E5, // [ms] minimal time to count for consecutive sleep
1515
deepTh: 150, // threshold for deep sleep
1616
lightTh: 300,// threshold for light sleep
17-
hrmLightTh: 74,// threshold for light sleep
18-
hrmDeepTh:60,// threshold for deep sleep
17+
hrmLightTh: 74,// threshold for light sleep with HRM
18+
hrmDeepTh:60,// threshold for deep sleep with HRM
1919
wearTemp: 19.5, // temperature threshold to count as worn
2020
// app settings
2121
breakToD: 12, // [h] time of day when to start/end graphs
@@ -302,7 +302,7 @@
302302
},
303303
/*LANG*/"Deep Sleep": {
304304
value: settings.hrmDeepTh,
305-
step: 2,
305+
step: 1,
306306
min: 30,
307307
max: 100,
308308
wrap: true,
@@ -314,7 +314,7 @@
314314
},
315315
/*LANG*/"Light Sleep": {
316316
value: settings.hrmLightTh,
317-
step: 2,
317+
step: 1,
318318
min: 30,
319319
max: 100,
320320
wrap: true,

0 commit comments

Comments
 (0)