Search code examples
androidgamepad

Dualshock 5 and Android


I'm trying to implement support for gamepads for my app, but it turns out Dualshock 5 gives me really weird values. I also tested it with an external app (Gamepad Tester).

I've tried connecting with both USB-c and Bluetooth, but both connection types work equally bad.

For an example, buttons map to these keycodes:

  • Cross -> Button_B, keycode 95
  • Circle -> Unknown, keycode 0
  • Triangle -> Button_Y, keycode 100 (correct!)
  • Square -> Button_A, kecyode 96

Left stick works fine (mapped to AXIS_Y and AXIS_X, value range -1 to 1), but the right stick is mapped to LTRIGGER/BRAKE and RTRIGGER/GAS. And they has value range 0 - 0.9

What's going on here? I'm getting all these wrong values regardless of app or connection type. I'm using Android 12 (beta, I guess?). I thought DS5 was already supported on android? Can anyone confirm if they are getting equally weird values from their DS5 controller?


Solution

  • DualSense is supported through the hid-playstation kernel module, which was added to the android12-5.4 and android12-5.10 branches. Previous versions of Android used the hid-input (default) mapping which doesn't follow the Linux Gamepad Specification. The hid-playstation kernel module updates the DualSense mapping to more closely match the spec. It also adds support for the battery status, accelerometer, gyroscope, light bar LED, haptics, and touchpad.

    On Android, there are keylayout files that allow the system to change how inputs from specific devices are interpreted. For gamepads, keylayout files are used to remap inputs to follow the Android standard mapping. Using DualSense with hid-playstation requires a new keylayout file which was added in Android 12.

    My guess is you have the new keylayout file but for some reason the hid-playstation driver isn't being used. That would be consistent with your observations that Circle is unmapped and the right thumbstick is mapped to trigger axes. (With the hid-input mapping, Circle emits keycode 0x132 which is not included in the new keylayout file. The right thumbstick emits axes 0x02 and 0x05 which are translated to LTRIGGER and RTRIGGER.)

    DualSense is supposed to work in Android 12 so this is probably a bug. Can you edit your question to provide more information about your Android device?