Don't rumble Bluetooth PS4 controllers by default, as that switches the controller into extended input report mode, which breaks games that use DirectInput.
authorSam Lantinga <slouken@libsdl.org>
Wed, 29 Aug 2018 20:23:39 -0700
changeset 12163dd056c76593a
parent 12162 03a4f7b4ec77
child 12164 8b71c22d6714
Don't rumble Bluetooth PS4 controllers by default, as that switches the controller into extended input report mode, which breaks games that use DirectInput.
include/SDL_hints.h
src/joystick/hidapi/SDL_hidapi_ps4.c
     1.1 --- a/include/SDL_hints.h	Wed Aug 29 20:23:36 2018 -0700
     1.2 +++ b/include/SDL_hints.h	Wed Aug 29 20:23:39 2018 -0700
     1.3 @@ -488,6 +488,21 @@
     1.4  #define SDL_HINT_JOYSTICK_HIDAPI_PS4 "SDL_JOYSTICK_HIDAPI_PS4"
     1.5  
     1.6  /**
     1.7 + *  \brief  A variable controlling whether extended input reports should be used for PS4 controllers when using the HIDAPI driver.
     1.8 + *
     1.9 + *  This variable can be set to the following values:
    1.10 + *    "0"       - extended reports are not enabled (the default)
    1.11 + *    "1"       - extended reports
    1.12 + *
    1.13 + *  Extended input reports allow rumble on Bluetooth PS4 controllers, but
    1.14 + *  break DirectInput handling for applications that don't use SDL.
    1.15 + *
    1.16 + *  Once extended reports are enabled, they can not be disabled without
    1.17 + *  power cycling the controller.
    1.18 + */
    1.19 +#define SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE "SDL_JOYSTICK_HIDAPI_PS4_RUMBLE"
    1.20 +
    1.21 +/**
    1.22   *  \brief  A variable controlling whether the HIDAPI driver for Steam Controllers should be used.
    1.23   *
    1.24   *  This variable can be set to the following values:
     2.1 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c	Wed Aug 29 20:23:36 2018 -0700
     2.2 +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c	Wed Aug 29 20:23:39 2018 -0700
     2.3 @@ -107,6 +107,7 @@
     2.4      SDL_bool is_dongle;
     2.5      SDL_bool is_bluetooth;
     2.6      SDL_bool audio_supported;
     2.7 +    SDL_bool rumble_supported;
     2.8      Uint8 volume;
     2.9      Uint32 last_volume_check;
    2.10      Uint32 rumble_expiration;
    2.11 @@ -297,6 +298,12 @@
    2.12          ctx->audio_supported = SDL_TRUE;
    2.13      }
    2.14  
    2.15 +    if (ctx->is_bluetooth) {
    2.16 +        ctx->rumble_supported = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, SDL_FALSE);
    2.17 +    } else {
    2.18 +        ctx->rumble_supported = SDL_TRUE;
    2.19 +    }
    2.20 +
    2.21      /* Initialize LED and effect state */
    2.22      HIDAPI_DriverPS4_Rumble(joystick, dev, ctx, 0, 0, 0);
    2.23  
    2.24 @@ -316,6 +323,10 @@
    2.25      Uint8 data[78];
    2.26      int report_size, offset;
    2.27  
    2.28 +    if (!ctx->rumble_supported) {
    2.29 +        return SDL_Unsupported();
    2.30 +    }
    2.31 +
    2.32      /* In order to send rumble, we have to send a complete effect packet */
    2.33      SDL_memset(data, 0, sizeof(data));
    2.34  
    2.35 @@ -517,7 +528,7 @@
    2.36          }
    2.37      }
    2.38  
    2.39 -	return (size >= 0);
    2.40 +    return (size >= 0);
    2.41  }
    2.42  
    2.43  static void