-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_controller.py
More file actions
executable file
·103 lines (84 loc) · 3.25 KB
/
debug_controller.py
File metadata and controls
executable file
·103 lines (84 loc) · 3.25 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
#!/usr/bin/env python3
"""
Debug Controller Input - Test what axes and buttons work
"""
import pygame
import time
import sys
def main():
print("🎮 Debugging Controller Input...")
# Initialize pygame
pygame.init()
pygame.joystick.init()
# Check for controllers
joystick_count = pygame.joystick.get_count()
print(f"Found {joystick_count} controller(s)")
if joystick_count == 0:
print("❌ No controllers found!")
return 1
# Initialize controllers
controllers = []
for i in range(joystick_count):
joy = pygame.joystick.Joystick(i)
joy.init()
controllers.append(joy)
print(f"Controller {i}: {joy.get_name()}")
print(f" Axes: {joy.get_numaxes()}")
print(f" Buttons: {joy.get_numbuttons()}")
print(f" Hats: {joy.get_numhats()}")
print("\n🎮 Testing Controller Input...")
print("Move the left stick up/down and press buttons!")
print("Press ESC to exit")
# Create a simple display
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Controller Debug")
clock = pygame.time.Clock()
font = pygame.font.Font(None, 36)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
# Clear screen
screen.fill((0, 0, 0))
y_offset = 50
for i, joy in enumerate(controllers):
# Controller name
text = font.render(f"Controller {i}: {joy.get_name()}", True, (255, 255, 255))
screen.blit(text, (50, y_offset))
y_offset += 40
# Test axes
for axis in range(joy.get_numaxes()):
try:
value = joy.get_axis(axis)
color = (0, 255, 0) if abs(value) > 0.1 else (100, 100, 100)
text = font.render(f" Axis {axis}: {value:.3f}", True, color)
screen.blit(text, (70, y_offset))
y_offset += 30
except:
text = font.render(f" Axis {axis}: ERROR", True, (255, 0, 0))
screen.blit(text, (70, y_offset))
y_offset += 30
# Test buttons
for button in range(joy.get_numbuttons()):
try:
pressed = joy.get_button(button)
color = (0, 255, 0) if pressed else (100, 100, 100)
text = font.render(f" Button {button}: {'PRESSED' if pressed else 'not pressed'}", True, color)
screen.blit(text, (70, y_offset))
y_offset += 30
except:
text = font.render(f" Button {button}: ERROR", True, (255, 0, 0))
screen.blit(text, (70, y_offset))
y_offset += 30
y_offset += 20
pygame.display.flip()
clock.tick(60)
pygame.quit()
print("✅ Controller debug completed!")
return 0
if __name__ == "__main__":
sys.exit(main())