From 25de7af957d0f0c16bd039a987123e9e42397a8a Mon Sep 17 00:00:00 2001 From: Holden Date: Wed, 23 Mar 2022 13:51:55 -0400 Subject: [PATCH] Fix Joystick Button Count --- src/Joystick/JoystickSDL.cc | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/Joystick/JoystickSDL.cc b/src/Joystick/JoystickSDL.cc index 4f1876d..4743e38 100644 --- a/src/Joystick/JoystickSDL.cc +++ b/src/Joystick/JoystickSDL.cc @@ -14,7 +14,7 @@ JoystickSDL::JoystickSDL(const QString& name, int axisCount, int buttonCount, in } bool JoystickSDL::init(void) { - if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0) { + if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK) < 0) { SDL_JoystickEventState(SDL_ENABLE); qWarning() << "Couldn't initialize SimpleDirectMediaLayer:" << SDL_GetError(); return false; @@ -37,29 +37,20 @@ QMap JoystickSDL::discover(MultiVehicleManager* _multiVehicl if (!ret.contains(name)) { int axisCount, buttonCount, hatCount; - bool isGameController; - - - if (SDL_IsGameController(i)) { - isGameController = true; - axisCount = SDL_CONTROLLER_AXIS_MAX; - buttonCount = SDL_CONTROLLER_BUTTON_MAX; - hatCount = 0; - } else { - isGameController = false; - if (SDL_Joystick* sdlJoystick = SDL_JoystickOpen(i)) { - SDL_ClearError(); - axisCount = SDL_JoystickNumAxes(sdlJoystick); - buttonCount = SDL_JoystickNumButtons(sdlJoystick); - hatCount = SDL_JoystickNumHats(sdlJoystick); - if (axisCount < 0 || buttonCount < 0 || hatCount < 0) { - qCWarning(JoystickLog) << "\t libsdl error parsing joystick features:" << SDL_GetError(); - } - SDL_JoystickClose(sdlJoystick); - } else { - qCWarning(JoystickLog) << "\t libsdl failed opening joystick" << qPrintable(name) << "error:" << SDL_GetError(); - continue; + bool isGameController = SDL_IsGameController(i); + + if (SDL_Joystick* sdlJoystick = SDL_JoystickOpen(i)) { + SDL_ClearError(); + axisCount = SDL_JoystickNumAxes(sdlJoystick); + buttonCount = SDL_JoystickNumButtons(sdlJoystick); + hatCount = SDL_JoystickNumHats(sdlJoystick); + if (axisCount < 0 || buttonCount < 0 || hatCount < 0) { + qCWarning(JoystickLog) << "\t libsdl error parsing joystick features:" << SDL_GetError(); } + SDL_JoystickClose(sdlJoystick); + } else { + qCWarning(JoystickLog) << "\t libsdl failed opening joystick" << qPrintable(name) << "error:" << SDL_GetError(); + continue; } qCDebug(JoystickLog) << "\t" << name << "axes:" << axisCount << "buttons:" << buttonCount << "hats:" << hatCount << "isGC:" << isGameController;