SDL Joystick!

Hi all!

We are currently working on implementing joystick input with sdl 1.2.8 on
windows XP and VS 2003!

We are using a “xbox controller” via “super joy box 10” adaptor!

it all goes well exept for several things…

Strange factor… SDL_JoystickGetAxis
we get control over the left trigger using SDL_JoystickGetAxis(m_joystick, 4);
but the right trigger is not responding with SDL_JoystickGetAxis(m_joystick,
5); makes sense since im reporting only 5 axis available.
How do we get controller over the right trigger?

so far, we get feedbacks from all buttons, left and right axis… no problem
there but…

How do we get control over the DPAD (cross) up, down, left, right etc…

we figured it must be the SDL_JoystickGetHat
what is this for exacly?

we ve tried:

if (SDL_JoystickGetHat(m_joystick, SDL_HAT_UP))
Trace(“SDL: Joystick Hat UP pressed.\n”);

and

case SDL_JOYHATMOTION:
if (m_event.jhat.hat & SDL_HAT_UP)
Trace(“SDL: Joystick Hat UP pressed.\n”);

without success…

what did we missed here? anyone can help clear this up?

thx a million!

Golgoth <neosettlers sympatico.ca> writes:

this works:

case SDL_JOYHATMOTION:
if (m_event.jhat.value & SDL_HAT_UP)

will be nice to not use sdl events… how to?

[…]

if (SDL_JoystickGetHat(m_joystick, SDL_HAT_UP))
Trace(“SDL: Joystick Hat UP pressed.\n”);
[…]

According to the documentation, SDL_JoystickGetHat() returns a Uint8
hat state. The last argument is an integer telling it which hat to
read. (There can be several hats on one joystick. Mine has 4 IIRC;
two on the actual stick and two on the throttle handle…)

So, the code should read something like:

if (SDL_JoystickGetHat(m_joystick, hat) & SDL_HAT_UP)
	Trace("SDL: Joystick Hat UP pressed.\n");

where “hat” is the index of the hat you want to read.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Thursday 01 December 2005 00.22, Golgoth wrote:

case SDL_JOYHATMOTION:
if (m_event.jhat.value & SDL_HAT_UP)

will be nice to not use sdl events… how to?

After you initialize everything:

SDL_JoystickEventState(SDL_QUERY); /* we will manually check */

Then when you want to check joystick state:

SDL_JoystickUpdate(); /* call this once per frame. /
value = SDL_JoystickGetAxis(myJoystick, 0); /
get axis 0’s state */

This way you don’t have to use the event loop for joysticks. Make sure
you call SDL_JoystickUpdate() once a frame, and then query for the
specific things you care about.

–ryan.

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.

Thx for the help guys!

Theres still problems remaining!

my left and right axis click are triggered by button 6 and 7…

index button 10 and 11 does not respond to any game pad buttons…

the left trigger work with:
SDL_JoystickGetAxis(m_joystick, 4);

and the right trigger is not doing any thing so far!

looks hocus pocus to me!

any ideas?

thx again!

Golgoth <neosettlers sympatico.ca> writes:

Thx for the help guys!

Theres still problems remaining!

my left and right axis click are triggered by button 6 and 7…

index button 10 and 11 does not respond to any game pad buttons…

the left trigger work with:
SDL_JoystickGetAxis(m_joystick, 4);

and the right trigger is not doing any thing so far!

looks hocus pocus to me!

any ideas?

thx again!

I’m having the exact same problem
only with a Joy Box 13 for GameCube controllers.
Did you find a solution?

/Jacob Kolding