Mercurial > code > home > repos > homeauto
comparison service/garageArduino/garageArduino.py @ 44:55b68d1e8212
opening usb apparently causes an arduino restart now, so i have to wait for that to pass before beginning communications
Ignore-this: 9f34e8914c6bbe3fb54b2c8f5ed01804
author | drewp@bigasterisk.com |
---|---|
date | Sat, 29 Dec 2012 04:54:54 -0800 |
parents | 62b3bb861e35 |
children | 69b214997213 |
comparison
equal
deleted
inserted
replaced
43:6fbb05317eef | 44:55b68d1e8212 |
---|---|
33 DEV = Namespace("http://projects.bigasterisk.com/device/") | 33 DEV = Namespace("http://projects.bigasterisk.com/device/") |
34 | 34 |
35 class ArduinoGarage(object): | 35 class ArduinoGarage(object): |
36 def __init__(self, port='/dev/ttyACM0'): | 36 def __init__(self, port='/dev/ttyACM0'): |
37 self.ser = LoggingSerial(port=port, baudrate=115200, timeout=1) | 37 self.ser = LoggingSerial(port=port, baudrate=115200, timeout=1) |
38 time.sleep(2) # wait for a arduino reset to pass | |
38 self.ser.flush() | 39 self.ser.flush() |
40 self.ping() | |
39 | 41 |
40 def ping(self): | 42 def ping(self): |
41 self.ser.write("\x60\x00\x00") | 43 self.ser.write("\x60\x00\x00") |
42 msg = self.ser.readJson() | 44 msg = self.ser.readJson() |
43 assert msg == {"ok":True}, msg | 45 assert msg == {"ok":True}, msg |
221 try: | 223 try: |
222 try: | 224 try: |
223 newData = ard.poll() | 225 newData = ard.poll() |
224 except ValueError, e: | 226 except ValueError, e: |
225 print e | 227 print e |
228 os.abort() | |
226 else: | 229 else: |
227 self.lastPollTime = now | 230 self.lastPollTime = now |
228 self.lastValues = newData # for other data besides the blinks | 231 self.lastValues = newData # for other data besides the blinks |
229 self.processBlinks(now, newData['newBlinks']) | 232 self.processBlinks(now, newData['newBlinks']) |
230 self.processMotion(newData['motion']) | 233 self.processMotion(newData['motion']) |