def main(): gpio_classes = [ ] # Add any GPIO class we use, so we can clean up at the end try: buzzerController = Buzzer() ledController = LED() gpio_classes.append(buzzerController) gpio_classes.append(ledController) sensor = UltraSonic() socket = ServerSocket() socket.setLightsUpdated(ledController.setState) sensor.setHandDetectedCallback(lambda: (buzzerController.playSound( ) or True) and socket.sendFlameState(True)) sensor.setHandRemovedCallback(lambda: socket.sendFlameState(False)) sensor.start() while True: time.sleep(1) except KeyboardInterrupt: print("Program stopped...") for g in gpio_classes: g.cleanup()
def __init__ (self): ####start the server self.server_socket=ServerSocket() #create a dictionary to get a id self.request_handle_function = {} #Each key point to a function, so that it will be easier to call different function self.request_handle_function[REQUEST_LOGIN] = self.request_login_handle self.request_handle_function[REQUEST_CHAT] = self.request_chat_handle #save the data of client witch successfully login self.clients={} #database part self.db=DB()