InputReader module for SDL2 GameControllers

Firmware/software/electronics/mechanics
Post Reply
mikezter
Beginner
Posts: 1
Joined: Fri Dec 30, 2016 7:40 pm

InputReader module for SDL2 GameControllers

Post by mikezter »

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
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: InputReader module for SDL2 GameControllers

Post by arnaud »

Hello Mike,

Welcome! Thanks for the pull request and thanks for telling us the story of it!

I will test the PR and merge it.

/Arnaud
Post Reply