Skip to content

Commit a67d410

Browse files
committed
Fixed analog triggers on the DualSense controller
1 parent 2d64f41 commit a67d410

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/joystick/hidapi/SDL_hidapi_ps5.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -1084,9 +1084,17 @@ static void HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL
10841084
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_MISC1, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
10851085
}
10861086

1087-
axis = ((int)packet->ucTriggerLeft * 257) - 32768;
1087+
if (packet->ucTriggerLeft == 0 && (packet->rgucButtonsHatAndCounter[1] & 0x04)) {
1088+
axis = SDL_JOYSTICK_AXIS_MAX;
1089+
} else {
1090+
axis = ((int)packet->ucTriggerLeft * 257) - 32768;
1091+
}
10881092
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
1089-
axis = ((int)packet->ucTriggerRight * 257) - 32768;
1093+
if (packet->ucTriggerRight == 0 && (packet->rgucButtonsHatAndCounter[1] & 0x08)) {
1094+
axis = SDL_JOYSTICK_AXIS_MAX;
1095+
} else {
1096+
axis = ((int)packet->ucTriggerRight * 257) - 32768;
1097+
}
10901098
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
10911099
axis = ((int)packet->ucLeftJoystickX * 257) - 32768;
10921100
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX, axis);
@@ -1183,13 +1191,13 @@ static void HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL
11831191
SDL_SendJoystickButton(timestamp, joystick, SDL_CONTROLLER_BUTTON_PS5_RIGHT_PADDLE, (data & 0x80) ? SDL_PRESSED : SDL_RELEASED);
11841192
}
11851193

1186-
if (packet->rgucButtonsAndHat[1] & 0x04) {
1194+
if (packet->ucTriggerLeft == 0 && (packet->rgucButtonsAndHat[1] & 0x04)) {
11871195
axis = SDL_JOYSTICK_AXIS_MAX;
11881196
} else {
11891197
axis = ((int)packet->ucTriggerLeft * 257) - 32768;
11901198
}
11911199
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
1192-
if (packet->rgucButtonsAndHat[1] & 0x08) {
1200+
if (packet->ucTriggerRight == 0 && (packet->rgucButtonsAndHat[1] & 0x08)) {
11931201
axis = SDL_JOYSTICK_AXIS_MAX;
11941202
} else {
11951203
axis = ((int)packet->ucTriggerRight * 257) - 32768;

0 commit comments

Comments
 (0)