diff options
author | Elena ``of Valhalla'' Grandi <elena.valhalla@gmail.com> | 2012-01-22 16:25:30 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <elena.valhalla@gmail.com> | 2012-01-22 16:25:30 +0100 |
commit | 0cb5e21f17bf795d36f06ed1181b7eee6a279831 (patch) | |
tree | c5a693e693c2bd62a55947bd26d27366572967d2 /client | |
parent | d2618b33cf3e44e79d9fa51b3b8274922e39dc07 (diff) |
client: actually send commands to the clock via serial
Diffstat (limited to 'client')
-rwxr-xr-x | client/ur_fuzzy_alarm_clock.py | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/client/ur_fuzzy_alarm_clock.py b/client/ur_fuzzy_alarm_clock.py index 24bbb94..752da46 100755 --- a/client/ur_fuzzy_alarm_clock.py +++ b/client/ur_fuzzy_alarm_clock.py @@ -1,14 +1,32 @@ #!/usr/bin/env python -import urwid +import datetime +import sys + +try: + import urwid +except ImportError: + sys.stderr.write('This program needs urwid\n') + sys.exit(1) + +try: + import serial +except ImportError: + sys.stderr.write('This program needs pySerial\n') + sys.exit(1) class FuzzyAlarmClock: def __init__(self,device): - self.device = device + try: + self.serial = serial.Serial(device,9600) + except serial.serialutil.SerialException: + sys.stderr.write('No such serial device '+device+'\n') + sys.exit(1) def set_time_to_now(self): - pass + now = 's'+datetime.datetime.now().strftime("%y%m%d%u%H%M%S") + self.serial.write(now) def read_alarms(self): return [ @@ -58,6 +76,15 @@ class FuzzyAlarmClock: ], ] + def set_alarm(self,alarm,values): + s = 'a'+str(alarm) + b0 = 0 + for i,bit in enumerate(values[:8][::-1]): + b0 += bit << i + s += "%02x"%(b0) + for val in values[8:]: + s += "%02x"%(val) + self.serial.write(s) class ModEdit(urwid.IntEdit): @@ -119,6 +146,22 @@ class Alarm: self.w_hour.set_edit_text(values[10]) self.w_minute.set_edit_text(values[11]) + def get_values(self): + return [ + self.w_repeat.get_state(), + self.w_mon.get_state(), + self.w_tue.get_state(), + self.w_wed.get_state(), + self.w_thu.get_state(), + self.w_fri.get_state(), + self.w_sat.get_state(), + self.w_sun.get_state(), + self.w_month.value(), + self.w_day.value(), + self.w_hour.value(), + self.w_minute.value(), + ] + class UI: @@ -184,7 +227,8 @@ class UI: self.alarms[i].set_values(al) def set_alarms(self): - pass + for i,alarm in enumerate(self.alarms): + self.fac.set_alarm(i,alarm.get_values()) def print_help(self): pass |