@@ -50,6 +50,37 @@ def start(self):
5050 self .cleanup ()
5151
5252
53+ class MultiplePinWatcher (GPIOConfig , GPIOActions ):
54+ """This class is used with multiple pins. Calling the 'start' method will
55+ block, waiting for changes in state for the defined pins. When that happens
56+ a method on the `event_handler` class, matching the 'handler' name from the
57+ pin config is called. Each of these 'handler' methods takes a single argument,
58+ the pin number, which is passed in automatically by the RPi.GPIO library.
59+
60+ The 'event_handler' class should have one parameter in its constructor. An
61+ instance of GPIO will be passed in so you have access to it in each custom
62+ 'handler' method."""
63+
64+ def __init__ (self , config , event_handler ):
65+ super (MultiplePinWatcher , self ).__init__ (config = config , event_handler = event_handler )
66+ self ._initialize_gpio ()
67+ self ._initialize_pins ()
68+
69+ def _initialize_pins (self ):
70+ for pin_num , pin_options in self ._pin_config .items ():
71+ self ._setup_pin (pin_num , pin_options )
72+
73+ def start (self ):
74+ try :
75+ # keep this running for the threaded callbacks
76+ while True :
77+ sleep (0.250 )
78+ except KeyboardInterrupt :
79+ pass
80+ finally :
81+ self .cleanup ()
82+
83+
5384class PinManager (object ):
5485
5586 def __init__ (self , config_file = None , config_dict = None , event_handlers = None ):
0 commit comments