|
|
@ -15,7 +15,7 @@ JoystickSDL::JoystickSDL(const QString& name, int axisCount, int buttonCount, in |
|
|
|
QMap<QString, Joystick*> JoystickSDL::discover(MultiVehicleManager* _multiVehicleManager) { |
|
|
|
QMap<QString, Joystick*> JoystickSDL::discover(MultiVehicleManager* _multiVehicleManager) { |
|
|
|
static QMap<QString, Joystick*> ret; |
|
|
|
static QMap<QString, Joystick*> ret; |
|
|
|
|
|
|
|
|
|
|
|
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_NOPARACHUTE) < 0) { |
|
|
|
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0) { |
|
|
|
qWarning() << "Couldn't initialize SimpleDirectMediaLayer:" << SDL_GetError(); |
|
|
|
qWarning() << "Couldn't initialize SimpleDirectMediaLayer:" << SDL_GetError(); |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
@ -33,7 +33,7 @@ QMap<QString, Joystick*> JoystickSDL::discover(MultiVehicleManager* _multiVehicl |
|
|
|
int axisCount, buttonCount, hatCount; |
|
|
|
int axisCount, buttonCount, hatCount; |
|
|
|
bool isGameController; |
|
|
|
bool isGameController; |
|
|
|
|
|
|
|
|
|
|
|
SDL_Joystick* sdlJoystick = SDL_JoystickOpen(i); |
|
|
|
|
|
|
|
if (SDL_IsGameController(i)) { |
|
|
|
if (SDL_IsGameController(i)) { |
|
|
|
isGameController = true; |
|
|
|
isGameController = true; |
|
|
|
axisCount = SDL_CONTROLLER_AXIS_MAX; |
|
|
|
axisCount = SDL_CONTROLLER_AXIS_MAX; |
|
|
@ -41,12 +41,20 @@ QMap<QString, Joystick*> JoystickSDL::discover(MultiVehicleManager* _multiVehicl |
|
|
|
hatCount = 0; |
|
|
|
hatCount = 0; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
isGameController = false; |
|
|
|
isGameController = false; |
|
|
|
|
|
|
|
if (SDL_Joystick* sdlJoystick = SDL_JoystickOpen(i)) { |
|
|
|
|
|
|
|
SDL_ClearError(); |
|
|
|
axisCount = SDL_JoystickNumAxes(sdlJoystick); |
|
|
|
axisCount = SDL_JoystickNumAxes(sdlJoystick); |
|
|
|
buttonCount = SDL_JoystickNumButtons(sdlJoystick); |
|
|
|
buttonCount = SDL_JoystickNumButtons(sdlJoystick); |
|
|
|
hatCount = SDL_JoystickNumHats(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); |
|
|
|
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; |
|
|
|
qCDebug(JoystickLog) << "\t" << name << "axes:" << axisCount << "buttons:" << buttonCount << "hats:" << hatCount << "isGC:" << isGameController; |
|
|
|
ret[name] = new JoystickSDL(name, qMax(0,axisCount), qMax(0,buttonCount), qMax(0,hatCount), i, isGameController, _multiVehicleManager); |
|
|
|
ret[name] = new JoystickSDL(name, qMax(0,axisCount), qMax(0,buttonCount), qMax(0,hatCount), i, isGameController, _multiVehicleManager); |
|
|
|