GP2X Sdl Joystick Help


jkgp2x

Still Fresh
Joined
Feb 7, 2006
Messages
32
does anyone have a good function to get joystick input . Im having trouble because im a beginner at SDL so i need some help. Maybe give me an example of how you guys did it so i could have an idea how to get started.
 
Here's what I use, I find it simpler than events and cases:

Code:
#define GP2X_BUTTON_START (8)

int start;

SDL_JoystickUpdate();

start = SDL_JoystickGetButton(joystick, GP2X_BUTTON_START);
if(start) // do something

- Alex
 
That does look simple how you did that. But how would i put that in my code. IS there in easy void function i could use that would make this a lot easier for me
 
Here is what it may look like in code.

Code:
#define GP2X_BUTTON_START (8)

int main()
{
	// SDL Init code here
	
	bool QuitFlag = false;
	
	while(!QuitFlag)
	{

		SDL_JoystickUpdate();
	
		if ( SDL_JoystickGetButton(joystick, GP2X_BUTTON_START) != 0 )
		{
			// Do something
		}
		
		// Draw stuff here
		// Flip buffers		
	}
	
	// SDL cleanup

}
 
alrite im fine for joystick help with sdl. Now how can i do keyboard input without using the event thing. THat way i can test on my pc and still have the joystick controls in there too.
 
From "Focus on SDL"
Code:
Uint8* kbarray;
// grab the keyboard state
kbarray[SDL_a] == 1)
{ 
 // The A is down
}
 
Edit: Re-read what you asked for, not using the Event thing, well, this might be of use anyway!

I use Dev-C++ to code, the one that came with the Offical DevPack.
After searching about I found this lump of code I use as an include to my main file:

Code:
#ifdef GP2X
#define GP2X_EVENT_DOWN	SDL_JOYBUTTONDOWN
#define GP2X_EVENT_UP	  SDL_JOYBUTTONUP
#define GP2X_EVENT_VAR	 jbutton.button
//Numbers because some sources say some SDL headers are wrong in the button layout.
#define GP2X_KEY_UP		0
#define GP2X_KEY_UPLEFT	1
#define GP2X_KEY_LEFT	  2
#define GP2X_KEY_DOWNLEFT  3
#define GP2X_KEY_DOWN	  4
#define GP2X_KEY_DOWNRIGHT 5
#define GP2X_KEY_RIGHT	 6
#define GP2X_KEY_UPRIGHT   7
#define GP2X_KEY_START	 8
#define GP2X_KEY_SELECT	9
#define GP2X_KEY_TOPL	  10
#define GP2X_KEY_TOPR	  11
#define GP2X_KEY_A		 12
#define GP2X_KEY_B		 13
#define GP2X_KEY_X		 14
#define GP2X_KEY_Y		 15
#define GP2X_KEY_VOLUP	 16
#define GP2X_KEY_VOLDOWN   17
#define GP2X_KEY_JOYBUT	18
#else
#define GP2X_EVENT_DOWN	SDL_KEYDOWN
#define GP2X_EVENT_UP	  SDL_KEYUP
#define GP2X_EVENT_VAR	 key.keysym.sym
#define GP2X_KEY_UP		SDLK_KP8
#define GP2X_KEY_UPLEFT	SDLK_KP7
#define GP2X_KEY_LEFT	  SDLK_KP4
#define GP2X_KEY_DOWNLEFT  SDLK_KP1
#define GP2X_KEY_DOWN	  SDLK_KP2
#define GP2X_KEY_DOWNRIGHT SDLK_KP3
#define GP2X_KEY_RIGHT	 SDLK_KP6
#define GP2X_KEY_UPRIGHT   SDLK_KP9
#define GP2X_KEY_START	 SDLK_ESCAPE
#define GP2X_KEY_SELECT	SDLK_TAB
#define GP2X_KEY_TOPL	  SDLK_q
#define GP2X_KEY_TOPR	  SDLK_w
#define GP2X_KEY_A		 SDLK_a
#define GP2X_KEY_B		 SDLK_b
#define GP2X_KEY_X		 SDLK_x
#define GP2X_KEY_Y		 SDLK_y
#define GP2X_KEY_VOLUP	 SDLK_EQUALS
#define GP2X_KEY_VOLDOWN   SDLK_MINUS
#define GP2X_KEY_JOYBUT	SDLK_SPACE
#endif

Then in the actual code itself:
Code:
//Loop all the time it's not set to 1
   while (!done)
   {
	  SDL_Event event;
	  /* Check for events */
	  while (SDL_PollEvent (&event))
	  {
		 //What sort of event is it?
		 switch (event.type)
		 //Something being pressed?
		 case GP2X_EVENT_DOWN:
		 //Yep, what was it?
		switch( event.GP2X_EVENT_VAR )
		{
		   case GP2X_KEY_START
			  /* if press Start button, terminate program */
			  printf("User pressed Start, exiting\n");
			  done=1;
			  break;
		   case GP2X_KEY_UP:
			  /* Funky coding here */
			  break;
		  }
	  }
   }

Can't take any credit as I found this in someone else thread, sorry to who ever it was I've forgotten now!
It lets me complie for Windows for testing and the 2x for release.

Hope that's some help.

Ben
---
 
Back
Top