aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xclient/ur_fuzzy_alarm_clock.py65
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)