+# vim:ts=4
import re, pg
from CRC import do_crc
from select import select
elif code == '401':
self.events.append((DOOR, 1))
elif code == '610':
- self.events_append((SWITCH, None))
+ self.events.append((SWITCH, None))
self.interpret_switches(text)
elif code[0] == '2':
self.events.append((KEY, int(code[1:3])))
(code, string) = self.get_response()
return (code == '300', code, string)
- def next_event(self):
- if len(self.events) > 0:
- ret = self.events[0]
- del self.events[0]
- return ret
- return None
-
- def wait_for_events(self, timeout = None):
- if self.events: return True
- (r, _, _) = select([self.rfh], [], [], timeout)
- if not r: return False
- event_added = False
+ def next_event(self, timeout = None):
+ # we don't want to buffer in the serial port, so we get all the events
+ # we can ASAP.
+ if len(self.events) > 0: timeout = 0
while True:
- self.get_response(async = True)
- (r, _, _) = select([self.rfh], [], [], 0)
- if not r: return event_added
+ (r, _, _) = select([self.rfh], [], [], timeout)
+ if r:
+ self.get_response(async = True)
+ else:
+ break
+ if len(self.events) == 0: return None
+ ret = self.events[0]
+ del self.events[0]
+ return ret