Merge branch 'master' of ralfj.de:saartuer
[saartuer.git] / pins.py
diff --git a/pins.py b/pins.py
index 8b699be529ef3db077af6f51da04856c8a0932c8..88a17c294428b04a4ce528a00df31bda21391833 100644 (file)
--- 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()