Almost done, although there's a data send collision now
This commit is contained in:
parent
13139912aa
commit
fa6e5d8213
51
Client.py
51
Client.py
@ -1,44 +1,23 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
#import pyxinput
|
import pyxinput
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import pickle
|
import pickle
|
||||||
# Define server ip and port
|
# Define server ip and port
|
||||||
ip = '192.168.122.1'
|
ip = '192.168.122.1'
|
||||||
port = 2222
|
port = 2222
|
||||||
#Define globals
|
# Create virtual controller
|
||||||
decodedServerData = ""
|
MyVirtual = pyxinput.vController()
|
||||||
def recvData(ip, port):
|
# Connect to Server
|
||||||
global decodedServerData
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
# Connect to Server
|
client.connect((ip, port))
|
||||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
while True:
|
||||||
#client.setblocking(False)
|
from_server = client.recv(8144)
|
||||||
client.connect((ip, port))
|
#Decode Sever message
|
||||||
while True:
|
decodedServerData = pickle.loads(from_server)
|
||||||
from_server = client.recv(4096)
|
print("Raw Data:", str(decodedServerData))
|
||||||
#Decode Sever message
|
# pyxinput will only accept values one at a time, so we need to apply the itme in the dictionary one by one
|
||||||
decodedServerData = pickle.loads(from_server)
|
for event, state in decodedServerData.items():
|
||||||
print("Raw Data:", decodedServerData)
|
MyVirtual.set_value(event, state)
|
||||||
MyVirtual.set_value(decodedServerData)
|
print('\''+event+'\''+',', state)
|
||||||
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
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
# pyInputStreaming
|
# pyInputStreaming
|
||||||
Python Scripts to stream controller input from a Linux Host to a Windows 10 virtual machine
|
Python Scripts to stream controller input from a Linux Host to a Windows 10 virtual machine
|
||||||
|
# Dependancies
|
||||||
lol
|
On the server, the following libraries are required:
|
||||||
|
colored
|
||||||
|
inputs
|
||||||
|
On the Client:
|
||||||
|
PYXInput
|
||||||
|
106
Server.py
106
Server.py
@ -14,53 +14,61 @@ print("Gamepads available:")
|
|||||||
print(devices.gamepads)
|
print(devices.gamepads)
|
||||||
#Define globals
|
#Define globals
|
||||||
controllerData = ""
|
controllerData = ""
|
||||||
# Show device output, send it in var
|
|
||||||
#def printInput():
|
|
||||||
#global 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)
|
|
||||||
#s.setblocking(False)
|
|
||||||
conn, addr = s.accept()
|
|
||||||
with conn:
|
|
||||||
print(colored('Connected by', 'red'), addr)
|
|
||||||
'''
|
|
||||||
#Dictionary of of all possible values
|
#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}
|
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
|
#Lookup table to convert values from the "inputs" library
|
||||||
print(controllerDataDict)
|
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'}
|
||||||
#Print value of AxisRx
|
print("Waiting for connection...")
|
||||||
#print(controllerDataDict['AxisRx'])
|
def sendData():
|
||||||
while True:
|
#Pickle for transmittion
|
||||||
events = get_gamepad()
|
encodedControllerData = pickle.dumps(controllerDataDict)
|
||||||
for event in events:
|
#print(encodedControllerData)
|
||||||
#controllerDataTuple = event.ev_type, event.code, event.state
|
conn.send(encodedControllerData)
|
||||||
controllerDataTuple = event.code, event.state
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
controllerData = controllerDataTuple
|
s.bind((ip, port))
|
||||||
#print("controllerData is a", type(controllerData))
|
s.listen(1)
|
||||||
print(controllerData)
|
#s.setblocking(False)
|
||||||
|
conn, addr = s.accept()
|
||||||
'''
|
with conn:
|
||||||
#Pickle for transmittion
|
print(colored('Connected by', 'red'), addr)
|
||||||
encodedControllerData = pickle.dumps(controllerDataDict)
|
print(controllerDataDict)
|
||||||
print(encodedControllerData)
|
while True:
|
||||||
conn.send(encodedControllerData)
|
events = get_gamepad()
|
||||||
#Wait for ok signal from client before continuing...
|
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)
|
||||||
|
print(controllerDataDict)
|
||||||
# Execute all functions as threads
|
#If event.code is SYN_REPORT, ignore it
|
||||||
#if __name__ == "__main__":
|
if event.code == "SYN_REPORT":
|
||||||
#Create Threads
|
continue
|
||||||
#t1 = threading.Thread(target=printInput, args=())
|
if event.code == "BTN_MODE":
|
||||||
#t2 = threading.Thread(target=inputCapture, args=(ip, port))
|
print(colored('The home button is unimplemented on PYXinput, ignoring', 'red'))
|
||||||
#t1.start()
|
continue
|
||||||
#t2.start()
|
#Ugh, PYXinput and inputs handle the Dpad in the most annoying way possible
|
||||||
|
elif event.code == "ABS_HAT0X":
|
||||||
|
#if ABS_HAT0X is 0, then there is no input on the dpad
|
||||||
|
if event.state == 0:
|
||||||
|
controllerDataDict['Dpad'] = 0 #No input
|
||||||
|
if event.state == 1:
|
||||||
|
controllerDataDict['Dpad'] = 8 #Right
|
||||||
|
if event.state == -1:
|
||||||
|
controllerDataDict['Dpad'] = 4 #Left
|
||||||
|
sendData()
|
||||||
|
elif event.code == "ABS_HAT0Y":
|
||||||
|
#if ABS_HAT0Y is 0, then there is no input on the dpad
|
||||||
|
if event.state == 0:
|
||||||
|
controllerDataDict['Dpad'] = 0 #No input
|
||||||
|
if event.state == 1:
|
||||||
|
controllerDataDict['Dpad'] = 2 #Down
|
||||||
|
if event.state == -1:
|
||||||
|
controllerDataDict['Dpad'] = 1 #Up
|
||||||
|
sendData()
|
||||||
|
else:
|
||||||
|
# Add values to controllerDataDict
|
||||||
|
controllerDataDict[lookup_table[str(event.code)]] = event.state
|
||||||
|
sendData()
|
||||||
|
#Execute everything
|
||||||
|
controllerLoop()
|
||||||
|
Loading…
Reference in New Issue
Block a user