Issues getting DualSense touchpad X coordinates with HID
Hello everyone,
So I'm working on a way to get all the PS5 DualSense controller mappings with HID object. I have no problems for most of them, from the buttons to the gyroscope and accelerometer. But for the touchpad coordinates, I don't get why it's working like that : the Y coordinates (from top to bottom) have no problems, for one and two fingers. They are absolute, and the values go from 0 to 67. But for the X axis, it seems to be like a counter increasing from 0 to 255, looping when sliding to the right and decreasing in the other direction.
Did someone face the same issue, and if so managed to get through ? Would there be a way to convert the relative values into absolute coordinates for X ?
Note that I know gamepad object exists, but for larger compatibility reasons, I need to use HID which is more compliant.
I'm currently on Mac OS Ventura 13 Intel, and using Max 9.0.4.
Thank you for your replies !
Edit : I now made the update to 9.0.5, without change.
Hi Olivier,
I mean this in the kindest of ways, but I think you are simply better off using gamepad. In 9.0.5 you can also load community mappings using either the addmappingfile message, or installing a gamecontrollerdb.txt file in the search path? Might help for some older controllers.
From gamepad reference file:
addmappingfile
Add SDL controller mappings from a file such as gamecontrollerdb.txt from the excellent SDL_GameControllerDB community database. If you place a file named "gamecontrollerdb.txt" in the Max search path, gamepad will load the mapping file prior initializing SDL with the first gamepad instance created. This can work better for certain controllers than loading the mapping file after creation.
However, because of my own curiosity and to provide an example of how the hid object enables people to build their own drivers for proprietary HID reports, I decided to look at what the dualsense HID report looks like. SDL2 has written specific, and from what I can tell, reverse engineered driver for such hardware. This is completely out of scope for us and the HID object, and we won't be investing significant time and effort in implementing game controller specific HID drivers for proprietary HID reports.
I've made an example patch which ports the SDL2 code to Javascript to demonstrate what is being reported in the HID report and how you might use it to extract the X/Y touch coordinates, which are unlabeled 12 bit values packed in a 24 bit value(3-byte array).
One of the very important things that this example demonstrates is that for proprietary fields that have a zero usage value, the helpfile ignores this output, which is often padding information. For parsing proprietary data, you will not want to ignore this data, and I'll probably update the helpfile accordingly for a future release.
Otherwise, I don't think I'll be spending much more time on this sort of thing, and again would stress how you should use the gamepad object and not hid for this purpose, unless you want to do lots of work supporting such game controllers manually (we have no such plans).
That said, maybe this example will inspire you to go deeper, and if so, I hope it is a fun filled journey of reverse engineering, puzzle solving, and/or standing on the shoulders of the giants that have worked on SDL.
Warm regards,
Joshua
EDIT: Updated example for button12-15
Hello Joshua,
It's indeed working with the method you gave me.
Thank you so much for this, I really appreciate the time and efforts you put into this !
Kind regards,
Olivier
Great! In case you are going deeper with this approach, I cleaned up a copy paste bug for the button handling. Archive updated above.
Hello,
So I will continue here because it is actually the continuation of what I'm trying to do.
When I was talking about larger compatibility, it was between MacOS and Windows. I want my application to work with most controllers and on both OS. For example the Logitech Dual Action and Thrustmaster Dual Analog 4 are recognized when plugged on Mac but not on Windows.
I tried to use the new gamepad feature "addmappingfile" using the "gamecontrollerdb.txt" file provided on https://github.com/mdqinc/SDL_GameControllerDB but it didn't work.
To investigate, I downloaded SDL2 Gamepad Mapper and there the device was recognized. I verified the controllers's GUID and mapping and pasted it in "gamecontrollerdb.txt", without success.
For more details, I can tell that those two controllers don't appear in the Windows device manager neither, but are working on some softwares. It makes me think the issue is coming from the fact that those controllers (and basically the old ones) are using DirectInput and not XInput for their mappings.
I you can confirm that Max is using only XInput and does not support DirectInput, it will elucidate the question.
Best,
Olivier
I'm not 100% sure that DINPUT devices which conform to a traditional gamepad (dual joystick) layout with correct mapping in gamecontrollerdb.txt will not work with gamepad, but I can confirm that my brief attempt to get a logitech extreme 3d pro joystick controller working with the gamepad object on windows with a mapping I made with https://www.generalarcade.com/gamepadtool/ was not successful today.
We only use the SDL gamepad API and not the Joystick API, which is what I'm guessing is required to recognize such devices. I've added a feature request to support devices via the lower level Joystick API in the future.
In the meantime it looks like you'll need to use the hid object for joystick controllers, and maybe the older logitech dual action (I don't have one of these to test with, but I've ordered one off ebay and will let you know if I'm able to get it working with the gamecontrollerdb.txt mapping).
I would probably just have both hid and gamepad inputs in your patch and let the user choose the HID input if their device is not automatically registered and recognized by the gamepad object.
Just an update. I received my old Logitech Dual Action dinput only controller, and I can confirm that it is not recognized with the current version of the gamepad object.
I have done some initial experiments for recognizing both my Logitech Extreme 3D Pro Joystick and the Logitech Dual Action gamepad and it will likely be included in a future version.
In the meantime, if you need to support these types of controllers, but still want to make use of the features gamepad provides, you'll need to use the suggested combination of gamepad and hid (for devices that gamepad does not support).
Well thank you lot for your dedication on this question, it was very helpful ! I will now wait and hope it will be possible to add this easily on your side. I know it's difficult to tell now but when could we expect a possible fix ? More in weeks or in months ?
In the meantime, I wish you good continuation and good development !
Thanks! To be honest, this one is likely going to need a decent amount of time to adequately test before making it into the distribution, because it requires enabling parts of SDL which were not being enabled before (i.e. the video subsystem on windows, because for some reason that is required to load all the appropriate libraries to support direct input, and we need to make sure that it plays well with all of the other aspects of Max and Jitter before including). So...I'm going to guess months not weeks at this point.
Shouldn't be terribly hard for you to make an hid fallback in the meantime, if you need something working sooner.