diff options
-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 |