diff --git a/Server.py b/Server.py old mode 100644 new mode 100755 index a38f48b..da64384 --- a/Server.py +++ b/Server.py @@ -20,7 +20,7 @@ controllerData = "" #Dictionary of of all possible values controllerDataDict = {'AxisLx': 0, 'AxisLy': 0, 'AxisRx': 0, 'AxisRy': 0, 'BtnBack': 0, 'BtnStart': 0, 'BtnA': 0, 'BtnB': 0, 'BtnX': 0, 'BtnY': 0, 'BtnThumbL': 0, 'BtnThumbR': 0, 'BtnShoulderL': 0, 'BtnShoulderR': 0, 'Dpad': 0, 'TriggerL': 0, 'TriggerR': 0} #Lookup table to convert values from the "inputs" library -lookup_table = {'BTN_SELECT': 'BtnBack', 'BTN_START': 'BtnStart', 'BTN_SOUTH': 'BtnA', 'BTN_EAST': 'BtnB', 'BTN_NORTH': 'BtnX', 'BTN_WEST': 'BtnY', 'BTN_THUMBL': 'BtnThumbL', 'BTN_THUMBR': 'BtnThumbR', 'BTN_TL': 'BtnShoulderL', 'BTN_TR': 'BtnShoulderR'} +lookup_table = {'BTN_SELECT': 'BtnBack', 'BTN_START': 'BtnStart', 'BTN_SOUTH': 'BtnA', 'BTN_EAST': 'BtnB', 'BTN_NORTH': 'BtnX', 'BTN_WEST': 'BtnY', 'BTN_THUMBL': 'BtnThumbL', 'BTN_THUMBR': 'BtnThumbR', 'BTN_TL': 'BtnShoulderL', 'BTN_TR': 'BtnShoulderR', 'BTN_TL2': 'TriggerL', 'BTN_TR2': 'TriggerR'} def sendData(): #Pickle for transmittion pickle.dump(controllerDataDict, file) @@ -41,6 +41,8 @@ iwantThatRaddr = re.findall(r"'(?<=raddr=\(')\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' print(iwantThatRaddr) print(colored('Connected by', 'red'), iwantThatRaddr[0]) print(controllerDataDict) +min = 0 +max = 255 while True: events = get_gamepad() for event in events: @@ -78,25 +80,25 @@ while True: #'ABS_X': 'AxisLx', 'ABS_Y': 'AxisLy', 'ABS_RX': 'AxisRx', 'ABS_RY': 'AxisRy' #Left Joystick elif event.code == 'ABS_X': # Left Joystick, left+right - controllerDataDict['AxisLx'] = 2/(32767 - -32768)*(event.state-32767)+1 + controllerDataDict['AxisLx'] = (event.state - 127.5) / 127.5 sendData() elif event.code == 'ABS_Y': # Left Joystick, up+down - controllerDataDict['AxisLy'] = - 2/(32767 - -32768)*(event.state-32767)+1-2 + controllerDataDict['AxisLy'] = - (event.state - 127.5) / 127.5 sendData() #Right Joystick elif event.code == 'ABS_RX': # Left Joystick, left+right - controllerDataDict['AxisRx'] = 2/(32767 - -32768)*(event.state-32767)+1 + controllerDataDict['AxisRx'] = (event.state - 127.5) / 127.5 sendData() elif event.code == 'ABS_RY': # Left Joystick, up+down - controllerDataDict['AxisRy'] = - 2/(32767 - -32768)*(event.state-32767)+1-2 + controllerDataDict['AxisRy'] = - (event.state - 127.5) / 127.5 sendData() #Now, for the triggers #'ABS_Z': 'TriggerL', 'ABS_RZ': 'TriggerR' elif event.code == 'ABS_Z': - controllerDataDict['TriggerL'] = float(event.state) / 1023 + controllerDataDict['TriggerL'] = (event.state - 127.5) / 127.5 sendData() elif event.code == 'ABS_RZ': - controllerDataDict['TriggerR'] = float(event.state) / 1023 + controllerDataDict['TriggerR'] = (event.state - 127.5) / 127.5 sendData() else: # Add button values to controllerDataDict