1
0
Fork 0

sleepphasealarm

add README.md
master
Erik Andresen 2022-04-28 10:21:54 +02:00
parent d1d50bb965
commit edaa4da5b3
7 changed files with 30 additions and 8 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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];
}
}
},
}
}

View File

@ -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"},

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

2
core

@ -1 +1 @@
Subproject commit 44d49cdbd59dc6a7e09cc0facee89d338ccc7d04
Subproject commit 89049a5c7c80d2b56dc235d135fc63b80789db96

View File

@ -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;