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
joysticktest.c
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.
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)
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;
}