def start(key_manager): """ Start the acc client with the key manager. :param key_manager: Key manager for configure acc. """ try: # create http server with HttpServer server = HTTPServer((hostName, hostPort), HttpServer) # set http server key_manager. server.key_manager = key_manager # set ACC-Client buttons thread. buttons = {'D5', 'D6'} # create the global bridge to arduino bridge = BridgeGlobal() # set http server global bridge server.bridge = bridge # initialize buttons array threads = [] # create a thread for each button for button in buttons: # create pin thread, with the KeyManager, the pin of the button and the global bridge. thread = PinThread(key_manager=key_manager, pin=button, bridge=bridge) # start the pin thread thread.start() # append the pin thread to the threads list. threads.append(thread) # print the start of the server. print(time.asctime(), "Server Starts - %s:%s" % (hostName, hostPort)) # start the http server server.serve_forever() except KeyboardInterrupt: # on key board interrupt # stop http server server.server_close() # stop all threads for thread in threads: thread.interrupt() pass
def start(decibel, address): """ Start the acc client with the key manager. :param key_manager: Key manager for configure acc. """ server = None try: # create http server with HttpServer # create the global bridge to arduino bridge = BridgeGlobal() threads = [] mic_thread = MicThread(bridge, decibel, address) mic_thread.start() threads.append(mic_thread) remote_thread = RemoteThread(bridge, address) remote_thread.start() threads.append(remote_thread) print(time.asctime(), "Server Starts - %s:%s" % (hostName, hostPort)) # start the http server server = HTTPServer((hostName, hostPort), HttpServer) server.bridge = bridge server.mic_thread = mic_thread server.serve_forever() except KeyboardInterrupt: # on key board interrupt # stop http server if server is not None: server.server_close() # stop all threads for thread in threads: thread.interrupt() pass