Linux上的SDL是否支持多个游戏手柄/操纵杆?

时间:2022-02-10 00:12:34

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

我有一个便宜的PS3控制器和一个NEO-GEO X控制器。它们都在例如检测到。 Fedora 20和Lubuntu 14.04。它们出现在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

设备显示在/ dev / input下面。在它们上运行udevadm都表明GreenAsia设备使用了pantherlord驱动程序,而另一个设备使用了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?

如果我运行以下测试代码,则SDL仅报告GreenAsia设备。如果我拔掉它,则检测到其他设备。这是SDL的已知限制还是其他一些问题?

// 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;
}

1 个解决方案

#1


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.

如果只有一个操纵杆映射到设备/ dev / input / event13或类似的问题,我的问题的答案似乎是“不”,这就是我的PS3控制器在我的情况下发生的情况。

In SDL_SYS_JoystickInit there is the following code

在SDL_SYS_JoystickInit中,有以下代码

#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.

当我为0时,它正在寻找“事件”设备。我的PS3控制器获取设备/ dev / input / event13和/ dev / input / js1,但我的NEO-GEO X控制器只有设备/ dev / input / js0,因此断开循环会导致它被忽略。

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

这种情况下的解决方法是将没有相应“事件”设备的设备添加到SDL_JOYSTICK_DEVICE

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

感谢Brian McFarland帮助我们深究这一点。

#1


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.

如果只有一个操纵杆映射到设备/ dev / input / event13或类似的问题,我的问题的答案似乎是“不”,这就是我的PS3控制器在我的情况下发生的情况。

In SDL_SYS_JoystickInit there is the following code

在SDL_SYS_JoystickInit中,有以下代码

#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.

当我为0时,它正在寻找“事件”设备。我的PS3控制器获取设备/ dev / input / event13和/ dev / input / js1,但我的NEO-GEO X控制器只有设备/ dev / input / js0,因此断开循环会导致它被忽略。

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

这种情况下的解决方法是将没有相应“事件”设备的设备添加到SDL_JOYSTICK_DEVICE

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

感谢Brian McFarland帮助我们深究这一点。