def read(self):
curstate = GPIO.input(self.pin)
assert curstate in (0, 1)
- if curstate != self._state:
+ if curstate != self.state:
# the state is about to change
if curstate == self._newstate:
# we already saw this new state
class PinsWatcher():
def __init__(self, state_machine):
- self.pins = {
+ self._pins = {
'bell_ringing': PinWatcher(18, 2),
- 'door_closed': PinWatcher(8, 5),
- 'door_locked': PinWatcher(10, 5),
- 'space_active': PinWatcher(24, 5),
+ 'door_closed': PinWatcher(8, 4),
+ 'door_locked': PinWatcher(10, 4),
+ 'space_active': PinWatcher(24, 4),
}
self._sm = state_machine
# start a thread doing the work
- self._t = ThreadRepeater(self._read, 0.02)
-
- def _read():
+ self._t = ThreadRepeater(self._read, 0.02, name="PinsWatcher")
+
+ def _read(self):
saw_change = False
- for name in self.pins.keys():
- pin = pins[name]
+ for name in self._pins.keys():
+ pin = self._pins[name]
if pin.read():
saw_change = True
- logger.debug("Pin %s changed to %d" % (name, pin.state)
- if not saw_change: return
+ logger.debug("Pin %s changed to %d" % (name, pin.state))
+ if not saw_change:
+ return None
# create return object
pinsState = PinsState()
- for name in self.pins.keys():
- setattr(pinsState, name, self.pins[name].state)
+ for name in self._pins.keys():
+ setattr(pinsState, name, self._pins[name].state)
# send it to state machine
self._sm.callback(StateMachine.CMD_PINS, pinsState)
- def stop():
+ def stop(self):
self._t.stop()