From 24cc0012f071f3c95ecf288959c9d75507df335f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 25 Nov 2020 16:05:15 -0800 Subject: [PATCH] Some controllers don't always reset their triggers to zero when they are released (e.g. Xbox One S in Bluetooth mode), so only trigger rumble if the trigger is pulled halfway or more. --- test/testgamecontroller.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c index d32148040..52d8eec84 100644 --- a/test/testgamecontroller.c +++ b/test/testgamecontroller.c @@ -308,17 +308,19 @@ loop(void *arg) /* Update rumble based on trigger state */ { - Uint16 low_frequency_rumble = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT) * 2; - Uint16 high_frequency_rumble = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) * 2; + Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT); + Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT); + Uint16 low_frequency_rumble = ConvertAxisToRumble(left); + Uint16 high_frequency_rumble = ConvertAxisToRumble(right); SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, 250); } /* Update trigger rumble based on thumbstick state */ { - Sint16 left_y = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_LEFTY); - Sint16 right_y = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_RIGHTY); - Uint16 left_rumble = ConvertAxisToRumble(~left_y); - Uint16 right_rumble = ConvertAxisToRumble(~right_y); + Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_LEFTY); + Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_RIGHTY); + Uint16 left_rumble = ConvertAxisToRumble(~left); + Uint16 right_rumble = ConvertAxisToRumble(~right); SDL_GameControllerRumbleTriggers(gamecontroller, left_rumble, right_rumble, 250); }