EmulationStation fails to detect newly connected controller post-boot
-
- Raspberry Pi Zero 2W
- Raspbian GNU/Linux 10 (buster)
- RetroPie 4.8.5 (4195f151)
- Original image generated by the Raspberry Pi Imager
- no USB devices connected
- Nintendo Switch Pro Controller (Bluetooth)
- Setup via https://retropie.org.uk/docs/Nintendo-Switch-Controllers/
I am able to connect the controller using Bluetooth to the Raspberry Pi and get a response via
jstest /dev/input/js0
. If I pair the controller beforeemulationstation
fully boots at startup (initial splashscreen for EmulationStation asserts "NO GAMEPADS DETECTED" (source)), or start a new instance ofemulationstation
via CLI (no such splashscreen appears), controller input is detected normally and can be used as a normal controller.However, if I am to disconnect the controller and reconnect, the existing instance of EmulationStation does not pick up the reconnected controller; however, running
jstest
again shows the controller is indeed reconnected.I see that EmulationStation is adding / removing devices by monitoring SDL events (source) and I was suspecting that maybe the
SDL_JOYDEVICEADDED
wasn't firing, so I tried to monitor --import sdl2 import ctypes sdl2.SDL_Init(sdl2.SDL_INIT_JOYSTICK) event = sdl2.SDL_Event() def _list_js(): for j in range(sdl2.SDL_NumJoysticks()): js = sdl2.SDL_JoystickOpen(j) print(sdl2.SDL_JoystickName(js)) while True: if sdl2.SDL_PollEvent(ctypes.byref(event)) != 0: if event.type == sdl2.SDL_JOYDEVICEADDED: print("SDL_JOYDEVICEADDED") _list_js() elif event.type == sdl2.SDL_JOYDEVICEREMOVED: print("SDL_JOYDEVICEREMOVED") _list_js()
Running this after boot, with the controller connected, gets me
SDL_JOYDEVICEADDED b'Nintendo Switch Pro Controller' b'Nintendo Switch Pro Controller IMU' SDL_JOYDEVICEADDED b'Nintendo Switch Pro Controller' b'Nintendo Switch Pro Controller IMU' # Power off controller and wait for 10s SDL_JOYDEVICEREMOVED # IMU removed b'Nintendo Switch Pro Controller' SDL_JOYDEVICEREMOVED # Controller removed # Power back on and paired SDL_JOYDEVICEADDED b'Nintendo Switch Pro Controller IMU' # Missing Controller
If I SIGTERM and run the script again, I get
SDL_JOYDEVICEADDED b'Nintendo Switch Pro Controller' b'Nintendo Switch Pro Controller IMU' SDL_JOYDEVICEADDED b'Nintendo Switch Pro Controller' b'Nintendo Switch Pro Controller IMU'
So it appears there is some SDL event which is not monitored that impacts
SDL_NumJoysticks()
.I'm not sure if this is the root of the problem, but it appears that the Aloshi base (source) shares this controller management logic, so something may be out of date.
-
This looks more like a SDL issue than EmulationStation. Are you able to compile a recent SDL2 and try testing with that version ? Did you install the hid-nintendo module for your gamepad ?
-
$ sdl2-config --version 2.0.10 $ dkms status nintendo, 3.2, 5.10.103-v7+, armv7l: installed xpad, 0.4, 5.10.103-v7+, armv7l: installed (original_module exists)
Seems like the SDL2 lib is pretty out of date in the repo list.
Downloaded the latest stable and ran the usual
../configure make all make DESTDIR=/home/pi/sdl-tmp/ install
import os os.environ["PYSDL2_DLL_PATH"] = "/home/pi/sdl-tmp/usr/local/lib" import sdl2 import ctypes v = sdl2.version.SDL_version() sdl2.SDL_GetVersion(ctypes.byref(v)) assert "%s.%s.%s" % (v.major, v.minor, v.patch) == "2.28.3" # new sdl2.SDL_Init(sdl2.SDL_INIT_JOYSTICK) event = sdl2.SDL_Event() ... # same as above
Running the same flow as before
SDL_JOYDEVICEADDED b'Nintendo Switch Pro Controller' # Power off controller and wait for 10s SDL_JOYDEVICEREMOVED # Controller removed # Power back on and paired, no SDL_JOYDEVICEADDED event generated
And rerunning shows the controller as before, which should mean the same behavior will persist even if I were to upgrade SDL2.
Am I invoking the SDL API correctly here? Should I file a bug instead with the SDL developers? I see a tangentially related issue https://github.com/libsdl-org/SDL/issues/8085, but this does not appear to be the same problem I'm seeing.
Update: Opened https://github.com/libsdl-org/SDL/issues/8260 in case the SDL invocation pattern in the script above is the recommended method.
-
I think opening the issue is ok - seems something is not working correctly. Note that SDL includes some testing applications in the
test
folder, one of them is a joystick test - if you can reproduce the issue with it, then there's no need forpysdl2
or any confusion on the usage of SDL's event handling functions.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.