Skip to content

Commit 4e0e253

Browse files
author
thyttan
committed
sleeplog: put use of HRM data behind a setting preferHRM
Discussed around: https://github.com/orgs/espruino/discussions/7801#discussioncomment-15711051
1 parent e51123c commit 4e0e253

5 files changed

Lines changed: 18 additions & 4 deletions

File tree

apps/sleeplog/ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@
2020
0.22: Fix bug with HRM threshold not updating due to movement thresholds being incorrectly compared against the HRM thresholds.
2121
0.23: Fix important bug with HRM data being undefined when compared - broken apps should work properly now
2222
0.24: Change day title to be easier to read, capitalization, and improved documentation/tuning guide in README.
23+
0.25: Put HRM mode behind the setting `Prefer HRM` which defaults to `false`.
24+
Please turn it on if you want the recent HRM behavior. The new default
25+
will be more in line with how version 0.20 worked.

apps/sleeplog/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This app logs and displays the following states:
66

77
It is using the built in movement calculation or HRM to decide your sleeping state. While charging it is assumed that you are not wearing the watch and if the status changes to _deep sleep_ the internal heartrate sensor is used to detect if you are wearing the watch.
88

9-
If HRM polling is enabled in the `Health` app, sleep tracking uses the much more accurate HRM sensor to detect sleep status instead. If not enabled in `Health`, uses movement calculations from the watch.
9+
If HRM polling is enabled in the `Health` app, sleep tracking can use the HRM sensor to detect sleep status instead. Set `Prefer HRM` in settings to enable. Falls back to using movement calculations if HRM is not available.
1010

1111
#### Explanations
1212
* __Detection of Sleep__
@@ -93,6 +93,8 @@ To make sure the app accurately provides sleep information, it's a good idea to
9393
_10min_ / _20min_ / ... / __30min__ / ... / _120min_
9494
- __Enabled__ | completely en-/disables the background service
9595
__on__ / _off_
96+
- __Prefer HRM__ | en-/disables use of HRM readings if they are available for determining sleep states.
97+
__on__ / _off_
9698
- __Debugging__ submenu
9799
- __View log__ | display logfile data
98100
Select the logfile by its starting time.

apps/sleeplog/boot.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ global.sleeplog = {
1515
lightTh: 300, // threshold for light sleep
1616
wearTemp: 19.5,
1717
hrmDeepTh: 60,
18-
hrmLightTh: 74
18+
hrmLightTh: 74,
19+
preferHRM: false
1920
}, require("Storage").readJSON("sleeplog.json", true) || {})
2021
};
2122

@@ -160,7 +161,7 @@ if (global.sleeplog.conf.enabled) {
160161
data.timestamp = data.timestamp || ((Date.now() / 6E5 | 0) - 1) * 6E5;
161162
// add preliminary status depending on charging and movement thresholds
162163
// 1 = not worn, 2 = awake, 3 = light sleep, 4 = deep sleep
163-
if(data.bpm){
164+
if(data.bpm && global.sleeplog.conf.preferHRM){
164165
data.status = Bangle.isCharging() ? 1 :
165166
data.bpm <= global.sleeplog.conf.hrmDeepTh ? 4 :
166167
data.bpm <= global.sleeplog.conf.hrmLightTh ? 3 : 2;

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.24",
5+
"version": "0.25",
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
lightTh: 300,// threshold for light sleep
1717
hrmLightTh: 74,// threshold for light sleep with HRM
1818
hrmDeepTh:60,// threshold for deep sleep with HRM
19+
preferHRM: false, // prefer hrm based sleep state determination
1920
wearTemp: 19.5, // temperature threshold to count as worn
2021
// app settings
2122
breakToD: 12, // [h] time of day when to start/end graphs
@@ -518,6 +519,13 @@
518519
require("sleeplog").setEnabled(v);
519520
}
520521
},
522+
/*LANG*/"Prefer HRM": {
523+
value: settings.preferHRM,
524+
onchange: v => {
525+
settings.preferHRM = v;
526+
writeSetting();
527+
}
528+
},
521529
/*LANG*/"Debugging": {
522530
value: debugImg,
523531
onchange: () => setTimeout(showDebug, 10)

0 commit comments

Comments
 (0)