Hey, I might be able to help a little bit. I’m making an actual Xbox game, so
I’m dealing with similiar stuff to you. Don’t know if this’ll help much, but
here’s everything I can offer:
I’ve set up a struct for my controller, like so:
//gamepad struct
struct INPUT{
SDL_Joystick *GAMEPAD; //pointer for the gamepad
Sint16 abutton,bbutton,xbutton,ybutton,whitebutton,blackbutton; //signed ints
for buttons
Sint16 rtrigger,ltrigger,startbutton,backbutton; //signed ints for buttons
Sint16 rstick,lstick; //signed ints for joystick clicks
Sint16 joyx, joyy; //signed ints for left joystick axes
Sint16 rjoyx, rjoyy; //signed ints for right joystick axes
Sint16 dpad; //signed int for the dpad
const static int threshold = 3200; //controller deadzone
};
INPUT pad; //our controller
I’ve then made a function that updates the input:
//this updates the joypad states, so we can check for input
void get_input(void)
{
//update the joystick
SDL_JoystickUpdate(); //refreshes the gamepad state
//DPAD
pad.dpad = SDL_JoystickGetHat(pad.GAMEPAD, 0); //Get DPAD
//AXES
pad.joyx = SDL_JoystickGetAxis(pad.GAMEPAD, 0); //Get Left Joystick X-value
pad.joyy = SDL_JoystickGetAxis(pad.GAMEPAD, 1); //Get Left Joystick Y-value
pad.rjoyx = SDL_JoystickGetAxis(pad.GAMEPAD,2); //Get Right Joystick X-value
pad.rjoyy = SDL_JoystickGetAxis(pad.GAMEPAD,3); //Get Right Joystick Y-value
//BUTTONS
pad.abutton = SDL_JoystickGetButton(pad.GAMEPAD, 0); //Get A-Button (0)
pad.bbutton = SDL_JoystickGetButton(pad.GAMEPAD, 1); //Get B-Button (1)
pad.xbutton = SDL_JoystickGetButton(pad.GAMEPAD,2); //Get X-Button (2)
pad.ybutton = SDL_JoystickGetButton(pad.GAMEPAD,3); //Get Y-Button (3)
pad.blackbutton = SDL_JoystickGetButton(pad.GAMEPAD, 4);//Get Black Button (4)
pad.whitebutton = SDL_JoystickGetButton(pad.GAMEPAD, 5);//Get White Button (5)
pad.ltrigger = SDL_JoystickGetButton(pad.GAMEPAD,6); //Get Left Trigger (6)
pad.rtrigger = SDL_JoystickGetButton(pad.GAMEPAD,7); //Get Right Trigger (7)
pad.startbutton = SDL_JoystickGetButton(pad.GAMEPAD,8); //Get Start Button (8)
pad.backbutton = SDL_JoystickGetButton(pad.GAMEPAD, 9); //Get Back Button (9)
pad.lstick = SDL_JoystickGetButton(pad.GAMEPAD,10); //Get Left Stick Click (10)
pad.rstick = SDL_JoystickGetButton(pad.GAMEPAD,11); //Get Right Stick Click (11)
}
From here you can use a function to check the values on all those variables.
Also, some of this will be a little bit different because with SDLx the L and R
triggers are converted to buttons. Hopefully it’s enough to help you with
everything, though.