No Joysticks Are Showing Up


esavior

Still Fresh
Joined
Dec 2, 2005
Messages
11
I have been trying to get the buttons working with SDL. I compiled SDL with joystick support, and compiled sterm but the joysticks didnt work. So I wrote up a quick test application to try and see whats wrong. Heres the code (I appologize ahead of time for the lack of comments and over all messiness, just trying to debug):
gp2x.h
Code:
#define GP2X_WIDTH      (320)
#define GP2X_HEIGHT      (240)
#define GP2X_DEPTH      (8)


#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               (14)
#define GP2X_BUTTON_Y               (15)
#define GP2X_BUTTON_L               (10)
#define GP2X_BUTTON_R               (11)
#define GP2X_BUTTON_START           (8)
#define GP2X_BUTTON_SELECT          (9)
#define GP2X_BUTTON_VOLUP           (16)
#define GP2X_BUTTON_VOLDOWN         (17)
joysticktest.c
Code:
#include <SDL/SDL.h>
#include <stdint.h>
#include <stdbool.h>
#include "gp2x.h"
void cleanup(){
	SDL_Quit();
	exit(0);
}
void die(char *msg){
	perror(msg);
	cleanup();
	exit(1);
}
	
int main(){
	if(SDL_NumJoysticks()==0) die("No joysticks found");
	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK)<0) die("SDL Failed to Init");
	SDL_Joystick *joy = SDL_JoystickOpen(0); if(!joy) die("Failed to Init joystick");
	SDL_JoystickEventState(SDL_ENABLE);
	atexit(cleanup);
	SDL_Surface* screen;
	screen = SDL_SetVideoMode(GP2X_WIDTH,GP2X_HEIGHT,8, \
  	SDL_SWSURFACE| \
  	SDL_ANYFORMAT); if (!screen) die("Failed to set screen");
	
	uint32_t white = SDL_MapRGB(screen->format,255,255,255);
	uint32_t red = SDL_MapRGB(screen->format,255,0,0);
	
	uint32_t *current = &white;
	SDL_Event event;
	int timer=0;
	int testx=0;
	int testb=0;
	while(true) {	
  SDL_LockSurface(screen);
  SDL_FillRect(screen,NULL,*current);
  SDL_UnlockSurface(screen);
  SDL_Flip(screen);
  
  current = &white;
  
  SDL_Delay(10);
  
  SDL_JoystickUpdate();
  testx += SDL_JoystickGetButton(joy, GP2X_BUTTON_X);
  testb += SDL_JoystickGetButton(joy, GP2X_BUTTON_B);
  if(testx != 0){current = &red;testx=0;}
  if(testb != 0) cleanup();
	}
	return 0;
}
When I run it, it dumps at the beginning saying SDL says there are no joysticks. Is it that I have to modify the SDL codebade to get joystick support working for the GP2X? If so are there patch sets available? What am I doing wrong? Any help would be greatly appreciated. Oh, I also tried use the joystick via event polling, no dice there either.
 
Thanks, but I have already been to the wiki. As I said in my post I oirginally tried it with the event loop using the wiki as a reference. I went ahead and just rewrote it just incase. Here is the code I used:
Code:
#include <SDL/SDL.h>
#include <stdint.h>
#include <stdbool.h>
#include "gp2x.h"
void cleanup(){
	SDL_Quit();
	exit(0);
}
void die(char *msg){
	perror(msg);
	cleanup();
	exit(1);
}
	
int main(){
	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK)<0) die("SDL Failed to Init");
	SDL_Joystick *joy = SDL_JoystickOpen(0);
	SDL_JoystickEventState(SDL_ENABLE);
	atexit(cleanup);
	SDL_Surface* screen;
	screen = SDL_SetVideoMode(GP2X_WIDTH,GP2X_HEIGHT,8, \
  	SDL_SWSURFACE| \
  	SDL_ANYFORMAT); if (!screen) die("Failed to set screen");
	
	uint32_t white = SDL_MapRGB(screen->format,255,255,255);
	uint32_t red = SDL_MapRGB(screen->format,255,0,0);
	
	uint32_t *current = &white;
	SDL_Event event;
	int n;
	for(n=0;n<40;n++){
  SDL_LockSurface(screen);
  SDL_FillRect(screen,NULL,*current);
  SDL_UnlockSurface(screen);
  SDL_Flip(screen);
  current=&white;
  SDL_Delay(100);
  while(SDL_PollEvent(&event)) {
  	printf("x");
  	current= &red;
  }
	}
	return 0;
}
I should note that SDL_JoystickOpen returns NULL, I had to remove the check to get it to run. But in theroy the program should flash red whenever I press a button, in fact it should flash when ANY event gets called. But doesnt flash at all it just stays white. I compiled it on my workstation just to make sure it was running right and sure enough pressing keys moving the mouse etc etc would make it go red. I have also tried adding EVENTTHREAD to the init call, doesnt help anything. The reason I decided to try the other way was because the event loop didnt work and because thats how sterm did it.
 
theoddbot posted on Dec 13 2005 at 11:53 PM said:
Which SDL are you using ? Where did you get it from ? Which compiler are you using ? How are you linking it?
libSDL, libsdl.org, gcc4 from tool-chain scripts from open2x, static

I just realized there is a library pack on the wiki, I am going to try installing the SDL(and others) and try again. I had been just grabing sources around the web and manually compiling each individually

Update:
Okay when compiling against the precompiled library set from gp2x.org, the joystick test works as expected. Now the only thing to figure out is what went wrong with my libraries :(
 
Last edited by a moderator:
Back
Top