1

I have a cheap PS3 controller and a NEO-GEO X controller. They are both detected on eg. Fedora 20 and a Lubuntu 14.04. They appear in lsusb

Bus 001 Device 012: ID 0e8f:0003 GreenAsia Inc. MaxFire Blaze2
Bus 001 Device 016: ID 1292:4e47 Innomedia

The devices appear underneath /dev/input. Running udevadm on them both shows that the GreenAsia device uses the pantherlord driver whereas the other device uses hid-generic

If I run the following test code only the GreenAsia device is reported by SDL. If I unplug it then the other device is detected. Is this a known limitation of SDL or some other issue?

// from http://www.libsdl.org/release/SDL-1.2.15/docs/html/guideinput.html
#include "SDL/SDL.h"

int main () {
    if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0)
    {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        exit(1);
    }
    printf("%i joysticks were found.\n\n", SDL_NumJoysticks() );
    printf("The names of the joysticks are:\n");

    for( int i=0; i < SDL_NumJoysticks(); i++ ) 
    {
        printf("    %s\n", SDL_JoystickName(i));
    }
   return 0;
}
wreckgar23
  • 1,025
  • 9
  • 22
  • 1
    Should work fine. Can you see raw event output from both at the same time? Simplest way to do this is "cat /dev/input/" for each device in the two terminals then press buttons on both. – Brian McFarland Apr 12 '15 at 17:10
  • Also, FYI, SDL2 introduced a new Gamepad abstraction layer that makes working with devices like those waaaay easier. It's built on top of the joystick API though, so switching probably won't fix your problem. – Brian McFarland Apr 12 '15 at 17:11
  • @BrianMcFarland Hi I can cat both devices and get input from them both at the same time. I can only get one at a time detected by my test program and I get the same behaviour with MAME and other emulators – wreckgar23 Apr 13 '15 at 20:33
  • 1
    At this point then, I'd probably try the following: 1) specify both joysticks explicitly with the `SDL_JOYSTICK_DEVICE` env variable (':' seperated abs paths), or 2) Build SDL from source and stepping through `src/linux/SDL_sysjoystick.c:SDL_SYS_JoystickInit()`. Skimming through the code, I don't understand why it's not working, but it shouldn't be too hard to debug since you've effectively ruled out driver problems now. – Brian McFarland Apr 14 '15 at 12:59
  • @BrianMcFarland not stepped through the code yet, but setting both sticks in the `SDL_JOYSTICK_DEVICE` variable gives me 3 joysticks listed! (one of the joysticks is listed twice). So a workaround at least is to figure out which joystick isn't picked up by SDL and set it to that environment variable. – wreckgar23 Apr 14 '15 at 19:15

1 Answers1

2

The answer to my question appears to be "no" if only one of the joysticks maps to a device /dev/input/event13 or similar, which is what happens to my PS3 controller in my case.

In SDL_SYS_JoystickInit there is the following code

#if SDL_INPUT_LINUXEV
        /* This is a special case...
           If the event devices are valid then the joystick devices
           will be duplicates but without extra information about their
           hats or balls. Unfortunately, the event devices can't
           currently be calibrated, so it's a win-lose situation.
           So : /dev/input/eventX = /dev/input/jsY = /dev/jsY
        */
        if ( (i == 0) && (numjoysticks > 0) )
            break;
#endif

When i is 0 it is looking for the "event" devices. My PS3 controller gets devices /dev/input/event13 and /dev/input/js1, but my NEO-GEO X controller only has the device /dev/input/js0, so breaking from the loop causes it to get ignored.

A workaround in this case is to add the device that doesn't have a corresponding "event" device to SDL_JOYSTICK_DEVICE

Thanks to Brian McFarland with the help in getting to the bottom of this.

wreckgar23
  • 1,025
  • 9
  • 22