Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/sleeplog/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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 important bug with HRM data being undefined, fix bug with movement thresholds being compared against the HRM thresholds.
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,
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