I’ve got a HOTAS warthog Thrustmaster A-10 joystick which I would like to access from SDL2. But when I detect with SDL_NumJoysticks the joystick is always counted twice can be opened twice. How do I handle having two joysticks? Or even isn’t that a bug in SDL’s joystick detection?
I use this little snip to detect:
#include \<iostream\>
#include \<SDL2/SDL.h\>
#include \<vector\>
int main() {
SDL_Init(SDL_INIT_EVERYTHING);
const auto noOfJoysticks = SDL_NumJoysticks();
std::cout << "No of joysticks: " << noOfJoysticks << "\n";
SDL_version ver;
SDL_GetVersion(&ver);
std::cout << (int) ver.major << "." << (int) ver.minor << "." << (int) ver.patch << "\n";
std::vector<SDL_Joystick *> js;
js.reserve(noOfJoysticks);
for (int i = 0; i < noOfJoysticks; ++i) {
if (SDL_IsGameController(i))
std::cout << "No. " << i << " is game controller\n";
js[i] = SDL_JoystickOpen(i);
if (js[i]) {
printf("Opened Joystick %d\n", i);
printf("Name: %s\n", SDL_JoystickNameForIndex(i));
printf("Number of Axes: %d\n", SDL_JoystickNumAxes(js[i]));
printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(js[i]));
printf("Number of Hats: %d\n", SDL_JoystickNumHats(js[i]));
printf("Number of Balls: %d\n", SDL_JoystickNumBalls(js[i]));
} else {
printf("Couldn't open Joystick %d\n", i);
}
}
return 0;
}
and get this:
No of joysticks: 2
2.24.0
Opened Joystick 0
Name: Thustmaster Joystick - HOTAS Warthog
Number of Axes: 2
Number of Buttons: 19
Number of Hats: 1
Number of Balls: 0
Opened Joystick 1
Name: Thustmaster Joystick - HOTAS Warthog
Number of Axes: 2
Number of Buttons: 19
Number of Hats: 1
Number of Balls: 0
As you can see I run SDL2 version 2.24.0 and I’m on a Mageia (Cauldron) linux box.