Use the triggers to test rumble for more fine grained vibration feedback
authorSam Lantinga <slouken@libsdl.org>
Fri, 07 Feb 2020 11:45:32 -0800
changeset 13492c0f435c3bf24
parent 13491 5de509fd3a96
child 13493 9ebdd8dfc588
Use the triggers to test rumble for more fine grained vibration feedback
test/testgamecontroller.c
     1.1 --- a/test/testgamecontroller.c	Fri Feb 07 11:44:57 2020 -0800
     1.2 +++ b/test/testgamecontroller.c	Fri Feb 07 11:45:32 2020 -0800
     1.3 @@ -114,11 +114,6 @@
     1.4          case SDL_CONTROLLERBUTTONDOWN:
     1.5          case SDL_CONTROLLERBUTTONUP:
     1.6              SDL_Log("Controller button %s %s\n", SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
     1.7 -            /* First button triggers a 0.5 second full strength rumble */
     1.8 -            if (event.type == SDL_CONTROLLERBUTTONDOWN &&
     1.9 -                event.cbutton.button == SDL_CONTROLLER_BUTTON_A) {
    1.10 -                SDL_GameControllerRumble(gamecontroller, 0xFFFF, 0xFFFF, 500);
    1.11 -            }
    1.12              break;
    1.13          case SDL_KEYDOWN:
    1.14              if (event.key.keysym.sym != SDLK_ESCAPE) {
    1.15 @@ -155,6 +150,13 @@
    1.16          }
    1.17      }
    1.18  
    1.19 +    /* Update rumble based on trigger state */
    1.20 +    {
    1.21 +        Uint16 low_frequency_rumble = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT) * 2;
    1.22 +        Uint16 high_frequency_rumble = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) * 2;
    1.23 +        SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, 250);
    1.24 +    }
    1.25 +
    1.26      SDL_RenderPresent(screen);
    1.27  
    1.28      if (!SDL_GameControllerGetAttached(gamecontroller)) {