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
|
||||
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()
|
||||
|
27
Server.py
27
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:
|
||||
'''
|
||||
#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
|
||||
controllerData = str(controllerDataTuple)
|
||||
#controllerDataTuple = event.ev_type, event.code, event.state
|
||||
controllerDataTuple = event.code, event.state
|
||||
controllerData = controllerDataTuple
|
||||
#print("controllerData is a", type(controllerData))
|
||||
print(controllerData)
|
||||
#Encode datastream for transmittion
|
||||
encodedControllerData=controllerData.encode()
|
||||
|
||||
'''
|
||||
#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