From 13139912aa36342e3a82a5abe589bc716e6a8528 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Wed, 3 Jun 2020 01:07:28 -0500 Subject: [PATCH] alot of stuff --- Client.py | 29 ++++++++++++++--------------- Server.py | 37 ++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/Client.py b/Client.py index 861e4e5..d3c7846 100644 --- a/Client.py +++ b/Client.py @@ -1,9 +1,9 @@ #!/usr/bin/python import socket import threading -import re -import pyxinput +#import pyxinput from time import sleep +import pickle # Define server ip and port ip = '192.168.122.1' port = 2222 @@ -18,28 +18,27 @@ def recvData(ip, port): while True: from_server = client.recv(4096) #Decode Sever message - decodedServerData = from_server.decode() + decodedServerData = pickle.loads(from_server) print("Raw Data:", decodedServerData) + MyVirtual.set_value(decodedServerData) def virtualController(): MyVirtual = pyxinput.vController() + #Set percent to false so values match the raw data from the server + # MyVirtual.percent = False MyRead = pyxinput.rController(1) print(MyRead.gamepad) - +''' while True: #global decodedServerData # Init virtual XInput Controller - #print(MyRead.gamepad) - MyVirtual.set_value('BtnA', 1) - print(MyRead.buttons) - sleep(3) - #print(MyRead.gamepad) - MyVirtual.set_value('BtnA', 0) - print(MyRead.buttons) - sleep(3) + + MyVirtual.set_value('AxisLy', 0) + +''' # Execute all functions as threads if __name__ == "__main__": #Create Threads t1 = threading.Thread(target=recvData, args=(ip, port)) - t2 = threading.Thread(target=virtualController, args=()) -#t1.start() -t2.start() + #t2 = threading.Thread(target=virtualController, args=()) +t1.start() +#t2.start() diff --git a/Server.py b/Server.py index 65ac608..be0e115 100644 --- a/Server.py +++ b/Server.py @@ -5,6 +5,7 @@ from inputs import get_gamepad import threading import socket from termcolor import colored +import pickle # Define ip/port to use ip = "192.168.122.1" port = 2222 @@ -19,6 +20,8 @@ controllerData = "" # Capture device input and send it via a web socket #def inputCapture(ip, port): #global controllerData +print("Waiting for connection...") +''' with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((ip, port)) s.listen(1) @@ -26,17 +29,29 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: conn, addr = s.accept() with conn: print(colored('Connected by', 'red'), addr) - while True: - events = get_gamepad() - for event in events: - controllerDataTuple = event.ev_type, event.code, event.state - controllerData = str(controllerDataTuple) - print(controllerData) - #Encode datastream for transmittion - encodedControllerData=controllerData.encode() - conn.send(encodedControllerData) - #Wait for ok signal from client before continuing... - +''' +#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} +# Convert "inputs" library data to our dict +print(controllerDataDict) + #Print value of AxisRx + #print(controllerDataDict['AxisRx']) +while True: + events = get_gamepad() + for event in events: + #controllerDataTuple = event.ev_type, event.code, event.state + controllerDataTuple = event.code, event.state + controllerData = controllerDataTuple + #print("controllerData is a", type(controllerData)) + print(controllerData) + +''' + #Pickle for transmittion + encodedControllerData = pickle.dumps(controllerDataDict) + print(encodedControllerData) + conn.send(encodedControllerData) + #Wait for ok signal from client before continuing... +'''