diff --git a/apps/sleeplog/boot.js b/apps/sleeplog/boot.js index e956c5ed1..ac7e63b1e 100644 --- a/apps/sleeplog/boot.js +++ b/apps/sleeplog/boot.js @@ -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