Axes and Hats not read in PyGame/SDL 1.2

Bug #376537 reported by pymike
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
libsdl1.2 (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

I'm on Ubuntu 8.10 Intrepid, and since the upgrade (from 8.04) joystick hats and axes haven't been recognized using PyGame or SDL 1.2. Previously built games like Super Tux 2, Alex the Allegator, and Kobo Deluxe still work, but the hats/axes are not recognized when compiling new apps.

Revision history for this message
illume (illume) wrote :

hi,

Here is a related thread on the SDL mailing list:
http://thread.gmane.org/gmane.comp.lib.sdl/40019

It seems either linux or ubuntu has changed the numbers returned for different joystick functions... for no good reason.

This breaks all SDL based games that use joysticks.

cheers,

Revision history for this message
illume (illume) wrote :

... from pymikes email to the pygame mailing list...

here's an SDL C program to show it's broken...

Results of running the program on ubuntu listed below the code.

#include "SDL/SDL.h"

int main() {
    SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_VIDEO);
    SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
    SDL_Joystick *joy;
    joy = SDL_JoystickOpen(0);
    printf("Name of joystick: %s\n", SDL_JoystickName(0));
    printf("Number of hats: %d\n", SDL_JoystickNumHats(joy));
    printf("Number of buttons: %d\n", SDL_JoystickNumButtons(joy));
    printf("Number of balls: %d\n", SDL_JoystickNumBalls(joy));

    SDL_Event event;
    Uint8 hat_state;

    int running = 1;
    while( running ) {

        SDL_JoystickUpdate();

        hat_state = SDL_JoystickGetHat(0, 0);
        if( hat_state == SDL_HAT_UP )
            printf("Hat is pointing up");

        while(SDL_PollEvent(&event)) {
            switch(event.type) {
                case SDL_QUIT:
                    running = 0;
                    break;
                case SDL_KEYDOWN:
                    switch(event.key.keysym.sym) {
                        case SDLK_ESCAPE:
                            running = 0;
                            break;
                        default:
                            break;
                    }

                    break;
                case SDL_JOYBUTTONDOWN:
                    switch(event.jbutton.button) {
                        case 1:
                            printf("1 was pressed\n");
                            break;
                        case 2:
                            printf("2 was pressed\n");
                            break;
                    }

                    break;
                case SDL_JOYBUTTONUP:
                    switch(event.jbutton.button) {
                        case 1:
                            printf("1 was released\n");
                            break;
                        case 2:
                            printf("2 was released\n");
                            break;
                    }

                    break;
            }
        }
    }

    SDL_Quit();
    return 1;
}

Name of joystick: Logitech Logitech Dual Action
Number of hats: 0
Number of buttons: 12
Number of balls: 0
1 was released
2 was released
1 was pressed
1 was released
2 was pressed
2 was released

Revision history for this message
pymike (pymike) wrote :

Apparently only hats are broken. In the code above, I was checking for balls instead of axes. I corrected the code, and axes are still working fine.

Revision history for this message
Chris Boyle (cmb) wrote :

Check which joystick device is being used. Perhaps SDL is using /dev/input/event* where it was using /dev/input/js0 previously. See also bug 410187. Could be something completely different, especially since event devices are supposed to give SDL *more* info about hats etc, not less, but worth checking.

Revision history for this message
sam grayson (sam-grayson-ubuntu) wrote :

I am using pygame (which wraps SDL), and I have http://www.powera.com/Products/PROD_CTRLS/PLATFORM_PS3/CPFA051083 on a USB connection.
pygame.joystick.Joystick.get_numaxes() returns 1, even though it should return 4.
pygame.joystick.Joystick.get_numaxes() returns 0, even though it should return 1.
The joystick responds to pygame.JOYAXISMOTION events when any joystick moves, however.
The one axis that I do have control over (kind of) is the x axis on the left joystick
When I press the hat down in any direction, I get a segmentation fault:
"Fatal Python error: (pygame parachute) Segmentation Fault"
That is probably related.

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Please reply if this is still an issue on a supported release.

Changed in libsdl1.2 (Ubuntu):
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.