GP2X Lets Talk About Joysticks


JonHolland

Still Fresh
Joined
Dec 17, 2006
Messages
26
Originally, I wrote some joystick code that took axis readings much like a conventional joystick, or a PC d-pad.

When it didn't work, I realized that the stick on the Gp2x was digital. Now that I'm back to the drawing board, I know how to make it work, however I'm wondering on the best way to avoid dead spots.

My goal is to make the stick feel like an analog stick to the user, as responsive as possible.

It seems to me like you need to check the stick switches states for the 8 possible directions, instead of relying on "Button Left + Button Up" being pressed together, is this correct?

I'd do some more testing, but I don't have a Gp2x, and I'm annoying my friend by sending him a new GPE every few minutes :)
 
Jonathan Holland posted on Dec 21 2006 at 03:21 AM said:
Originally, I wrote some joystick code that took axis readings much like a conventional joystick, or a PC d-pad.

When it didn't work, I realized that the stick on the Gp2x was digital. Now that I'm back to the drawing board, I know how to make it work, however I'm wondering on the best way to avoid dead spots.

My goal is to make the stick feel like an analog stick to the user, as responsive as possible.

It seems to me like you need to check the stick switches states for the 8 possible directions, instead of relying on "Button Left + Button Up" being pressed together, is this correct?

I'd do some more testing, but I don't have a Gp2x, and I'm annoying my friend by sending him a new GPE every few minutes :)

Just about everything you need to know is right here:

http://wiki.gp2x.org/wiki/SDL_Joystick_mapping
http://wiki.gp2x.org/wiki/Suggested_Joystick_Configurations
I just disable SDL joystick events when initializing them in code (see SDL lib docs) and manually poll each button in my main game loop using macros like this:

Code:
#define GP2X_BUTTON_UP			  (0)
#define GP2X_BUTTON_DOWN			(4)
#define GP2X_BUTTON_LEFT			(2)
#define GP2X_BUTTON_RIGHT		   (6)
#define GP2X_BUTTON_UPLEFT		  (1)
#define GP2X_BUTTON_UPRIGHT		 (7)
#define GP2X_BUTTON_DOWNLEFT		(3)
#define GP2X_BUTTON_DOWNRIGHT	   (5)
#define GP2X_BUTTON_CLICK		   (18)
#define GP2X_BUTTON_A			   (12)
#define GP2X_BUTTON_B			   (13)
#define GP2X_BUTTON_X			   (15)
#define GP2X_BUTTON_Y			   (14)
#define GP2X_BUTTON_L			   (11)
#define GP2X_BUTTON_R			   (10)
#define GP2X_BUTTON_START		   (8)
#define GP2X_BUTTON_SELECT		  (9)
#define GP2X_BUTTON_VOLUP		   (16)
#define GP2X_BUTTON_VOLDOWN		 (17)

#define UpdateInput() SDL_JoystickUpdate()

// Quickly see if a specific button is pushed:
// ex:  
//	  UpdateInput();
//	  if (IsPressed(GP2X_BUTTON_VOLUP)) {
//		   IncreaseVolume();
//	  }

#define IsPressed(button) SDL_JoystickGetButton(joy, (button))

// For when we are just waiting for a button to be pushed.
extern inline int Pressed ()
{
	return (  SDL_JoystickGetButton(joy, GP2X_BUTTON_A) ||
			  SDL_JoystickGetButton(joy, GP2X_BUTTON_B) ||
			  SDL_JoystickGetButton(joy, GP2X_BUTTON_X) ||
			  SDL_JoystickGetButton(joy, GP2X_BUTTON_Y) ||
			  SDL_JoystickGetButton(joy, GP2X_BUTTON_CLICK) ||
			  SDL_JoystickGetButton(joy, GP2X_BUTTON_SELECT) ||
			  SDL_JoystickGetButton(joy, GP2X_BUTTON_START) ||
			  SDL_JoystickGetButton(joy, GP2X_BUTTON_L) ||
			  SDL_JoystickGetButton(joy, GP2X_BUTTON_R) );
}

You can make it a 16-way joystick by checking if diagonals are pushed together with the X+Y axes. It's not possible, though, say for UP and LEFT to be pushed simultaneously. You have to check for that specific diagonal, with would be button #1 in the standard defines above.

It's still good to check for UP and LEFT simultaneous pushes, however, as it won't hurt and it will allow those with D-PAD mod's (where your GP2X actually can work like you said in your original post) to play the game, too.
 
Last edited by a moderator:
Jonathan Holland posted on Dec 21 2006 at 03:21 AM said:
It seems to me like you need to check the stick switches states for the 8 possible directions, instead of relying on "Button Left + Button Up" being pressed together, is this correct?

Well actually you need to do both.

You need to check the 8 switch states for normal stick operation, but also LEFT+UP to give a diagonal for d-pad users.

You can do both at once too as one scheme doesn't effect the other. Since on the normal stick the LEFT+UP can't be done and on a d-pad the diagonal switch doesnt exist, they don't conflict.

More here:

http://gp2x.projectinfinity.org.uk/viewpage.php?page_id=16
 
Last edited by a moderator:
Jonathan Holland posted on Dec 20 2006 at 04:21 PM said:
Originally, I wrote some joystick code that took axis readings much like a conventional joystick, or a PC d-pad.

When it didn't work, I realized that the stick on the Gp2x was digital. Now that I'm back to the drawing board, I know how to make it work, however I'm wondering on the best way to avoid dead spots.

My goal is to make the stick feel like an analog stick to the user, as responsive as possible.

It seems to me like you need to check the stick switches states for the 8 possible directions, instead of relying on "Button Left + Button Up" being pressed together, is this correct?

I'd do some more testing, but I don't have a Gp2x, and I'm annoying my friend by sending him a new GPE every few minutes :)
There are 16 possible combinations outputs for the joystick:
Up
Up + UpRight
UpRight
Right + UpRight
Right
etc

If you can get away for only 16 discrete possible directions for your game then this may be the way to go?

However, this will screw over users that have dpad mods and only 8 possible combinations.
 
Last edited by a moderator:
I use the 16-way mechanism. I don't know how it would work on a D-Pad, but on a joystick it's very responsive.
 
Back
Top