alot of stuff
This commit is contained in:
parent
9afdf5a4d9
commit
13139912aa
29
Client.py
29
Client.py
@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
import re
|
#import pyxinput
|
||||||
import pyxinput
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
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
|
||||||
@ -18,28 +18,27 @@ def recvData(ip, port):
|
|||||||
while True:
|
while True:
|
||||||
from_server = client.recv(4096)
|
from_server = client.recv(4096)
|
||||||
#Decode Sever message
|
#Decode Sever message
|
||||||
decodedServerData = from_server.decode()
|
decodedServerData = pickle.loads(from_server)
|
||||||
print("Raw Data:", decodedServerData)
|
print("Raw Data:", decodedServerData)
|
||||||
|
MyVirtual.set_value(decodedServerData)
|
||||||
def virtualController():
|
def virtualController():
|
||||||
MyVirtual = pyxinput.vController()
|
MyVirtual = pyxinput.vController()
|
||||||
|
#Set percent to false so values match the raw data from the server
|
||||||
|
# MyVirtual.percent = False
|
||||||
MyRead = pyxinput.rController(1)
|
MyRead = pyxinput.rController(1)
|
||||||
print(MyRead.gamepad)
|
print(MyRead.gamepad)
|
||||||
|
'''
|
||||||
while True:
|
while True:
|
||||||
#global decodedServerData
|
#global decodedServerData
|
||||||
# Init virtual XInput Controller
|
# Init virtual XInput Controller
|
||||||
#print(MyRead.gamepad)
|
|
||||||
MyVirtual.set_value('BtnA', 1)
|
MyVirtual.set_value('AxisLy', 0)
|
||||||
print(MyRead.buttons)
|
|
||||||
sleep(3)
|
'''
|
||||||
#print(MyRead.gamepad)
|
|
||||||
MyVirtual.set_value('BtnA', 0)
|
|
||||||
print(MyRead.buttons)
|
|
||||||
sleep(3)
|
|
||||||
# Execute all functions as threads
|
# Execute all functions as threads
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
#Create Threads
|
#Create Threads
|
||||||
t1 = threading.Thread(target=recvData, args=(ip, port))
|
t1 = threading.Thread(target=recvData, args=(ip, port))
|
||||||
t2 = threading.Thread(target=virtualController, args=())
|
#t2 = threading.Thread(target=virtualController, args=())
|
||||||
#t1.start()
|
t1.start()
|
||||||
t2.start()
|
#t2.start()
|
||||||
|
37
Server.py
37
Server.py
@ -5,6 +5,7 @@ from inputs import get_gamepad
|
|||||||
import threading
|
import threading
|
||||||
import socket
|
import socket
|
||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
|
import pickle
|
||||||
# Define ip/port to use
|
# Define ip/port to use
|
||||||
ip = "192.168.122.1"
|
ip = "192.168.122.1"
|
||||||
port = 2222
|
port = 2222
|
||||||
@ -19,6 +20,8 @@ controllerData = ""
|
|||||||
# Capture device input and send it via a web socket
|
# Capture device input and send it via a web socket
|
||||||
#def inputCapture(ip, port):
|
#def inputCapture(ip, port):
|
||||||
#global controllerData
|
#global controllerData
|
||||||
|
print("Waiting for connection...")
|
||||||
|
'''
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
s.bind((ip, port))
|
s.bind((ip, port))
|
||||||
s.listen(1)
|
s.listen(1)
|
||||||
@ -26,17 +29,29 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|||||||
conn, addr = s.accept()
|
conn, addr = s.accept()
|
||||||
with conn:
|
with conn:
|
||||||
print(colored('Connected by', 'red'), addr)
|
print(colored('Connected by', 'red'), addr)
|
||||||
while True:
|
'''
|
||||||
events = get_gamepad()
|
#Dictionary of of all possible values
|
||||||
for event in events:
|
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}
|
||||||
controllerDataTuple = event.ev_type, event.code, event.state
|
# Convert "inputs" library data to our dict
|
||||||
controllerData = str(controllerDataTuple)
|
print(controllerDataDict)
|
||||||
print(controllerData)
|
#Print value of AxisRx
|
||||||
#Encode datastream for transmittion
|
#print(controllerDataDict['AxisRx'])
|
||||||
encodedControllerData=controllerData.encode()
|
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)
|
||||||
|
|
||||||
|
'''
|
||||||
|
#Pickle for transmittion
|
||||||
|
encodedControllerData = pickle.dumps(controllerDataDict)
|
||||||
|
print(encodedControllerData)
|
||||||
|
conn.send(encodedControllerData)
|
||||||
|
#Wait for ok signal from client before continuing...
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user