Skip to content

Commit

Permalink
Use the triggers to test rumble for more fine grained vibration feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Feb 7, 2020
1 parent 8ba77b3 commit dd0ebfd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions test/testgamecontroller.c
Expand Up @@ -114,11 +114,6 @@ loop(void *arg)
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
SDL_Log("Controller button %s %s\n", SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
/* First button triggers a 0.5 second full strength rumble */
if (event.type == SDL_CONTROLLERBUTTONDOWN &&
event.cbutton.button == SDL_CONTROLLER_BUTTON_A) {
SDL_GameControllerRumble(gamecontroller, 0xFFFF, 0xFFFF, 500);
}
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym != SDLK_ESCAPE) {
Expand Down Expand Up @@ -155,6 +150,13 @@ 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;
SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, 250);
}

SDL_RenderPresent(screen);

if (!SDL_GameControllerGetAttached(gamecontroller)) {
Expand Down

0 comments on commit dd0ebfd

Please sign in to comment.