Data is transfered, but client no longer updates...

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2020-06-03 20:19:43 -05:00
parent 5f666078ee
commit 613799f536
2 changed files with 53 additions and 47 deletions

View File

@ -12,9 +12,9 @@ MyVirtual = pyxinput.vController()
# Connect to Server # Connect to Server
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((ip, port)) client.connect((ip, port))
from_server = client.makefile(mode='rb') file = client.makefile(mode='rb')
#Decode Sever message #Decode Sever message
unpickler = pickle.Unpickler(from_server) unpickler = pickle.Unpickler(file)
while True: while True:
decodedServerData = unpickler.load() decodedServerData = unpickler.load()
print("Raw Data:", decodedServerData) print("Raw Data:", decodedServerData)

View File

@ -6,6 +6,7 @@ import threading
import socket import socket
from termcolor import colored from termcolor import colored
import pickle import pickle
import re
# Define ip/port to use # Define ip/port to use
ip = "192.168.122.1" ip = "192.168.122.1"
port = 2222 port = 2222
@ -20,54 +21,59 @@ controllerDataDict = {'AxisLx': 0, 'AxisLy': 0, 'AxisRx': 0, 'AxisRy': 0, 'BtnBa
lookup_table = {'ABS_X': 'AxisLx', 'ABS_Y': 'AxisLy', 'ABS_RX': 'AxisRx', 'ABS_RY': 'AxisRy', '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', 'ABS_Z': 'TriggerL', 'ABS_RZ': 'TriggerR'} lookup_table = {'ABS_X': 'AxisLx', 'ABS_Y': 'AxisLy', 'ABS_RX': 'AxisRx', 'ABS_RY': 'AxisRy', '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', 'ABS_Z': 'TriggerL', 'ABS_RZ': 'TriggerR'}
def sendData(): def sendData():
#Pickle for transmittion #Pickle for transmittion
file.flush()
pickler.dump(controllerDataDict) pickler.dump(controllerDataDict)
file.flush()
#Create Socket #Create Socket
socket = socket.create_server((ip, port)) socket = socket.create_server((ip, port))
#Create pickler :D
file = socket.makefile(mode='wb')
pickler = pickle.Pickler(file)
#Wait for connections before continuing #Wait for connections before continuing
print("Waiting for connection...") print("Waiting for connection...")
socket.accept() connection, _ = socket.accept()
#print(colored('Connected by', 'red'), addr) #Create pickler :D
file = connection.makefile(mode='wb')
pickler = pickle.Pickler(file)
file.flush()
print(connection)
print(type(connection))
#Immutiple socket? I don't think so...
iwantThatRaddr = re.findall(r"'(?<=raddr=\(')\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'", str(connection))
print(iwantThatRaddr)
print(colored('Connected by', 'red'), iwantThatRaddr[0])
print(controllerDataDict) print(controllerDataDict)
with socket: while True:
while True: events = get_gamepad()
events = get_gamepad() for event in events:
for event in events: #controllerDataTuple = event.ev_type, event.code, event.state
#controllerDataTuple = event.ev_type, event.code, event.state controllerDataTuple = event.code, event.state
controllerDataTuple = event.code, event.state controllerData = controllerDataTuple
controllerData = controllerDataTuple #print("controllerData is a", type(controllerData))
#print("controllerData is a", type(controllerData)) print(controllerData)
print(controllerData) print(controllerDataDict)
print(controllerDataDict) #If event.code is SYN_REPORT, ignore it
#If event.code is SYN_REPORT, ignore it if event.code == "SYN_REPORT":
if event.code == "SYN_REPORT": continue
continue if event.code == "BTN_MODE":
if event.code == "BTN_MODE": print(colored('The home button is unimplemented on PYXinput, ignoring', 'red'))
print(colored('The home button is unimplemented on PYXinput, ignoring', 'red')) continue
continue #Ugh, PYXinput and inputs handle the Dpad in the most annoying way possible
#Ugh, PYXinput and inputs handle the Dpad in the most annoying way possible elif event.code == "ABS_HAT0X":
elif event.code == "ABS_HAT0X": #if ABS_HAT0X is 0, then there is no input on the dpad
#if ABS_HAT0X is 0, then there is no input on the dpad if event.state == 0:
if event.state == 0: controllerDataDict['Dpad'] = 0 #No input
controllerDataDict['Dpad'] = 0 #No input if event.state == 1:
if event.state == 1: controllerDataDict['Dpad'] = 8 #Right
controllerDataDict['Dpad'] = 8 #Right if event.state == -1:
if event.state == -1: controllerDataDict['Dpad'] = 4 #Left
controllerDataDict['Dpad'] = 4 #Left sendData()
sendData() elif event.code == "ABS_HAT0Y":
elif event.code == "ABS_HAT0Y": #if ABS_HAT0Y is 0, then there is no input on the dpad
#if ABS_HAT0Y is 0, then there is no input on the dpad if event.state == 0:
if event.state == 0: controllerDataDict['Dpad'] = 0 #No input
controllerDataDict['Dpad'] = 0 #No input if event.state == 1:
if event.state == 1: controllerDataDict['Dpad'] = 2 #Down
controllerDataDict['Dpad'] = 2 #Down if event.state == -1:
if event.state == -1: controllerDataDict['Dpad'] = 1 #Up
controllerDataDict['Dpad'] = 1 #Up sendData()
sendData() else:
else: # Add values to controllerDataDict
# Add values to controllerDataDict controllerDataDict[lookup_table[str(event.code)]] = event.state
controllerDataDict[lookup_table[str(event.code)]] = event.state sendData()
sendData()