Determine if worn based on temperature threshold

master
Ishidres 2024-03-11 18:10:13 +01:00
parent 1aa6474974
commit c4a25b6be1
1 changed files with 13 additions and 0 deletions

View File

@ -13,6 +13,7 @@ global.sleeplog = {
minConsec: 18E5, // [ms] minimal time to count for consecutive sleep
deepTh: 100, // threshold for deep sleep
lightTh: 200, // threshold for light sleep
wearTemp: 27, // temperature threshold to count as worn
}, require("Storage").readJSON("sleeplog.json", true) || {})
};
@ -166,12 +167,18 @@ if (sleeplog.conf.enabled) {
// check if changing to deep sleep from non sleeping
if (data.status === 4 && sleeplog.status <= 2) {
// check wearing status
if (sleeplog.isNotWorn()) {
data.status = 1;
}
/*
sleeplog.checkIsWearing((isWearing, data) => {
// correct status
if (!isWearing) data.status = 1;
// set status
sleeplog.setStatus(data);
}, data);
*/
} else {
// set status
sleeplog.setStatus(data);
@ -209,6 +216,12 @@ if (sleeplog.conf.enabled) {
}, 2500, returnFn, data);
},
// Determine if Bangle.JS is worn based on temperature (same strategy as in activityreminder)
// https://github.com/espruino/BangleApps/blob/master/apps/activityreminder/boot.js#L37
isNotWorn: function() {
return (Bangle.isCharging() || this.conf.wearTemp >= E.getTemperature());
},
// define function to set the status
setStatus: function(data) {
// update lastCheck