Raylib: [input] Gamepad buttons and axis not working (linux)

Created on 22 Jul 2020  路  18Comments  路  Source: raysan5/raylib

Issue description

I have tried in both my own project and the gamepad example both in browser and
on my machine compiled. However it just shows up with gamepad not detected.
I have tested with jstest to make sure the joystick is showing up on a system
level and it appears to be fine. (To note i have tried this with both a Xbox
one controller and a steam controller)

Environment

I am on KISS Linux latest stable kernel.

Code Example

Just the code in the gamepad_test_example that checks if a gamepad is
available. AKA (IsGamePadAvailable(GAMEPAD_PLAYER1))

All 18 comments

@muevoid is the gamepad connected before running the example? It should be at least detected... it could be a KISS Linux specific issue...

Yes i can confirm the gamepad is connected before hand. I'm not sure exactly what on KISS could cause this issue.

@muevoid raylib uses GLFW internally on DESKTOP_PLATFORM (Windows, Linux, macOS) to manage inputs. Every frame [core] PollInputEvents() is called that also scans possible gamepads with glfwJoystickPresent().

IsGamepadAvailable(int gamepad) just returns the result of that detection (true or false), you can try with different int gamepad values just in case but if the function always returns false then the issue is probably on GLFW side and not in raylib.

Kk I am familiar with glfw and will test this tommorow.

Just a reference in case it can be useful in the future for gamepad buttons mapping: https://www.glfw.org/docs/3.3/input_guide.html#gamepad

An additional perspective > I just tried this on Ubuntu 20.04 LTS x86_64, kernel: 5.4.0-42-generic, using raylib 3.0.0. My build of 'core_input_gamepad.c' detects both a cheap Logitech controller and an 8bitdo SNES controller. They do not need to be plugged in before compilation; I can disconnect and reconnect the controllers, and the program will detect them and display their names correctly. However, I can't seem to be able to get any input from any of them, and neither buttons nor axes show up in the interface.

Hmmm I am still doing testing will post here soon.

This is for sure an issue with my configuration and not raylib. So I will close this jist of it was my Xorg configuration and some stuff with evdev.

Edit: I believe defutura's issue is unrelated to this issue.

I may have talked too soon my issue is now identical to defuturas. Gamepad is detected by raylib however no buttons or axis is detected.

neither buttons nor axes show up in the interface.

I should have expressed myself more clearly here. My build does in fact detect the 5 axes correctly with GetGamepadAxisCount() on line 164, and displays them with the following for loop, but no input data is shown for any of them.

@defutura Have you had any luck with this yet?

@muevoid No, I haven't looked at it yet, I'm doing most of my programming on a Windows machine. Will post here if I find anything out.

@defutura, @muevoid:
I had the same problem today. Raylib identified my gamepad and correctly detected connections/disconnections, but couldn identify button presses and axis movements.

My joystick worked fine with SDL and glfw3 sample codes, but not with raylib.
Following @raysan5 comment, my case was that the glfw gamepad database mapping was not updated with my model (03000000c62400003a54000001010000).

I've found a mapping for my gamepad here:
https://github.com/gabomdq/SDL_GameControllerDB/

With the mapping configuration for my gamepad, I cloned the raylib repo and added the mapping in the file /src/external/glfw/src/mappings.h and then recompiled the whole thing again.

After this it all worked.

To find my gamepad ID, I added a debug printf to log js->guid at the beginning of findValidMapping (/src/external/glfw/src/input.c). Then I recompiled the gamepad example and ran, checking the console output for the Gamepad ID.

Or, you could try to update the mappings dynamically
https://www.glfw.org/docs/3.3/input_guide.html#gamepad_mapping

@coderoth thank you very much for reporting!

Please, could you check if GLFW3 main branch is also updated? I will update raylib glfw version with it...

It seems the glfw mappings.h file is outdated (it was updated 10 months ago and it has 476 lines, while the gamecontrollerdb.txt has more than 800).

They have a Cmake script that "updates" the mappings.h file with the latest gamecontrollerdb.txt contents:
https://github.com/glfw/glfw/blob/master/CMake/GenerateMappings.cmake

Maybe they manually execute that cmake script as part of the build?

I cloned their repository and issued the following commands to update the mappings and it worked (the final mappings file went from 476 lines to 954 and my gamepad id was finally there):

cd glfw/CMake
cmake -P GenerateMappings.cmake ../src/mappings.h.in ../src/mappings.h

That command worked when I executed it from the raylib repo too (/src/external/glfw/CMake).
Maybe this additional step could be added to the raylib build process, before compiling?
Or you could run the above cmake command and commit a more recent mapping to the raylib repository.

@coderoth I maintain the plain Makefiles building system, not the CMake... maybe I can just update mappings.h manually on raylib side. Could you provide the updated file, please?

Updated version of the file:
mappings.h.txt

Created the following pull request, if you prefer:
https://github.com/raysan5/raylib/pull/1381

Updated! It should work now! Closing the issue!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

williamfjm picture williamfjm  路  3Comments

Triangle345 picture Triangle345  路  8Comments

SethArchambault picture SethArchambault  路  9Comments

gavriil07 picture gavriil07  路  11Comments

raysan5 picture raysan5  路  10Comments