<s> from pi_gpio import socketio <EOL> from config . pins import PinManager <EOL> class PinEventManager ( PinManager ) : <EOL> def __init__ ( self ) : <EOL> super ( PinEventManager , self ) . __init__ ( ) <EOL> self . socketio = socketio <EOL> self . edge = { <EOL> '<STR_LIT>' : self . gpio . RISING , <EOL> '<STR_LIT>' : self . gpio . FALLING , <EOL> '<STR_LIT>' : self . gpio . BOTH <EOL> } <EOL> def build_event_callback ( self , num , name , event ) : <EOL> def event_callback ( num ) : <EOL> data = { <EOL> '<STR_LIT>' : num , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : event <EOL> } <EOL> self . socketio . emit ( '<STR_LIT>' , data ) <EOL> print ( data ) <EOL> return event_callback <EOL> def register_gpio_events ( self ) : <EOL> for num , config in self . pins . items ( ) : <EOL> event = config . get ( '<STR_LIT>' , None ) <EOL> name = config . get ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> if event : <EOL> edge = self . edge [ event ] <EOL> bounce = config [ '<STR_LIT>' ] <EOL> cb = self . build_event_callback ( num , name , event ) <EOL> self . gpio . add_event_detect ( num , edge , callback = cb , bouncetime = bounce ) </s>
