From c8c1b7b91437199fe10c701ca375477e19f0f43b Mon Sep 17 00:00:00 2001 From: storm64 Date: Sun, 13 Feb 2022 22:39:57 +0100 Subject: [PATCH] sleeplog: Prevent removing other kill listeners #1445 Update boot.js - prevent removing other kill listeners #1445 Update README.md - change "only available" information for Settings - add new ideas to "To do list" --- apps/sleeplog/ChangeLog | 2 +- apps/sleeplog/README.md | 14 ++++++++++---- apps/sleeplog/boot.js | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/sleeplog/ChangeLog b/apps/sleeplog/ChangeLog index dae137b19..b82555903 100644 --- a/apps/sleeplog/ChangeLog +++ b/apps/sleeplog/ChangeLog @@ -1,3 +1,3 @@ 0.01: New App! 0.02: Fix crash on start -0.03: Added power saving mode + move all read/write log actions into lib/module +0.03: Added power saving mode, move all read/write log actions into lib/module, fix #1445 diff --git a/apps/sleeplog/README.md b/apps/sleeplog/README.md index d5c706940..32a14839a 100644 --- a/apps/sleeplog/README.md +++ b/apps/sleeplog/README.md @@ -49,14 +49,17 @@ also provides a power saving mode using the built in movement calculation. The i * __PowerSaving__ _on_ / __off__ En-/Disable power saving mode. _Saves battery, but might decrease accurracy._ -* __MaxMove__ | maximal movement threshold | only available when on power saving mode +* __MaxMove__ | maximal movement threshold + (only available when on power saving mode) _50_ / _51_ / _..._ / __100__ / _..._ / _200_ On power saving mode the watch is considered resting if this threshold is lower or equal to the movement value of bangle's health event. -* __NoMoThresh__ | no movement threshold | only available when not on power saving mode +* __NoMoThresh__ | no movement threshold + (only available when not on power saving mode) _0.006_ / _0.007_ / _..._ / __0.012__ / _..._ / _0.020_ The standard deviation over the measured values needs to be lower then this threshold to count as not moving. The defaut threshold value worked best for my watch. A threshold value below 0.008 may get triggert by noise. -* __MinDuration__ | minimal no movement duration | only available when not on power saving mode +* __MinDuration__ | minimal no movement duration + (only available when not on power saving mode) _5min_ / _6min_ / _..._ / __10min__ / _..._ / _15min_ If no movement is detected for this duration, the watch is considered as resting. * __Enabled__ @@ -77,7 +80,8 @@ For easy access from the console or other apps the following parameters, values enabled: true, // bool / service status indicator logfile: "sleeplog.log", // string / used logfile resting: false, // bool / indicates if the watch is resting - status: 2, // int / actual status: 0 = unknown, 1 = not worn, 2 = awake, 3 = sleeping + status: 2, // int / actual status: + / undefined = service stopped, 0 = unknown, 1 = not worn, 2 = awake, 3 = sleeping firstnomodate: 1644435877595, // number / Date.now() from first recognised no movement, not available in power saving mode stop: function () { ... }, // funct / stops the service until the next load() start: function () { ... }, // funct / restarts the service @@ -144,7 +148,9 @@ For easy access from the console or other apps the following parameters, values #### To do list * Send the logged information to Gadgetbridge. _(For now I have no idea how to achieve this, help is appreciated.)_ +* View, down- and upload log functions via App Loader. * Calculate and display overall sleep statistics. +* Option to automatically change power saving mode depending on time of day. #### Requests, Bugs and Feedback Please leave requests and bug reports by raising an issue at [github.com/storm64/BangleApps](https://github.com/storm64/BangleApps) or send me a [mail](mailto:banglejs@storm64.de). diff --git a/apps/sleeplog/boot.js b/apps/sleeplog/boot.js index 623463d69..254d7671b 100644 --- a/apps/sleeplog/boot.js +++ b/apps/sleeplog/boot.js @@ -33,7 +33,7 @@ if (sleeplog.enabled) { // remove all listeners Bangle.removeListener('accel', sleeplog.accel); Bangle.removeListener('health', sleeplog.health); - E.removeListener('kill', sleeplog.stop); + E.removeListener('kill', () => sleeplog.stop()); // exit on missing global object if (!global.sleeplog) return; // write log with undefined sleeping status @@ -55,7 +55,7 @@ if (sleeplog.enabled) { // add acceleration listener if defined and set status to unknown if (sleeplog.accel) Bangle.on('accel', sleeplog.accel); // add kill listener - E.on('kill', sleeplog.stop); + E.on('kill', () => sleeplog.stop()); // read log since 5min ago and restore status to last known state or unknown sleeplog.status = (require("sleeplog").readLog(0, Date.now() - 3E5)[1] || [0, 0])[1] // update resting according to status