I’m attempting to use a joystick under LInux using libSDL. The
problem that I’m having is that all my axis readings for the stick
return 0, no matter what position the actual sticks are in (using an
xbox gamepad, which registers as an 8-axis joystick). The standard
linux jstest program works perfectly, and SDL reports that there is
one joystick with 8 axes as expected, but all calls to
SDL_JoystickGetAxis return 0. Can anybody tell me if there’s anything
painfully obviously wrong about the program below?
#include <stdio.h>
#include <SDL/SDL.h>
int main()
{
SDL_Init(SDL_INIT_JOYSTICK);
SDL_JoystickEventState(SDL_DISABLE);
int i, j;
int numsticks = SDL_NumJoysticks();
SDL_Joystick *sticks = malloc(numstickssizeof(SDL_Joystick));
int axes = malloc(numsticks*sizeof(int));
printf("%d Stick(s)\n", numsticks);
for(i = 0; i < numsticks; i++) {
sticks[i] = SDL_JoystickOpen(i);
if(!sticks[i]) {
printf(“No stick!\n”);
return 1;
}
axes[i] = SDL_JoystickNumAxes(sticks[i]);
}
for(; {
for(i = 0; i < numsticks; i++) {
for(j = 0; j < axes[i]; j++) {
printf(“Stick %d, axis %d, position is %d\n”, i, j,
SDL_JoystickGetAxis(sticks[i], j));
}
}
}
return 0;
}