Skip to content
3 changes: 2 additions & 1 deletion apps/sleeplog/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 15 additions & 25 deletions apps/sleeplog/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed? I wonder if it could have some unintended side effect?

prevConsecutive: data.consecutive === this.consecutive ? undefined : this.consecutive
}, (e => {delete e.fn; return e;})(entry.clone()));
});
Expand Down
2 changes: 1 addition & 1 deletion apps/sleeplog/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions apps/sleeplog/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -302,7 +302,7 @@
},
/*LANG*/"Deep Sleep": {
value: settings.hrmDeepTh,
step: 2,
step: 1,
min: 30,
max: 100,
wrap: true,
Expand All @@ -314,7 +314,7 @@
},
/*LANG*/"Light Sleep": {
value: settings.hrmLightTh,
step: 2,
step: 1,
min: 30,
max: 100,
wrap: true,
Expand Down Expand Up @@ -399,7 +399,7 @@
} else {
/*menu =*/ E.showMenu(thresholdsMenu);
}
}
};

Check failure on line 402 in apps/sleeplog/settings.js

View workflow job for this annotation

GitHub Actions / build

Unnecessary semicolon

function showOtherSettings() {
// setup logging menu
Expand Down
Loading