forked from schmerdy/openxc-wheel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.py
More file actions
105 lines (92 loc) · 2.45 KB
/
Copy pathconfigure.py
File metadata and controls
105 lines (92 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pygame
import math
import os
WHEEL_NAME = "G27 Racing Wheel"
WHEEL_NAME = "Logitech G25 Racing Wheel USB"
def get_axis(num):
clock = pygame.time.Clock()
keep_going = True
while keep_going:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keep_going = False
if event.type == pygame.JOYAXISMOTION:
print(event.axis, event.value)
if (num > 0 and event.value >= num) or (num < 0 and event.value <= num):
return event.axis
clock.tick(10)
def get_button():
clock = pygame.time.Clock()
keep_going = True
button = None
while keep_going:
for event in pygame.event.get(pygame.JOYBUTTONDOWN):
print(event.button)
button = event.button
break
if button is not None:
break
clock.tick(10)
print("release button", button)
while keep_going:
for event in pygame.event.get(pygame.JOYBUTTONUP):
if button == event.button:
return button
clock.tick(10)
# make sure pygame doesn't try to open an output window
os.environ["SDL_VIDEODRIVER"] = "dummy"
try:
pygame.init()
except Exception as ex:
print(ex)
exit(-1)
wheel = None
for j in range(0,pygame.joystick.get_count()):
if pygame.joystick.Joystick(j).get_name() == WHEEL_NAME:
wheel = pygame.joystick.Joystick(j)
wheel.init()
print("Found", wheel.get_name())
if not wheel:
print("No " + WHEEL_NAME + " found")
exit(0)
#raise "No " + Wheel.config.WHEEL_NAME + " found"
print("steer all the way to the left")
print(get_axis(-1))
print("steer all the way to the right")
print(get_axis(1))
print("press gas pedal")
print(get_axis(-1))
print("release gas pedal")
print(get_axis(1))
print("press brake pedal")
print(get_axis(-1))
print("release brake pedal")
print(get_axis(1))
print("press clutch pedal")
print(get_axis(-1))
print("release clutch pedal")
print(get_axis(1))
print("shift to first gear")
print(get_button())
print("shift to second gear")
print(get_button())
print("shift to third gear")
print(get_button())
print("shift to fourth gear")
print(get_button())
print("shift to fifth gear")
print(get_button())
print("shift to sixth gear")
print(get_button())
print("shift to reverse gear")
print(get_button())
print("press ignition button")
print(get_button())
print("press handbrake button")
print(get_button())
print("press headlamp button")
print(get_button())
print("press high beam button")
print(get_button())
print("press windshield wiper button")
print(get_button())