From 3f054b40e1533936afa2326001140e43cfdcbcf3 Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub Date: Wed, 20 Jul 2022 10:18:41 +0200 Subject: [PATCH 1/8] docs: mention that pressing the button will stop the watch Signed-off-by: thiswillbeyourgithub --- wasp/apps/alarm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wasp/apps/alarm.py b/wasp/apps/alarm.py index 662b099..9489cd4 100644 --- a/wasp/apps/alarm.py +++ b/wasp/apps/alarm.py @@ -6,6 +6,7 @@ ~~~~~~~~~~~~~~~~~~~~ An application to set a vibration alarm. All settings can be accessed from the Watch UI. +Press the button to turn of ringing alarms. .. figure:: res/AlarmApp.png :width: 179 From 6e9b7b374deec78ebad0b05838b826b101d6f139 Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub Date: Wed, 20 Jul 2022 10:19:02 +0200 Subject: [PATCH 2/8] feat: save alarms across reboots Signed-off-by: thiswillbeyourgithub --- wasp/apps/alarm.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/wasp/apps/alarm.py b/wasp/apps/alarm.py index 9489cd4..3cacf3a 100644 --- a/wasp/apps/alarm.py +++ b/wasp/apps/alarm.py @@ -87,14 +87,16 @@ class AlarmApp: self.alarms = (bytearray(3), bytearray(3), bytearray(3), bytearray(3)) self.pending_alarms = array.array('d', [0.0, 0.0, 0.0, 0.0]) - # Set a nice default - self.num_alarms = 1 - for alarm in self.alarms: - alarm[_HOUR_IDX] = 8 - alarm[_MIN_IDX] = 0 - alarm[_ENABLED_IDX] = 0 - self.alarms[0][_ENABLED_IDX] = _WEEKDAYS - + self.num_alarms = 0 + try: + with open("alarms", "r") as f: + alarms = "".join(f.readlines()).split(";") + for alarm in alarms: + n = self.num_alarms + self.alarms[n][:] = map(int, alarm.split(",")) + self.num_alarms += 1 + except Exception: + pass def foreground(self): """Activate the application.""" @@ -137,6 +139,14 @@ class AlarmApp: del self.day_btns self._set_pending_alarms() + try: + with open("alarms", "w") as f: + for n in range(self.num_alarms): + al = self.alarms[n] + f.write(",".join(map(str, al)) + ";") + except Exception: + pass + def tick(self, ticks): """Notify the application that its periodic tick is due.""" From cb51e83a282c1d6550bd7559ee9f70927c4be005 Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub Date: Wed, 20 Jul 2022 10:19:17 +0200 Subject: [PATCH 3/8] new: increment minutes by 5 instead of 1 Signed-off-by: thiswillbeyourgithub --- wasp/apps/alarm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasp/apps/alarm.py b/wasp/apps/alarm.py index 3cacf3a..92389f9 100644 --- a/wasp/apps/alarm.py +++ b/wasp/apps/alarm.py @@ -103,7 +103,7 @@ class AlarmApp: self.del_alarm_btn = widgets.Button(170, 204, 70, 35, 'DEL') self.hours_wid = widgets.Spinner(50, 30, 0, 23, 2) - self.min_wid = widgets.Spinner(130, 30, 0, 59, 2) + self.min_wid = widgets.Spinner(130, 30, 0, 59, 2, 5) self.day_btns = (widgets.ToggleButton(10, 145, 40, 35, 'Mo'), widgets.ToggleButton(55, 145, 40, 35, 'Tu'), widgets.ToggleButton(100, 145, 40, 35, 'We'), From 040edba1f74d67684935cea542c685fac9c360c9 Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub Date: Wed, 20 Jul 2022 11:41:11 +0200 Subject: [PATCH 4/8] fix: asked by daniel_thompson Signed-off-by: thiswillbeyourgithub --- wasp/apps/alarm.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wasp/apps/alarm.py b/wasp/apps/alarm.py index 92389f9..dc8eb29 100644 --- a/wasp/apps/alarm.py +++ b/wasp/apps/alarm.py @@ -6,7 +6,7 @@ ~~~~~~~~~~~~~~~~~~~~ An application to set a vibration alarm. All settings can be accessed from the Watch UI. -Press the button to turn of ringing alarms. +Press the button to turn off ringing alarms. .. figure:: res/AlarmApp.png :width: 179 @@ -91,10 +91,10 @@ class AlarmApp: try: with open("alarms", "r") as f: alarms = "".join(f.readlines()).split(";") - for alarm in alarms: - n = self.num_alarms - self.alarms[n][:] = map(int, alarm.split(",")) - self.num_alarms += 1 + for alarm in alarms: + n = self.num_alarms + self.alarms[n][:] = map(int, alarm.split(",")) + self.num_alarms += 1 except Exception: pass From 20027dc16a8bfc8194a4c6aac310ae576a3eb020 Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub Date: Wed, 20 Jul 2022 18:14:32 +0200 Subject: [PATCH 5/8] fix: don't erase previous alarm if none loaded Signed-off-by: thiswillbeyourgithub --- wasp/apps/alarm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wasp/apps/alarm.py b/wasp/apps/alarm.py index dc8eb29..6ba0d9b 100644 --- a/wasp/apps/alarm.py +++ b/wasp/apps/alarm.py @@ -140,6 +140,8 @@ class AlarmApp: self._set_pending_alarms() try: + if self.num_alarms == 0: + return with open("alarms", "w") as f: for n in range(self.num_alarms): al = self.alarms[n] From d12cd8d4525b874040d62ae61766e8d9ac85d49a Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub Date: Mon, 25 Jul 2022 21:42:33 +0200 Subject: [PATCH 6/8] fix: files without suffix are deleted Signed-off-by: thiswillbeyourgithub --- wasp/apps/alarm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wasp/apps/alarm.py b/wasp/apps/alarm.py index 6ba0d9b..9ceab33 100644 --- a/wasp/apps/alarm.py +++ b/wasp/apps/alarm.py @@ -89,7 +89,7 @@ class AlarmApp: self.num_alarms = 0 try: - with open("alarms", "r") as f: + with open("alarms.txt", "r") as f: alarms = "".join(f.readlines()).split(";") for alarm in alarms: n = self.num_alarms @@ -142,7 +142,7 @@ class AlarmApp: try: if self.num_alarms == 0: return - with open("alarms", "w") as f: + with open("alarms.txt", "w") as f: for n in range(self.num_alarms): al = self.alarms[n] f.write(",".join(map(str, al)) + ";") From a39683021d723dc4a8e4638b237ebd99f880e58e Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub Date: Mon, 25 Jul 2022 22:04:10 +0200 Subject: [PATCH 7/8] fix Signed-off-by: thiswillbeyourgithub --- wasp/apps/alarm.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wasp/apps/alarm.py b/wasp/apps/alarm.py index 9ceab33..7b035c1 100644 --- a/wasp/apps/alarm.py +++ b/wasp/apps/alarm.py @@ -90,10 +90,15 @@ class AlarmApp: self.num_alarms = 0 try: with open("alarms.txt", "r") as f: - alarms = "".join(f.readlines()).split(";") + alarms = f.readlines()[0].split(";") + if "" in alarms: + alarms.remove("") for alarm in alarms: n = self.num_alarms - self.alarms[n][:] = map(int, alarm.split(",")) + h, m, st = map(int, alarm.split(",")) + self.alarms[n][0] = h + self.alarms[n][1] = m + self.alarms[n][2] = st self.num_alarms += 1 except Exception: pass From d49324422d3be58cdcc31ee0daadf5057ccbc02a Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub Date: Thu, 28 Jul 2022 20:35:24 +0200 Subject: [PATCH 8/8] fix: activate alarm at boot Signed-off-by: thiswillbeyourgithub --- wasp/apps/alarm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wasp/apps/alarm.py b/wasp/apps/alarm.py index 7b035c1..843de2d 100644 --- a/wasp/apps/alarm.py +++ b/wasp/apps/alarm.py @@ -102,6 +102,7 @@ class AlarmApp: self.num_alarms += 1 except Exception: pass + self._set_pending_alarms() def foreground(self): """Activate the application."""