Added a hint to control whether the player LEDs should be lit to indicate which player is associated with a PS5 controller.

This commit is contained in:
Sam Lantinga 2020-12-29 12:13:10 -08:00
parent 6116ccf035
commit 0684572ccc
2 changed files with 33 additions and 1 deletions

View File

@ -645,6 +645,15 @@ extern "C" {
*/
#define SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE "SDL_JOYSTICK_HIDAPI_PS5_RUMBLE"
/**
* \brief A variable controlling whether the player LEDs should be lit to indicate which player is associated with a PS5 controller.
*
* This variable can be set to the following values:
* "0" - player LEDs are not enabled
* "1" - player LEDs are enabled (the default)
*/
#define SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED "SDL_JOYSTICK_HIDAPI_PS5_PLAYER_LED"
/**
* \brief A variable controlling whether the HIDAPI driver for Steam Controllers should be used.
*

View File

@ -159,6 +159,7 @@ typedef struct {
IMUCalibrationData calibration[6];
Uint32 last_packet;
int player_index;
SDL_bool player_lights;
Uint8 rumble_left;
Uint8 rumble_right;
SDL_bool color_set;
@ -445,7 +446,11 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, int effect_mask)
if ((effect_mask & k_EDS5EffectPadLights) != 0) {
effects->ucEnableBits2 |= 0x10; /* Enable touchpad lights */
SetLightsForPlayerIndex(effects, ctx->player_index);
if (ctx->player_lights) {
SetLightsForPlayerIndex(effects, ctx->player_index);
} else {
effects->ucPadLights = 0x00;
}
}
if ((effect_mask & k_EDS5EffectMicLight) != 0) {
effects->ucEnableBits2 |= 0x01; /* Enable microphone light */
@ -547,6 +552,18 @@ static void SDLCALL SDL_PS5RumbleHintChanged(void *userdata, const char *name, c
}
}
static void SDLCALL SDL_PS5PlayerLEDHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)userdata;
SDL_bool player_lights = SDL_GetStringBoolean(hint, SDL_TRUE);
if (player_lights != ctx->player_lights) {
ctx->player_lights = player_lights;
HIDAPI_DriverPS5_UpdateEffects(ctx->device, k_EDS5EffectPadLights);
}
}
static void
HIDAPI_DriverPS5_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
{
@ -641,6 +658,7 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
/* Initialize player index (needed for setting LEDs) */
ctx->player_index = SDL_JoystickGetPlayerIndex(joystick);
ctx->player_lights = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED, SDL_TRUE);
/* Initialize the joystick capabilities
*
@ -656,6 +674,8 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE,
SDL_PS5RumbleHintChanged, ctx);
}
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED,
SDL_PS5PlayerLEDHintChanged, ctx);
return SDL_TRUE;
}
@ -1022,6 +1042,9 @@ HIDAPI_DriverPS5_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick
SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE,
SDL_PS5RumbleHintChanged, ctx);
SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED,
SDL_PS5PlayerLEDHintChanged, ctx);
hid_close(device->dev);
device->dev = NULL;