Fixed analog triggers on the DualSense controller (cherry picked from commit a67d41050164e447048fa55179cc31b23be9d9b7)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c
index 1c1ca50..8a3608b 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps5.c
@@ -1088,9 +1088,17 @@ static void HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_MISC1, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
}
- axis = ((int)packet->ucTriggerLeft * 257) - 32768;
+ if (packet->ucTriggerLeft == 0 && (packet->rgucButtonsHatAndCounter[1] & 0x04)) {
+ axis = SDL_JOYSTICK_AXIS_MAX;
+ } else {
+ axis = ((int)packet->ucTriggerLeft * 257) - 32768;
+ }
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERLEFT, axis);
- axis = ((int)packet->ucTriggerRight * 257) - 32768;
+ if (packet->ucTriggerRight == 0 && (packet->rgucButtonsHatAndCounter[1] & 0x08)) {
+ axis = SDL_JOYSTICK_AXIS_MAX;
+ } else {
+ axis = ((int)packet->ucTriggerRight * 257) - 32768;
+ }
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, axis);
axis = ((int)packet->ucLeftJoystickX * 257) - 32768;
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_LEFTX, axis);
@@ -1186,13 +1194,13 @@ static void HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_PS5_RIGHT_PADDLE, (data & 0x80) ? SDL_PRESSED : SDL_RELEASED);
}
- if (packet->rgucButtonsAndHat[1] & 0x04) {
+ if (packet->ucTriggerLeft == 0 && (packet->rgucButtonsAndHat[1] & 0x04)) {
axis = SDL_JOYSTICK_AXIS_MAX;
} else {
axis = ((int)packet->ucTriggerLeft * 257) - 32768;
}
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERLEFT, axis);
- if (packet->rgucButtonsAndHat[1] & 0x08) {
+ if (packet->ucTriggerRight == 0 && (packet->rgucButtonsAndHat[1] & 0x08)) {
axis = SDL_JOYSTICK_AXIS_MAX;
} else {
axis = ((int)packet->ucTriggerRight * 257) - 32768;