Added a hint to control whether the player LEDs should be lit to indicate which player is associated with a PS5 controller.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 80b572b..a20fe6d 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -646,6 +646,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.
*
* This variable can be set to the following values:
diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c
index 3f21740..0248c86 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps5.c
@@ -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;