From 01c16b488dad65b039b0c8cc3038e713fdc234c0 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 20 Feb 2019 21:25:54 +0100 Subject: [PATCH] Log info about Joysticks --- src/main.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 34068e96..d6c7c1df 100644 --- a/src/main.c +++ b/src/main.c @@ -750,9 +750,6 @@ int Init_program(int argc,char * argv[]) #if defined(USE_SDL2) SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE); #endif -#if defined(USE_JOYSTICK) - Joystick = SDL_JoystickOpen(0); -#endif #endif #if defined(USE_SDL) SDL_EnableKeyRepeat(250, 32); @@ -772,6 +769,26 @@ int Init_program(int argc,char * argv[]) // a video mode may be requested as a command-line parameter file_in_command_line=Analyze_command_line(argc, argv, main_filename, main_directory, spare_filename, spare_directory); +#if defined(USE_JOYSTICK) && (defined(USE_SDL) || defined(USE_SDL2)) + GFX2_Log(GFX2_DEBUG, "%d joystick(s) attached\n", SDL_NumJoysticks()); + if (SDL_NumJoysticks() > 0) + { + Joystick = SDL_JoystickOpen(0); + if (Joystick == NULL) + { + GFX2_Log(GFX2_ERROR, "Failed to open joystick #0 : %s\n", SDL_GetError()); + } + else + { + GFX2_Log(GFX2_DEBUG, "Joystick #0 open : \"%s\" %d axes, %d buttons, %d balls, %d hats\n", + SDL_JoystickName(Joystick), SDL_JoystickNumAxes(Joystick), + SDL_JoystickNumButtons(Joystick), SDL_JoystickNumBalls(Joystick), + SDL_JoystickNumHats(Joystick)); + SDL_JoystickEventState(SDL_ENABLE); + } + } +#endif + Pixel_ratio=PIXEL_SIMPLE; // On initialise les données sur l'état du programme: // Donnée sur la sortie du programme: