feat: save alarms across reboots
Signed-off-by: thiswillbeyourgithub <github@32mail.33mail.com>
This commit is contained in:
parent
3f054b40e1
commit
6e9b7b374d
1 changed files with 18 additions and 8 deletions
|
@ -87,14 +87,16 @@ class AlarmApp:
|
||||||
self.alarms = (bytearray(3), bytearray(3), bytearray(3), bytearray(3))
|
self.alarms = (bytearray(3), bytearray(3), bytearray(3), bytearray(3))
|
||||||
self.pending_alarms = array.array('d', [0.0, 0.0, 0.0, 0.0])
|
self.pending_alarms = array.array('d', [0.0, 0.0, 0.0, 0.0])
|
||||||
|
|
||||||
# Set a nice default
|
self.num_alarms = 0
|
||||||
self.num_alarms = 1
|
try:
|
||||||
for alarm in self.alarms:
|
with open("alarms", "r") as f:
|
||||||
alarm[_HOUR_IDX] = 8
|
alarms = "".join(f.readlines()).split(";")
|
||||||
alarm[_MIN_IDX] = 0
|
for alarm in alarms:
|
||||||
alarm[_ENABLED_IDX] = 0
|
n = self.num_alarms
|
||||||
self.alarms[0][_ENABLED_IDX] = _WEEKDAYS
|
self.alarms[n][:] = map(int, alarm.split(","))
|
||||||
|
self.num_alarms += 1
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
def foreground(self):
|
def foreground(self):
|
||||||
"""Activate the application."""
|
"""Activate the application."""
|
||||||
|
@ -137,6 +139,14 @@ class AlarmApp:
|
||||||
del self.day_btns
|
del self.day_btns
|
||||||
|
|
||||||
self._set_pending_alarms()
|
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):
|
def tick(self, ticks):
|
||||||
"""Notify the application that its periodic tick is due."""
|
"""Notify the application that its periodic tick is due."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue