diff --git a/apps/sleepphasealarm/README.md b/apps/sleepphasealarm/README.md new file mode 100644 index 000000000..04388194f --- /dev/null +++ b/apps/sleepphasealarm/README.md @@ -0,0 +1,15 @@ +# Sleep Phase Alarm + +The display shows: + +- the current time +- time of the next alarm or timer +- time difference between current time and alarm time (ETA) +- current state of the ESS algorithm, "Sleep" or "Awake", useful for debugging + +## Logging + +For each day of month (1..31) the ESS states are logged. An entry will be overwritten in the next month, e.g. an entry on the 4th May will overwrite an entry on the 4th April. +The logs can be viewed with the download button: + +![](screenshot.jpg) diff --git a/apps/sleepphasealarm/app.js b/apps/sleepphasealarm/app.js index a2c8504f0..9bde85452 100644 --- a/apps/sleepphasealarm/app.js +++ b/apps/sleepphasealarm/app.js @@ -1,4 +1,4 @@ -const BANGLEJS2 = process.env.HWVERSION == 2; //# check for bangle 2 +const BANGLEJS2 = process.env.HWVERSION == 2; // check for bangle 2 const Layout = require("Layout"); const locale = require('locale'); const alarms = require("Storage").readJSON("sched.json",1) || []; @@ -135,9 +135,9 @@ if (nextAlarm !== undefined) { // log if (swest_last != swest) { if (swest) { - addLog(new Date(Date.now() - sleepthresh*13/12.5*1000), "sleep"); // calculate begin of no motion phase, 13 values/second at 12.5Hz + addLog(new Date(now - sleepthresh*13/12.5*1000), "sleep"); // calculate begin of no motion phase, 13 values/second at 12.5Hz } else { - addLog(new Date(), "awake"); + addLog(now, "awake"); } swest_last = swest; } @@ -145,9 +145,10 @@ if (nextAlarm !== undefined) { if (now >= nextAlarm) { // The alarm widget should handle this one + addLog(now, "alarm"); setTimeout(load, 1000); } else if (measure && now >= minAlarm && swest === false) { - addLog(new Date(), "alarm"); + addLog(now, "alarm"); buzz(); measure = false; } diff --git a/apps/sleepphasealarm/interface.html b/apps/sleepphasealarm/interface.html index d9e5a2504..02fd60626 100644 --- a/apps/sleepphasealarm/interface.html +++ b/apps/sleepphasealarm/interface.html @@ -27,12 +27,12 @@ function getData() { Util.showModal("Loading..."); // get the data Util.readStorageFile('sleepphasealarm.json',data=>{ - data = '{"logs":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[{"time":"2022-04-21T19:03:02.130Z","type":"awake"},{"time":"2022-04-21T19:03:35.219Z","type":"sleep"},{"time":"2022-04-21T19:16:08.958Z","type":"awake"},{"time":"2022-04-21T19:16:08.994Z","type":"alarm"}]]}'; let logs = JSON.parse(data || "{}")?.logs || []; // remove window Util.hideModal(); logs = logs.filter(log => log != null); + logs.sort(function(a, b) {return new Date(b?.filter(entry => entry.type === "alarm")[0]?.time) - new Date(a?.filter(entry => entry.type === "alarm")[0]?.time)}); // sort by alarm date desc logs.forEach((log, i) => { const timeStr = log.filter(entry => entry.type === "alarm")[0]?.time; if (timeStr) { @@ -64,6 +64,7 @@ function getData() { x: { type: 'time', time: { + tooltipFormat: 'HH:mm', displayFormats: { millisecond: 'HH:mm:ss.SSS', second: 'HH:mm:ss', @@ -77,7 +78,11 @@ function getData() { }, plugins: { tooltip: { - enabled: false + callbacks: { + label: function(context) { + return yTicks[context.raw]; + } + } }, } } diff --git a/apps/sleepphasealarm/metadata.json b/apps/sleepphasealarm/metadata.json index aba240e37..f55854f35 100644 --- a/apps/sleepphasealarm/metadata.json +++ b/apps/sleepphasealarm/metadata.json @@ -7,6 +7,7 @@ "icon": "app.png", "tags": "alarm", "supports": ["BANGLEJS","BANGLEJS2"], + "readme": "README.md", "dependencies": {"scheduler":"type"}, "storage": [ {"name":"sleepphasealarm.app.js","url":"app.js"}, diff --git a/apps/sleepphasealarm/screenshot.jpg b/apps/sleepphasealarm/screenshot.jpg new file mode 100644 index 000000000..b1fd05dec Binary files /dev/null and b/apps/sleepphasealarm/screenshot.jpg differ diff --git a/core b/core index 44d49cdbd..89049a5c7 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 44d49cdbd59dc6a7e09cc0facee89d338ccc7d04 +Subproject commit 89049a5c7c80d2b56dc235d135fc63b80789db96 diff --git a/css/main.css b/css/main.css index f4850babe..c4e5286cc 100644 --- a/css/main.css +++ b/css/main.css @@ -81,7 +81,7 @@ a.btn.btn-link.dropdown-toggle { min-height: 8em; } -.tile-content { position: relative; } +.tile-content { position: relative; word-break: break-word; } .link-github { position:absolute; top: 36px;