diff options
author | Elena ``of Valhalla'' Grandi <elena.valhalla@gmail.com> | 2012-01-22 18:14:50 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <elena.valhalla@gmail.com> | 2012-01-22 18:14:50 +0100 |
commit | 5d2de0923d3b33af2516766d51bea3e021407c11 (patch) | |
tree | eedefc5c90d86f397d049d91ed691357ccb66a50 /client | |
parent | 0cb5e21f17bf795d36f06ed1181b7eee6a279831 (diff) |
client: read current alarms
Diffstat (limited to 'client')
-rwxr-xr-x | client/ur_fuzzy_alarm_clock.py | 65 |
1 files changed, 16 insertions, 49 deletions
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) |