added auto detection of system to set serial port and added ability to change serial port
This commit is contained in:
parent
cb8c861407
commit
61160fcd70
7 changed files with 19 additions and 6 deletions
Binary file not shown.
BIN
GAME_METHODS/__pycache__/BEAMNG_METHODS.cpython-312.pyc
Normal file
BIN
GAME_METHODS/__pycache__/BEAMNG_METHODS.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
GAME_METHODS/__pycache__/FORZA_METHODS.cpython-312.pyc
Normal file
BIN
GAME_METHODS/__pycache__/FORZA_METHODS.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
GAME_METHODS/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
GAME_METHODS/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
|
|
@ -1,16 +1,18 @@
|
|||
#please use python 3.11
|
||||
import socket
|
||||
import struct
|
||||
import serial
|
||||
import time
|
||||
import csv
|
||||
import platform
|
||||
from enum import Enum
|
||||
from GAME_METHODS import *
|
||||
|
||||
runningOs = platform.system()
|
||||
|
||||
COM_PORT = 'COM5'
|
||||
UDP_IP = "127.0.0.1"
|
||||
BEAMNG_UDP_PORT = 4444
|
||||
FORZA_UDP_PORT= 4843
|
||||
SERIAL_PORT = ""
|
||||
|
||||
class GameType(Enum):
|
||||
NONE=0,
|
||||
|
|
@ -26,9 +28,19 @@ carData = 0
|
|||
|
||||
#code runs from here<-----------------------------------------------------------------------------------------------------------
|
||||
|
||||
if runningOs == 'Windows':
|
||||
print("Windows detacted setting serial port to 'COM5'\n")
|
||||
SERIAL_PORT= 'COM5'
|
||||
elif runningOs == 'Linux':
|
||||
print("Linux detected setting serial port to '/dev/ttyAMC0'\n")
|
||||
SERIAL_PORT = '/dev/ttyACM0'
|
||||
else:
|
||||
print("OS detection failed setting serial port to 'COM5'\n")
|
||||
SERIAL_PORT = 'COM5'
|
||||
|
||||
#select game
|
||||
while gameSelected == False:
|
||||
gameNo = input("1:BEAMNG\n2:FORZA\n")
|
||||
gameNo = input("1:BEAMNG\n2:FORZA\n\n\n9:SET SERIAL PORT ("+SERIAL_PORT+")\n")
|
||||
if gameNo == "1":
|
||||
portToConnect = BEAMNG_UDP_PORT
|
||||
gameSelected = True
|
||||
|
|
@ -39,7 +51,8 @@ while gameSelected == False:
|
|||
gameType=GameType.FORZA
|
||||
gameSelected=True
|
||||
print("Forza Selected")
|
||||
|
||||
elif gameNo == "9":
|
||||
SERIAL_PORT = input("set serial port: ")
|
||||
else:
|
||||
print("please select a number from the list")
|
||||
|
||||
|
|
@ -55,10 +68,10 @@ while connectedWebSocket == False:
|
|||
|
||||
while connectedArduino == False:
|
||||
try:
|
||||
toPi=serial.Serial(COM_PORT,115200) #connect to arduino
|
||||
toPi=serial.Serial(SERIAL_PORT,115200) #connect to arduino
|
||||
connectedArduino = True
|
||||
except:
|
||||
print("please check connection to arduino and verify the correct COM port")
|
||||
print("please check connection to arduino and verify the correct serial port")
|
||||
time.sleep(1)
|
||||
|
||||
csvOut = False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue