Expose Steam Controller touchpads in Gamepad API#15378
Expose Steam Controller touchpads in Gamepad API#15378slouken merged 19 commits intolibsdl-org:mainfrom
Conversation
|
Also something I noticed when comparing this to the kernel driver: |
|
I made two videos with a green pixel showing the touchpad positions to show the jitter. Kernel-Driver.mp4SDL-Driver.mp4The code I'm using to read the kernel driver is fairly simple. and then in the main loop: Note that you need avoid setting SDL_INIT_GAMEPAD, otherwise sdl blocks the /dev/input device. |
|
It's possible the jitter is because SDL doesn't filter the output, while the kernel driver does via a fuzz value, but the difference seems more noticeable than I would expect. |
It's probably reasonable to do some kind of filtering on the touchpad value. Typically values are passed straight through to the application, but they're reasonably stable on PS4 and DualSense controllers, so we'd want similar behavior here. The position of a touch release should be the last valid position. SDL_SendJoystickTouchpad() automatically ignores further calls once the touch has been released. |
|
I've implemented a moving average filter similar to what the kernel is using, but there is seemingly still some remaining jitter. I believe that it should be possible to at least detect 3 different pressure levels, since the touchpads are clickable. Since the click threshold is adjustable it might make sense to have the reported pressure value relate to the threshold in some way, but I'm not sure this is that important. |
|
Another issue is that steam still initalizes the right pad as a mouse and the left as a scroll wheel, I don't know how to stop that behavior without having an appid and access to the steamworks documentation. It works fine when steam isn't running. |
Also save the touch position in the context so it works with multiple controllers, and added documentation that the touchpads are normally reported as D-Pad and right thumbstick.
|
Okay, I went ahead and updated the changes for style and made a couple of improvements. If you're happy with the changes, I'll go ahead and merge this. |
|
I added 1 comment, the rest looks fine to me. |
|
You could also think about basing the pressure calculation on the click threshold currently set in the controller, but I'm not sure what value should be reported in that case. |
|
Merged, thanks! |
Description
Adds the touchpads to the joystick object associated with the steam controller, and updates them when possible.
Existing Issue(s)
Fixes #15359
Should be checked by someone with more experience with the hardware who knows whether the pads are properly centered at (0,0) to decide whether it should be ~ or - for reporting the y-coordinate. The kernel driver does this differently from SDL, so there are two different implementations out there. Overflow is not a problem here.
The cast I added a comment to should probably be changed in the future, but that might be better as its own issue to discuss it. I do not believe it is safe to keep it as is because struct padding is platform dependent.
I copied the syntax for converting from int to sdl's float format from the steam deck code, though I'm not sure this is optimal. Probably depends on whether sdl can be used on soft-float devices. It should be reasonably trivial to keep it mostly as int or fixed point except for the last step when converting to float, even provided that you want the same rounding behavior.