def handleSpeed(speed): theSpeed = float(speed) GlobalSettings.setSpeed(speed) print("Speed: "+str(theSpeed))
def listen(): print("Listening...") global bb global p global client_socket server = socket.socket() server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server.bind(('',4329)) server.listen(4) client_socket, client_address = server.accept() while True: try: received_data = client_socket.recv(8192) if not received_data: print("Received empty packet from client") return except socket.error: print("Cannot receive data from client") return #print(received_data) jsonData = received_data try: dataDict = json.loads(jsonData) except ValueError: write('Malformed Data') else: left = 0 #Music right = 0 #Music if 'color' in dataDict: color = dataDict['color'] GlobalSettings.setColor(color) if 'speed' in dataDict: speed = dataDict['speed'] GlobalSettings.setSpeed(speed) if 'Music' in dataDict: left = dataDict['Music'][0] right = dataDict['Music'][1] if 'command' in dataDict: command = dataDict['command'] if command == 'Flash': startRoutine(flash_example.flash,name="Flash") elif command == 'Stop': write("Stopping...") print("Stopping...") stop() GlobalSettings.inProgress = False elif command == 'Clear': startRoutine(flash_example.clear,name="Clear") elif command == 'RoundAndRound': startRoutine(RoundAndRound.start,name="RoundAndRound") elif command == 'Snake': startRoutine(RoundAndRound.startSnake,name="Snake") elif command == 'OutsideIn': startRoutine(RoundAndRound.outsideIn,name="OutsideIn") elif command == 'Random': startRoutine(flash_example.random,name="Random") elif command == "Solid": startRoutine(flash_example.solid,name="Solid") elif command == "Rainbow": startRoutine(flash_example.rainbow,name="Rainbow") elif command == "DCStart": if GlobalSettings.dynaColor is False: startDC(); elif command == "DCStop": stopDC(); elif command == "Music": write("Stopping...") print("Stopping...") stop() write("Showing volume...") print("Showing volume; left: "+str(left)+", right: "+str(right)) Music.showVolume(left,right,bb) elif command == "Show": onLights = dataDict["onLights"] showPixels(onLights) elif command == "OutsideInRemix": startRoutine(OutsideInRemix.start,name="OutsideInRemix") else: write('Unrecognized Command\n')