Fixed analog triggers on the DualSense controller

(cherry picked from commit a67d41050164e447048fa55179cc31b23be9d9b7)
(cherry picked from commit 866f7c7f7c496343ad21d32f8edc76390e11101d)
This commit is contained in:
Sam Lantinga 2023-03-30 07:25:49 -07:00
parent d94b944f91
commit 4fb81fdff9
1 changed files with 12 additions and 4 deletions

View File

@ -1083,9 +1083,17 @@ HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL_hid_device
SDL_PrivateJoystickButton(joystick, 15, (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);
@ -1178,13 +1186,13 @@ HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL_hid_device
SDL_PrivateJoystickButton(joystick, 16, (data & 0x04) ? 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;