GP2X Program To Test Davec's Joystick Configurations


miq01

Member
Joined
Nov 27, 2005
Messages
259
Location
Barcelona, Catalonia
Website
Visit site
Hi.

I posted this in the General GP2X / XGP talk board (check this post) as an answer to a message by DaveC, but it surely fits better here.

I have coded a small app to test DaveC's joystick configurations (see the Wiki) that could be useful for us coders in order to decide which config is better for our app/game/emulator.

ASAP I'll translate variable and function names into english and then I'll release the source code so that anyone can add extra configurations.

Download it here.

Edit: Here is the source code.
 
Last edited by a moderator:
Nice work. It would be nice to have a joystick configuration in either emulators/apps or even as part of the FW. It really sucks at times have to EXACTLY hit the switch to do something.
 
This gives me some hope about correcting the dead-zone issues I'm seeing in DrMD, as well as better detection of cardinal directions.
 
Here is the source code. Different configurations are implemented inside void Update().

Just a quick word of thanks for this program and now for the source code. After running the program on my GP2X I quickly identified a problem with the one-axis movement in my programs. Because of the imprecision of the joystick I was allowing the player to move if she hit any of the three directions for left or for right. So UP_LEFT, DOWN_LEFT and LEFT all moved the player left. The code looked like this:
Code:
    if (SDL_PollEvent(&event)) {
        switch (event.type) {
            case SDL_JOYBUTTONDOWN:  /* Joystick Button Press */
                switch (event.jbutton.button) {
                    case GP2X_BUTTON_LEFT:
                        xMove = -XSPEED;
                        break;
                    case GP2X_BUTTON_RIGHT: 
                        xMove = +XSPEED;
                        break;
                    case GP2X_BUTTON_UPLEFT: 
                        xMove = -XSPEED;
                        break;
                    case GP2X_BUTTON_UPRIGHT: 
                        xMove = +XSPEED;
                        break;
                    case GP2X_BUTTON_DOWNLEFT: 
                        xMove = -XSPEED;
                        break;
                    case GP2X_BUTTON_DOWNRIGHT: 
                        xMove = +XSPEED;
                        break;
                }
                break;
            case SDL_JOYBUTTONUP:  /* Joystick Button Release */
                switch (event.jbutton.button) {
                    case GP2X_BUTTON_LEFT:
                        if(xMove < 0) xMove = 0;
                        break;
                    case GP2X_BUTTON_RIGHT:
                        if(xMove > 0) xMove = 0; 
                        break;
                    case GP2X_BUTTON_UPLEFT: 
                        if(xMove < 0) xMove = 0;
                        break;
                    case GP2X_BUTTON_UPRIGHT: 
                        if(xMove > 0) xMove = 0;
                        break;
                    case GP2X_BUTTON_DOWNLEFT: 
                        if(xMove < 0) xMove = 0;
                        break;
                    case GP2X_BUTTON_DOWNRIGHT: 
                        if(xMove > 0) xMove = 0;
                        break;
The problem was that sometimes two directions were being selected at once (eg LEFT and DOWN_LEFT). So when one of them was "released" (because the joystick moved fractionally away from the DOWN_LEFT direction) it cancelled the movement even if the other one was still being pressed. This led to the player "sticking". To resolve this, I am now keeping a count ("lefts" and "rights") of how many buttons are pressed in each direction and movement in a particular direction only stops when there are no more buttons being pressed for that direction. I've ended up doing this and it seems to be much better although it still needs some testing:
Code:
int lefts = 0, rights = 0;
// ...
        if (SDL_PollEvent(&event)) {
          switch (event.type) {
            case SDL_JOYBUTTONDOWN:  /* Joystick Button Press */
                switch (event.jbutton.button) {
                    case GP2X_BUTTON_LEFT:
                        xMove = -XSPEED;
                        lefts++;
                        break;
                    case GP2X_BUTTON_RIGHT: 
                        xMove = +XSPEED;
                        rights++;
                        break;
                    case GP2X_BUTTON_UPLEFT: 
                        xMove = -XSPEED;
                        lefts++;
                        break;
                    case GP2X_BUTTON_UPRIGHT: 
                        xMove = +XSPEED;
                        rights++;
                        break;
                    case GP2X_BUTTON_DOWNLEFT: 
                        xMove = -XSPEED;
                        lefts++;
                        break;
                    case GP2X_BUTTON_DOWNRIGHT: 
                        xMove = +XSPEED;
                        rights++;
                        break;
                }
                break;
            case SDL_JOYBUTTONUP:  /* Joystick Button Release */
                switch (event.jbutton.button) {
                    case GP2X_BUTTON_LEFT:
                        lefts--;
                        if(xMove < 0 && lefts == 0) xMove = 0;
                        break;
                    case GP2X_BUTTON_RIGHT:
                        rights--;
                        if(xMove > 0 && rights == 0) xMove = 0; 
                        break;
                    case GP2X_BUTTON_UPLEFT: 
                        lefts--;
                        if(xMove < 0 && lefts == 0) xMove = 0;
                        break;
                    case GP2X_BUTTON_UPRIGHT: 
                        rights--;
                        if(xMove > 0 && rights == 0) xMove = 0; 
                        break;
                    case GP2X_BUTTON_DOWNLEFT: 
                        lefts--;
                        if(xMove < 0 && lefts == 0) xMove = 0;
                        break;
                    case GP2X_BUTTON_DOWNRIGHT: 
                        rights--;
                        if(xMove > 0 && rights == 0) xMove = 0; 
                        break;
My apologies if this seems obvious to people - I'd never encountered a problem quite like this before.
 
Last edited by a moderator:
Back
Top