From 84f12124fcd410d79fbefefe15f89b9694a6459f Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Thu, 19 Sep 2024 14:06:55 +0100 Subject: [PATCH 01/12] clock_info: describe use of `dynamic` --- apps/clock_info/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/clock_info/README.md b/apps/clock_info/README.md index 031f89121..220a0cf4d 100644 --- a/apps/clock_info/README.md +++ b/apps/clock_info/README.md @@ -50,7 +50,7 @@ extensions). `load()` returns an array of menu objects, where each object contains a list of menu items: * `name` : text to display and identify menu object (e.g. weather) * `img` : a 24x24px image -* `dynamic` : if `true`, items are not constant but are sorted (e.g. calendar events sorted by date) +* `dynamic` : if `true`, items are not constant but are sorted (e.g. calendar events sorted by date). This is only used by a few clocks, for example `circlesclock` * `items` : menu items such as temperature, humidity, wind etc. Note that each item is an object with: From 943de6fca82356297041578150cb5936d874209f Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Thu, 19 Sep 2024 14:07:09 +0100 Subject: [PATCH 02/12] sched/clkinfo: tapping an alarm toggles it on/off --- apps/sched/ChangeLog | 1 + apps/sched/clkinfo.js | 10 ++++++++-- apps/sched/metadata.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/sched/ChangeLog b/apps/sched/ChangeLog index 1b385c8ea..46cf02caa 100644 --- a/apps/sched/ChangeLog +++ b/apps/sched/ChangeLog @@ -27,3 +27,4 @@ 0.24: Emit alarmReload when alarms change (used by widalarm) 0.25: Fix wrap around when snoozed through midnight 0.26: Fix hitting snooze on an alarm after when the snooze would've fired +0.27: Tapping clkinfo enables/disables the selected alarm diff --git a/apps/sched/clkinfo.js b/apps/sched/clkinfo.js index 89402ea67..0140e6067 100644 --- a/apps/sched/clkinfo.js +++ b/apps/sched/clkinfo.js @@ -96,12 +96,13 @@ } var img = iconAlarmOn; + var all = alarm.getAlarms(); //get only alarms not created by other apps var alarmItems = { name: /*LANG*/"Alarms", img: img, dynamic: true, - items: alarm.getAlarms().filter(a=>!a.appid) + items: all.filter(a=>!a.appid) //.sort((a,b)=>alarm.getTimeToAlarm(a)-alarm.getTimeToAlarm(b)) .sort((a,b)=>getAlarmOrder(a)-getAlarmOrder(b)) .map((a, i)=>({ @@ -123,7 +124,12 @@ this.interval = undefined; this.switchTimeout = undefined; }, - run: function() { } + run: function() { + a.on = !a.on; + this.emit("redraw"); + alarm.setAlarms(all); + alarm.reload(); + } })), }; diff --git a/apps/sched/metadata.json b/apps/sched/metadata.json index be4dcdf33..591e9d3e9 100644 --- a/apps/sched/metadata.json +++ b/apps/sched/metadata.json @@ -1,7 +1,7 @@ { "id": "sched", "name": "Scheduler", - "version": "0.26", + "version": "0.27", "description": "Scheduling library for alarms and timers", "icon": "app.png", "type": "scheduler", From 6657d34123fd2936709af3ef314e17ecb9beacd2 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 22 Sep 2024 21:55:11 +0100 Subject: [PATCH 03/12] sched/clkinfo: ignore taps on events --- apps/sched/clkinfo.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/sched/clkinfo.js b/apps/sched/clkinfo.js index 0140e6067..a336c988d 100644 --- a/apps/sched/clkinfo.js +++ b/apps/sched/clkinfo.js @@ -125,6 +125,7 @@ this.switchTimeout = undefined; }, run: function() { + if (a.date) return; // ignore events a.on = !a.on; this.emit("redraw"); alarm.setAlarms(all); From 594d08bf60edf8bd2cfc92cdd91801fc13a0ef0e Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 22 Sep 2024 21:55:26 +0100 Subject: [PATCH 04/12] sched/clkinfo: schedule an alarm via `setAlarm` ... to ensure timers are scheduled from now --- apps/sched/clkinfo.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/sched/clkinfo.js b/apps/sched/clkinfo.js index a336c988d..8a5576181 100644 --- a/apps/sched/clkinfo.js +++ b/apps/sched/clkinfo.js @@ -127,9 +127,13 @@ run: function() { if (a.date) return; // ignore events a.on = !a.on; + if (a.on) { + // use sched to start the alarm, + // so it takes care of timers etc + alarm.setAlarm(a.id, a); + } this.emit("redraw"); - alarm.setAlarms(all); - alarm.reload(); + alarm.reload(); // schedule/unschedule the alarm } })), }; From acc940d99f7e14c69d6ea6f79e6a11c8ab0c4bb5 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Thu, 3 Oct 2024 21:06:44 +0100 Subject: [PATCH 05/12] sched: add `resetTimer()` --- apps/sched/lib.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/sched/lib.js b/apps/sched/lib.js index 13cce1ef2..fcd971fc4 100644 --- a/apps/sched/lib.js +++ b/apps/sched/lib.js @@ -34,14 +34,18 @@ exports.setAlarm = function(id, alarm) { if (alarm.dow===undefined) alarm.dow = 0b1111111; if (alarm.on!==false) alarm.on=true; if (alarm.timer) { // if it's a timer, set the start time as a time from *now* - var time = new Date(); - var currentTime = (time.getHours()*3600000)+(time.getMinutes()*60000)+(time.getSeconds()*1000); - alarm.t = (currentTime + alarm.timer) % 86400000; + exports.resetTimer(alarm); } alarms.push(alarm); } exports.setAlarms(alarms); }; +/// Set a timer's firing time based off the timer's `timer` property + the given time (or now) +exports.resetTimer = function(alarm, time) { + time = time || new Date(); + var currentTime = (time.getHours()*3600000)+(time.getMinutes()*60000)+(time.getSeconds()*1000); + alarm.t = (currentTime + alarm.timer) % 86400000; +}; /// Get time until the given alarm (object). Return undefined if alarm not enabled, or if 86400000 or more, alarm could be *more* than a day in the future exports.getTimeToAlarm = function(alarm, time) { if (!alarm) return undefined; From 5fc1f5cd13805f6f180c6e7f9bdf748cf62012ab Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Thu, 3 Oct 2024 21:07:08 +0100 Subject: [PATCH 06/12] sched clkinfo: revert to toggling `alarm.on` --- apps/sched/clkinfo.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps/sched/clkinfo.js b/apps/sched/clkinfo.js index 8a5576181..3700ee1e5 100644 --- a/apps/sched/clkinfo.js +++ b/apps/sched/clkinfo.js @@ -127,12 +127,8 @@ run: function() { if (a.date) return; // ignore events a.on = !a.on; - if (a.on) { - // use sched to start the alarm, - // so it takes care of timers etc - alarm.setAlarm(a.id, a); - } this.emit("redraw"); + alarm.setAlarms(all); alarm.reload(); // schedule/unschedule the alarm } })), From 46321d91b717f0fe9bed2da626979debe1339404 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Thu, 3 Oct 2024 21:07:39 +0100 Subject: [PATCH 07/12] sched clkinfo: reset a timer when triggering --- apps/sched/clkinfo.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/sched/clkinfo.js b/apps/sched/clkinfo.js index 3700ee1e5..d9ed5fbb4 100644 --- a/apps/sched/clkinfo.js +++ b/apps/sched/clkinfo.js @@ -127,6 +127,7 @@ run: function() { if (a.date) return; // ignore events a.on = !a.on; + if(a.on && a.timer) alarm.resetTimer(a); this.emit("redraw"); alarm.setAlarms(all); alarm.reload(); // schedule/unschedule the alarm From 2517f807544c44d80314aea2dd3591cdd5597825 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Thu, 3 Oct 2024 22:09:35 +0100 Subject: [PATCH 08/12] typescript: update sched.d.ts --- typescript/types/sched.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/typescript/types/sched.d.ts b/typescript/types/sched.d.ts index c2cd23d35..766455dc6 100644 --- a/typescript/types/sched.d.ts +++ b/typescript/types/sched.d.ts @@ -103,6 +103,8 @@ declare module Sched { function setAlarm(id: string, alarm?: NewSched): void; + function resetTimer(alarm: Sched, time?: Date): void; + function getTimeToAlarm(alarm: Sched | undefined | null, time?: Date): number | undefined; function getTimeToAlarm(alarm?: undefined | null, time?: Date): undefined; From 6f4a3b8c780a722426ef9e1761d4b087ffe597b0 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Thu, 3 Oct 2024 22:10:53 +0100 Subject: [PATCH 09/12] typescript: sched.d.ts: distinguish between Timer & Sched --- typescript/types/sched.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/typescript/types/sched.d.ts b/typescript/types/sched.d.ts index 766455dc6..1bcffb632 100644 --- a/typescript/types/sched.d.ts +++ b/typescript/types/sched.d.ts @@ -77,6 +77,8 @@ declare module Sched { } ); + type Timer = Sched & { timer: Milliseconds }; + type Repeat = { num: number, interval: "day" | "week" | "month" | "year", @@ -103,7 +105,7 @@ declare module Sched { function setAlarm(id: string, alarm?: NewSched): void; - function resetTimer(alarm: Sched, time?: Date): void; + function resetTimer(alarm: Timer, time?: Date): void; function getTimeToAlarm(alarm: Sched | undefined | null, time?: Date): number | undefined; function getTimeToAlarm(alarm?: undefined | null, time?: Date): undefined; From a5a915e38aeeb712c87533473e0123897bbdce56 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 6 Oct 2024 11:16:01 +0100 Subject: [PATCH 10/12] sched: add clkinfo icon for events --- apps/sched/clkinfo.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/sched/clkinfo.js b/apps/sched/clkinfo.js index d9ed5fbb4..44fa5c4f9 100644 --- a/apps/sched/clkinfo.js +++ b/apps/sched/clkinfo.js @@ -4,6 +4,7 @@ const iconAlarmOff = atob("GBiBAAAAAAAAAAYAYA4AcBx+ODn/nAP/wAf/4A/n8A/n8B/n+B/n+B/nAB/mAB/geB/5/g/5tg/zAwfzhwPzhwHzAwB5tgAB/gAAeA=="); const iconTimerOn = atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADnAADDAAGBgAGBgAGBgAf/4Af/4AAAAAAAAAAAAA=="); const iconTimerOff = atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADkeADB/gGBtgGDAwGDhwfzhwfzAwABtgAB/gAAeA=="); + const iconEvent = atob("Hh6BAf////////////////////gAAH/AAAD/P//z/P//z/P//z/P//z/AAAD/AAAD/AAAD/AAAD/AAMD/AAcD/AA4D/AxwD/A7gD/AfAD/AOAD/AAAD/AAAD/AAAD/AAAD/gAAH////////////////////w"); //from 0 to max, the higher the closer to fire (as in a progress bar) function getAlarmValue(a){ @@ -20,6 +21,7 @@ } function getAlarmIcon(a) { + if(a.date) return iconEvent; if(a.on) { if(a.timer) return iconTimerOn; return iconAlarmOn; From 5671c8bbe0dedd53ef8cd4737457e207e090cd15 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 6 Oct 2024 11:16:09 +0100 Subject: [PATCH 11/12] sched: add clkinfo text for events --- apps/sched/clkinfo.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/sched/clkinfo.js b/apps/sched/clkinfo.js index 44fa5c4f9..5b4d25cd3 100644 --- a/apps/sched/clkinfo.js +++ b/apps/sched/clkinfo.js @@ -41,6 +41,10 @@ time += "m"; return time; } + if(a.date){ + const d = new Date(a.date); + return `${d.getDate()} ${require("locale").month(d, 1)}`; + } return require("time_utils").formatTime(a.t); } From 4d9deeaa6d662645f20d17f537731e123cc0bdbd Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 6 Oct 2024 22:02:09 +0100 Subject: [PATCH 12/12] sched: fix event icon b/w Co-authored-by: thyttan <97237430+thyttan@users.noreply.github.com> --- apps/sched/clkinfo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sched/clkinfo.js b/apps/sched/clkinfo.js index 5b4d25cd3..65e462042 100644 --- a/apps/sched/clkinfo.js +++ b/apps/sched/clkinfo.js @@ -4,7 +4,7 @@ const iconAlarmOff = atob("GBiBAAAAAAAAAAYAYA4AcBx+ODn/nAP/wAf/4A/n8A/n8B/n+B/n+B/nAB/mAB/geB/5/g/5tg/zAwfzhwPzhwHzAwB5tgAB/gAAeA=="); const iconTimerOn = atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADnAADDAAGBgAGBgAGBgAf/4Af/4AAAAAAAAAAAAA=="); const iconTimerOff = atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADkeADB/gGBtgGDAwGDhwfzhwfzAwABtgAB/gAAeA=="); - const iconEvent = atob("Hh6BAf////////////////////gAAH/AAAD/P//z/P//z/P//z/P//z/AAAD/AAAD/AAAD/AAAD/AAMD/AAcD/AA4D/AxwD/A7gD/AfAD/AOAD/AAAD/AAAD/AAAD/AAAD/gAAH////////////////////w"); + const iconEvent = atob("GBiBAAAAAAAAAAAAAA//8B//+BgAGBgAGBgAGB//+B//+B//+B/++B/8+B/5+B8z+B+H+B/P+B//+B//+B//+A//8AAAAAAAAAAAAA=="); //from 0 to max, the higher the closer to fire (as in a progress bar) function getAlarmValue(a){