From 5d2de0923d3b33af2516766d51bea3e021407c11 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sun, 22 Jan 2012 18:14:50 +0100 Subject: client: read current alarms --- client/ur_fuzzy_alarm_clock.py | 65 +++++++++++------------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) (limited to 'client') diff --git a/client/ur_fuzzy_alarm_clock.py b/client/ur_fuzzy_alarm_clock.py index 752da46..e86d6fd 100755 --- a/client/ur_fuzzy_alarm_clock.py +++ b/client/ur_fuzzy_alarm_clock.py @@ -19,7 +19,7 @@ class FuzzyAlarmClock: def __init__(self,device): try: - self.serial = serial.Serial(device,9600) + self.serial = serial.Serial(device,9600,timeout=5) except serial.serialutil.SerialException: sys.stderr.write('No such serial device '+device+'\n') sys.exit(1) @@ -28,53 +28,20 @@ class FuzzyAlarmClock: now = 's'+datetime.datetime.now().strftime("%y%m%d%u%H%M%S") self.serial.write(now) - def read_alarms(self): - return [ - [ True, - True, - True, - True, - True, - True, - True, - True, - 0, 0, - 10, 23 - ], - [ False, - False, - False, - False, - False, - False, - False, - False, - 10, 20, - 10, 23 - ], - [ True, - True, - True, - False, - True, - True, - False, - True, - 0, 0, - 10, 23 - ], - [ True, - True, - False, - True, - True, - False, - True, - False, - 12, 1, - 10, 23 - ], - ] + def read_alarms(self,n): + data = [] + self.serial.flushInput() + self.serial.write('p') + for i in xrange(n): + data.append(self.serial.readline()) + for i in xrange(n): + data[i] = data[i].split(' ')[2:-1] + days = [] + for j in xrange(8): + days.append(bool(int(data[i][0]) & 2**j)) + days.reverse() + data[i] = days+data[i][1:] + return data def set_alarm(self,alarm,values): s = 'a'+str(alarm) @@ -221,7 +188,7 @@ class UI: pass def read_alarms(self): - alarms = self.fac.read_alarms() + alarms = self.fac.read_alarms(self.alarm_number) for i, al in enumerate(alarms): self.alarms[i].set_values(al) -- cgit v1.2.3