#!/usr/bin/env python3 """ Outil de diagnostic pour analyser les entrées d'un joystick. Affiche en temps réel les axes, boutons et chapeau détectés. """ import os import platform import sys import pygame import time print("=== Infos système ===") print(f" Python : {sys.version}") print(f" OS : {platform.system()} {platform.release()}") # Même comportement que main.py : désactive HIDAPI pour éviter la renumérotation des boutons os.environ.setdefault("SDL_JOYSTICK_HIDAPI", "0") print(f" SDL_JOYSTICK_HIDAPI : {os.environ.get('SDL_JOYSTICK_HIDAPI', '(non défini)')}") def main(): pygame.init() pygame.joystick.init() sdl_ver = pygame.get_sdl_version() print(f" pygame : {pygame.__version__}") print(f" SDL : {sdl_ver[0]}.{sdl_ver[1]}.{sdl_ver[2]}") print() # Petite fenêtre pour capturer les événements screen = pygame.display.set_mode((400, 300)) pygame.display.set_caption("Joystick Debug") clock = pygame.time.Clock() joysticks = [] for idx in range(pygame.joystick.get_count()): joy = pygame.joystick.Joystick(idx) joy.init() joysticks.append(joy) print(f"\n=== Joystick {idx}: {joy.get_name()} ===") try: print(f" GUID : {joy.get_guid()}") except AttributeError: pass print(f" Boutons: {joy.get_numbuttons()}") print(f" Axes : {joy.get_numaxes()}") print(f" Chapeaux: {joy.get_numhats()}") print(f" Trackballs: {joy.get_numballs()}") if not joysticks: print("❌ Aucun joystick détecté!") pygame.quit() return print("\n📋 Monitoring en direct (appuyez sur ESC ou fermez la fenêtre pour quitter)...\n") axis_values = {} button_states = {} hat_states = {} running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: running = False elif event.type == pygame.JOYBUTTONDOWN: print(f"🔴 [J{event.joy}] BOUTON DOWN: {event.button}") elif event.type == pygame.JOYBUTTONUP: print(f"⚪ [J{event.joy}] BOUTON UP: {event.button}") elif event.type == pygame.JOYAXISMOTION: # Afficher seulement si le mouvement est significatif if abs(event.value) > 0.1: print(f"↔️ [J{event.joy}] AXE {event.axis}: {event.value:.3f}") elif event.type == pygame.JOYHATMOTION: print(f"🧭 [J{event.joy}] CHAPEAU: {event.value}") # État en direct des axes for idx, joy in enumerate(joysticks): print("\r", end="") status = f"[J{idx}] " for axis_idx in range(min(4, joy.get_numaxes())): # Afficher les 4 premiers axes val = joy.get_axis(axis_idx) status += f"AX{axis_idx}:{val:6.3f} " # État du chapeau try: hat_x, hat_y = joy.get_hat(0) status += f"| CHAPEAU:({hat_x},{hat_y})" except: pass print(status, end="", flush=True) clock.tick(30) # 30 FPS pygame.quit() print("\n✅ Terminé.") if __name__ == "__main__": main()