Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -16,3 +16,4 @@
0.18: Add back as a function to prevent translation making it a menu entry
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.
42 changes: 27 additions & 15 deletions apps/sleeplog/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Sleep Log

This app logs and displays the following states:
- sleepling status: _unknown, not worn, awake, light sleep, deep sleep_
- sleeping status: _unknown, not worn, awake, light sleep, deep sleep_
- consecutive sleep status: _unknown, not consecutive, consecutive_

It is using the built in movement calculation 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.
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.

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.

#### Explanations
* __Detection of Sleep__
Expand Down Expand Up @@ -55,23 +57,32 @@ Logfiles are not removed on un-/reinstall to prevent data loss.
### Settings Usage
---

- __Thresholds__ submenu
- __HRM Thresholds__ submenu

Changes take effect from now on, not retrospective! HRM works only if polling is enabled in `Health` settings
- __Deep Sleep__ | deep sleep threshold
_30_ / _31_ / ... / __100__ / ... / _200_
- __Light Sleep__ | light sleep threshold
_100_ / _110_ / ... / __200__ / ... / _400_
- __Reset to Default__ | reset to bold values above
- __Movement Thresholds__ submenu

Changes take effect from now on, not retrospective!
- __Max Awake__ | maximal awake duration
_10min_ / _20min_ / ... / __60min__ / ... / _120min_
- __Min Consecutive__ | minimal consecutive sleep duration
_10min_ / _20min_ / ... / __30min__ / ... / _120min_
- __Deep Sleep__ | deep sleep threshold
_30_ / _31_ / ... / __100__ / ... / _200_
- __Light Sleep__ | light sleep threshold
_100_ / _110_ / ... / __200__ / ... / _400_
- __Wear Temperature__ | Set the minimum measured temperature of the wearable to consider it being worn. Can be disabled to use the HRM instead to detect if it's being worn.
__Disabled__ / _20.0°C_ / _20.5°C_ / ... / _40.0°C_
- __Reset to Default__ | reset to bold values above
- __BreakToD__ | time of day to break view
_0:00_ / _1:00_ / ... / __12:00__ / ... / _23:00_
- __App Timeout__ | app specific lock timeout
__0s__ / _10s_ / ... / _120s_
- __Reset to Default__ | reset to bold values above
- __Other Settings__ submenu
- __BreakToD__ | time of day to break view
_0:00_ / _1:00_ / ... / __12:00__ / ... / _23:00_
- __App Timeout__ | app specific lock timeout
__0s__ / _10s_ / ... / _120s_
- __Wear Temperature__ | Set the minimum measured temperature of the wearable to consider it being worn. Can be disabled to use the HRM instead to detect if it's being worn.
- __Max Awake__ | maximal awake duration
_10min_ / _20min_ / ... / __60min__ / ... / _120min_
- __Min Consecutive__ | minimal consecutive sleep duration
_10min_ / _20min_ / ... / __30min__ / ... / _120min_
- __Enabled__ | completely en-/disables the background service
__on__ / _off_
- __Debugging__ submenu
Expand Down Expand Up @@ -231,7 +242,8 @@ Please leave requests and bug reports by raising an issue at [github.com/storm64
Storm64 ([mail](mailto:banglejs@storm64.de), [github](https://github.com/storm64))

#### Contributors
myxor ([github](https://github.com/myxor))
- myxor ([github](https://github.com/myxor))
- RKBoss6

#### Attributions
The app icon is downloaded from [https://icons8.com](https://icons8.com).
Expand Down
30 changes: 25 additions & 5 deletions apps/sleeplog/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ global.sleeplog = {
minConsec: 18E5, // [ms] minimal time to count for consecutive sleep
deepTh: 150, // threshold for deep sleep
lightTh: 300, // threshold for light sleep
wearTemp: 19.5, // temperature threshold to count as worn
wearTemp: 19.5,
hrmDeepTh: 60,
hrmLightTh: 74
}, require("Storage").readJSON("sleeplog.json", true) || {})
};

Expand Down Expand Up @@ -160,10 +162,28 @@ if (global.sleeplog.conf.enabled) {

// add preliminary status depending on charging and movement thresholds
// 1 = not worn, 2 = awake, 3 = light sleep, 4 = deep sleep
data.status = Bangle.isCharging() ? 1 :
data.movement <= global.sleeplog.conf.deepTh ? 4 :
data.movement <= global.sleeplog.conf.lightTh ? 3 : 2;

if(data.hrm){

if (!Bangle.isCharging()) {
if (data.heartRate <= global.sleeplog.conf.hrDeepTh) {
data.status = 4; // deep sleep
} else if (data.heartRate <= global.sleeplog.conf.hrLightTh) {
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;
}


// check if changing to deep sleep from non sleeping
if (data.status === 4 && global.sleeplog.status <= 2) {
global.sleeplog.checkIsWearing((isWearing, data) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/sleeplog/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"id":"sleeplog",
"name":"Sleep Log",
"shortName": "SleepLog",
"version": "0.20",
"description": "Log and view your sleeping habits. This app uses built in movement calculations. View data from Bangle, or from the web app.",
"version": "0.21",
"description": "Log and view your sleeping habits. This app uses built in movement calculations, or HRM data is present. View data from Bangle, or from the web app.",
"icon": "app.png",
"type": "app",
"tags": "tool,boot,health",
Expand Down
Loading