X-Git-Url: https://git.ralfj.de/saartuer.git/blobdiff_plain/8b136f42bf0c83f8aee52c315f7dbebc371cce1b..986e711c18a3960baa5dda8b9919372e6a387909:/pins.py?ds=inline diff --git a/pins.py b/pins.py index 8b699be..88a17c2 100644 --- a/pins.py +++ b/pins.py @@ -20,7 +20,7 @@ class PinWatcher(): 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 @@ -41,31 +41,32 @@ class PinWatcher(): class PinsWatcher(): def __init__(self, state_machine): - self.pins = { + self._pins = { 'bell_ringing': PinWatcher(18, 2), - 'door_closed': PinWatcher(8, 5), - 'door_locked': PinWatcher(9, 5), - 'space_active': PinWatcher(10, 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()