From 1174faafbf2db3c4397ff4ed3158045109b2f8fe Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Fri, 3 Feb 2023 18:03:44 +0100 Subject: [PATCH] sleepphasealarm 0.14 Reduce update interval of current time when seconds are not shown --- apps/sleepphasealarm/ChangeLog | 1 + apps/sleepphasealarm/app.js | 26 ++++++++++++++++++++------ apps/sleepphasealarm/metadata.json | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/apps/sleepphasealarm/ChangeLog b/apps/sleepphasealarm/ChangeLog index 4815e5e75..5a7be5b20 100644 --- a/apps/sleepphasealarm/ChangeLog +++ b/apps/sleepphasealarm/ChangeLog @@ -14,3 +14,4 @@ 0.11: Minor tweaks 0.12: Support javascript command to execute as defined in scheduler 'js' configuration 0.13: Fix dated events alarm on wrong date +0.14: Reduce update interval of current time when seconds are not shown diff --git a/apps/sleepphasealarm/app.js b/apps/sleepphasealarm/app.js index 0aef07760..c74303b76 100644 --- a/apps/sleepphasealarm/app.js +++ b/apps/sleepphasealarm/app.js @@ -14,6 +14,7 @@ const active = alarms.filter(alarm => require("sched").getTimeToAlarm(alarm)); const schedSettings = require("sched").getSettings(); let buzzCount = schedSettings.buzzCount; let logs = []; +let drawTimeTimeout; // Sleep/Wake detection with Estimation of Stationary Sleep-segments (ESS): // Marko Borazio, Eugen Berlin, Nagihan Kücükyildiz, Philipp M. Scholl and Kristof Van Laerhoven, "Towards a Benchmark for Wearable Sleep Analysis with Inertial Wrist-worn Sensing Units", ICHI 2014, Verona, Italy, IEEE Press, 2014. @@ -26,7 +27,7 @@ const nomothresh=0.023; // Original implementation: 6, resolution 11 bit, scale const sleepthresh=600; var ess_values = []; var slsnds = 0; -function calc_ess(acc_magn) { +function calc_ess(acc_magn) {"ram" ess_values.push(acc_magn); if (ess_values.length == winwidth) { @@ -90,10 +91,12 @@ function drawApp() { layout.alarm_date.label = `${LABEL_WAKEUP_TIME}: ${alarmHour}:${alarmMinute}`; layout.render(); - function drawTime() { + function drawTime() {"ram" + const drawSeconds = !Bangle.isLocked(); + if (Bangle.isLCDOn()) { const now = new Date(); - layout.date.label = locale.time(now, BANGLEJS2 && Bangle.isLocked() ? 1 : 0); // hide seconds on bangle 2 + layout.date.label = locale.time(now, !drawSeconds); // hide seconds on bangle 2 const diff = nextAlarmDate - now; const diffHour = Math.floor((diff % 86400000) / 3600000).toString(); const diffMinutes = Math.floor(((diff % 86400000) % 3600000) / 60000).toString(); @@ -101,11 +104,22 @@ function drawApp() { layout.render(); } - setTimeout(()=>{ + const period = drawSeconds ? 1000 : 60000; + if (this.drawTimeTimeout !== undefined) { + clearTimeout(this.drawTimeTimeout); + } + drawTimeTimeout = setTimeout(()=>{ + drawTimeTimeout = undefined; drawTime(); - }, 1000 - (Date.now() % 1000)); + }, period - (Date.now() % period)); } + Bangle.on('lock', function(on) { + if (on === false) { + drawTime(); + } + }); + drawTime(); } @@ -146,7 +160,7 @@ if (nextAlarmDate !== undefined) { layout.render(); Bangle.setOptions({powerSave: false}); // do not dynamically change accelerometer poll interval Bangle.setPollInterval(80); // 12.5Hz - Bangle.on('accel', (accelData) => { + Bangle.on('accel', (accelData) => {"ram" const now = new Date(); const acc = accelData.mag; const swest = calc_ess(acc); diff --git a/apps/sleepphasealarm/metadata.json b/apps/sleepphasealarm/metadata.json index 5382160c0..7e8d2b1a0 100644 --- a/apps/sleepphasealarm/metadata.json +++ b/apps/sleepphasealarm/metadata.json @@ -2,7 +2,7 @@ "id": "sleepphasealarm", "name": "SleepPhaseAlarm", "shortName": "SleepPhaseAlarm", - "version": "0.13", + "version": "0.14", "description": "Uses the accelerometer to estimate sleep and wake states with the principle of Estimation of Stationary Sleep-segments (ESS, see https://ubicomp.eti.uni-siegen.de/home/datasets/ichi14/index.html.en). This app will read the next alarm from the alarm application and will wake you up to 30 minutes early at the best guessed time when you are almost already awake.", "icon": "app.png", "tags": "alarm",