Update alarms code

This commit is contained in:
Simon Larsson
2020-05-30 08:57:20 +02:00
parent aa6129723d
commit 752d645324
2 changed files with 20 additions and 24 deletions
+13 -20
View File
@@ -86,31 +86,24 @@ class TimexAlarm:
self.day = day
self.label = label
self.audible = audible
self.seq=0
def __bytes__(self):
# TODO: Adapt for 150 series
data = [self.seq] # TODO: Should be alarm sequence ID! (1-5)
data += [self.hour, self.minute, self.month, self.day]
def __str__(self):
audible_str = "audible" if self.audible else "inaudible"
label = self.label
if len(label)<8: # Min 8 chars, pad with space
label +=" "*(8-len(label))
label = label[:8] # Max 8 chars
data += str2timex(label)
if self.day==0 and self.month==0:
return "Alarm at {:02d}:{:02d}, label \"{}\", {}".format(
self.hour, self.minute, self.label, audible_str)
if self.audible:
data += [1]
else:
data += [0]
if self.day==0:
return "Alarm at {:02d}:{:02d} every day in {}, label \"{}\", {}".format(
self.hour, self.minute, monthNamesAbbr[self.month], self.label, audible_str)
pkgdata = makepkg([0x50]+data)
if self.month==0:
return "Alarm at {:02d}:{:02d} on the {}, label \"{}\", {}".format(
self.hour, self.minute, self.day, self.label, audible_str)
if not self.audible:
data = [0, 0x61+self.seq, 0]
pkgdata += makepkg([0x70]+data)
return bytes(pkgdata)
return "Alarm at {:02d}:{:02d} on the {} of {}, label \"{}\", {}".format(
self.hour, self.minute, self.day, monthNamesAbbr[self.month], self.label, audible_str)
class TimexData:
def __init__(self):
+7 -4
View File
@@ -10,10 +10,13 @@ d = pytimex.TimexData()
#(self, hour=0, minute=0, month=0, day=0, label="", audible=True):
d.addNewAlarm(9,0,0,0,"sample",True)
d.addNewAlarm(1, 1, 5, 21, "cafe", True)
d.addNewAlarm(0, 0, 0, 23, "babee", True)
d.addNewAlarm(0, 0, 0, 0, "alarm #4", False)
d.addNewAlarm(0, 0, 0, 0, "alarm #5", False)
d.addNewAlarm(1, 1, 5, 21, "test", True)
d.addNewAlarm(0, 0, 0, 23, "example", True)
d.addNewAlarm(0, 10, 1, 0, "alarm #4", False)
d.addNewAlarm(10, 0, 0, 0, "alarm #5", False)
for a in d.alarms:
print(str(a))
data = bytes(d)
print(listhex(data))