X-Git-Url: https://git.ralfj.de/saartuer.git/blobdiff_plain/dcf982c61b81917b9b01261bf832768c00cb4843..d72b6eb3b787ea31c165de06a996dfca93d10146:/pins.py diff --git a/pins.py b/pins.py index 30f9666..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(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()