Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using SDL_GameController in SDL2 Joypad Driver sometimes returns different event ID #11885

Open
mrfixit2001 opened this issue Jan 15, 2021 · 6 comments

Comments

@mrfixit2001
Copy link

Retroarch currently tries to use SDL_GameController for gamepad button event detection, and uses SDL_Joystick as a backup mechanism. While this usually works fine, unfortunately not always. I've recently identified that 8bitdo controllers (in some cases, not always, and for some unknown reason), return different event IDs when the event is returned from SDL_GameController vs SDL_Joystick. I am testing with SDL 2.0.12 on ARMv8.

My workaround is to remove this conditional:
https://github.com/libretro/RetroArch/blob/master/input/drivers_joypad/sdl_joypad.c#L105
Which then does not assign a value to pad->controller and the rest of the code correctly falls back to using SDL_Joystick.

This might be a glitch within SDL itself, but twinaphex asked that I document my findings in an issue so that others can have visibility.

@crocket
Copy link

crocket commented Oct 18, 2021

SDL2 gamecontroller API ignores many buttons on hori fighting commander for nintendo switch.
See #13131

@crocket
Copy link

crocket commented Oct 18, 2021

https://wiki.libsdl.org/CategoryGameController says

SDL_GameController is an abstraction for gamepads ("controllers") similar to the xbox360-pad: They have a DPAD, two analog sticks, 4 buttons on the right (often called A, B, X, Y), shoulder buttons (two of which might be axes) and 3 buttons in the middle (Start, Back and usually some kind of logo-button).
This includes devices that have a similar layout, like the Playstation DualShock Controller, but different button names; SDL_GameController uses the naming-conventions of xbox360/XInput for all supported devices, so you'll know that SDL_CONTROLLER_AXIS_LEFTX is always the X-Axis of the left Analog Stick, or SDL_CONTROLLER_BUTTON_B is always the rightmost buttons of the 4 buttons on the right, for example.

To SDL2 joystick API, SDL2 gamecontroller is what RetroPad is to udev gamepads.
SDL2 gamecontroller API requires a database.
I confirmed that src/joystick/SDL_gamecontrollerdb.h doesn't have a mapping for my controller in SDL source code.

This is an issue in SDL2 gamecontroller database.

If SDL2 gamecontroller db doesn't have a mapping for a controller, SDL2 gamecontroller API may ignore buttons or return different event IDs.

I suggest not using SDL gamecontroller API. Perhaps, an SDL2 autoconfig file can individually opt out of SDL gamecontroller API?

The gamecontroller database has many variants of hori fighting commander, but no variant really supports the second mode of hori fighting commander for nintendo switch. One variant supports the first mode. Choosing any variant of hori fighting commander can break the second mode of hori fighting commander for nintendo switch.

@crocket
Copy link

crocket commented Oct 18, 2021

I discovered that if I disabled SDL2 gamecontroller API via a patch, I could just copy udev autoconfig files to sdl2 autoconfig folder and set input_driver to sdl2 and input_device to an appropriate device name reported by sdl2-jstest.

@crocket
Copy link

crocket commented Nov 9, 2021

@twinaphex Do you think it is a good idea to get rid of SDL gamecontroller API in retroarch?

@LibretroAdmin
Copy link
Contributor

It seems reasonable to add a setting to allow for SDL gamecontroller api to be skipped.

@lucasmr
Copy link
Contributor

lucasmr commented Sep 16, 2022

I think RetroArch prefers to use the GameController API whenever possible, there might be bugs on RetroArch's side by using GameController in cases where it shouldn't, some buttons are getting ignored or with the wrong IDs. By skipping SDL's GameController API, apparent bugs can be fixed and you can start using SDL2 HIDAPI drivers #14421.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants