Set the pad lights on the PS5 controller corresponding to the player index Also allow setting the player index from testgamecontroller using the number keys
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
diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c
index 5d91ee2..dfd94a9 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps5.c
@@ -205,9 +205,9 @@ SetLedsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
{ 0x40, 0x00, 0x00 }, /* Red */
{ 0x00, 0x40, 0x00 }, /* Green */
{ 0x20, 0x00, 0x20 }, /* Pink */
- { 0x02, 0x01, 0x00 }, /* Orange */
- { 0x00, 0x01, 0x01 }, /* Teal */
- { 0x01, 0x01, 0x01 } /* White */
+ { 0x20, 0x10, 0x00 }, /* Orange */
+ { 0x00, 0x10, 0x10 }, /* Teal */
+ { 0x10, 0x10, 0x10 } /* White */
};
if (player_index >= 0) {
@@ -221,6 +221,24 @@ SetLedsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
effects->ucLedBlue = colors[player_index][2];
}
+static void
+SetLightsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
+{
+ static const Uint8 lights[] = {
+ 0x04,
+ 0x0A,
+ 0x15,
+ 0x1B
+ };
+
+ if (player_index >= 0 && player_index < SDL_arraysize(lights)) {
+ /* Bitmask, 0x1F enables all lights, 0x20 changes instantly instead of fade */
+ effects->ucPadLights = lights[player_index];
+ } else {
+ effects->ucPadLights = 0x00;
+ }
+}
+
static SDL_bool
HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
{
@@ -425,7 +443,7 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, EDS5Effect effect)
case k_EDS5EffectPadLights:
effects->ucEnableBits2 |= 0x10; /* Enable touchpad lights */
- effects->ucPadLights = 0x00; /* Bitmask, 0x1F enables all lights, 0x20 changes instantly instead of fade */
+ SetLightsForPlayerIndex(effects, ctx->player_index);
break;
case k_EDS5EffectMicLight:
effects->ucEnableBits2 |= 0x01; /* Enable microphone light */
@@ -498,6 +516,7 @@ HIDAPI_DriverPS5_SetEffectsSupported(SDL_HIDAPI_Device *device, SDL_Joystick *jo
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL);
HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectLED);
+ HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectPadLights);
}
static void
@@ -513,6 +532,7 @@ HIDAPI_DriverPS5_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID
/* This will set the new LED state based on the new player index */
HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectLED);
+ HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectPadLights);
}
static SDL_bool
diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c
index 6522885..0c0d3dc 100644
--- a/test/testgamecontroller.c
+++ b/test/testgamecontroller.c
@@ -303,6 +303,14 @@ loop(void *arg)
break;
case SDL_KEYDOWN:
+ if (event.key.keysym.sym >= SDLK_0 && event.key.keysym.sym <= SDLK_9) {
+ if (gamecontroller) {
+ int player_index = (event.key.keysym.sym - SDLK_0);
+
+ SDL_GameControllerSetPlayerIndex(gamecontroller, player_index);
+ }
+ break;
+ }
if (event.key.keysym.sym != SDLK_ESCAPE) {
break;
}