InputReader module for SDL2 GameControllers
Posted: Fri Dec 30, 2016 9:08 pm
Hello Forum,
nice to meet such a helpful and vibrant community like You. I am Mike, a Programmer from Berlin playing with the Crazyflie since MakerFaire
I'm using cheapo gamecontrollers with tools like x360ce or GamePadTool to make them compatible to most games. This method didn't seem to work with the cfclient, though. No matter what SDL_GAMECONTROLLERCONFIG i used, i couldn't map the dpad's up-button to any action. I wanted to find out: why?
I learned that SDL2 defines two APIs to access input devices. PySDL2Reader uses the lower level Joystick API. This guarantees access to every button and axis present, and has no assumptions about the device. The GameController API assumes a controller with the most common functionality and allows to map the hardware devices buttons to the predefined set of axis and buttons using a config string.
I wanted to see if i could get the dpad's up-button to work using the GameController API instead, so i used pysdl2.py as a template to create a new module for this purpose. You can find the code here.
The dpad worked with that code, but it didn't help PySDL2Reader's implementation. Now having a hang of SDL2 APIs, i was brave enough to replace the code. Later, I learned, that in Python 0 evaluates to False in bool expressions, which was the original problem.
Thanks for following me on this SDL2 journey. I am looking forward to any comments and suggestions.
- Mike
nice to meet such a helpful and vibrant community like You. I am Mike, a Programmer from Berlin playing with the Crazyflie since MakerFaire

I'm using cheapo gamecontrollers with tools like x360ce or GamePadTool to make them compatible to most games. This method didn't seem to work with the cfclient, though. No matter what SDL_GAMECONTROLLERCONFIG i used, i couldn't map the dpad's up-button to any action. I wanted to find out: why?
I learned that SDL2 defines two APIs to access input devices. PySDL2Reader uses the lower level Joystick API. This guarantees access to every button and axis present, and has no assumptions about the device. The GameController API assumes a controller with the most common functionality and allows to map the hardware devices buttons to the predefined set of axis and buttons using a config string.
I wanted to see if i could get the dpad's up-button to work using the GameController API instead, so i used pysdl2.py as a template to create a new module for this purpose. You can find the code here.
The dpad worked with that code, but it didn't help PySDL2Reader's implementation. Now having a hang of SDL2 APIs, i was brave enough to replace the code. Later, I learned, that in Python 0 evaluates to False in bool expressions, which was the original problem.
Thanks for following me on this SDL2 journey. I am looking forward to any comments and suggestions.
- Mike