Separated PS4/PS5 effects support into individual capabilities
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c
index d5b3d29..04c3d40 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps4.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps4.c
@@ -126,9 +126,11 @@ typedef struct {
SDL_bool is_dongle;
SDL_bool is_bluetooth;
SDL_bool official_controller;
- SDL_bool effects_supported;
SDL_bool sensors_supported;
+ SDL_bool lightbar_supported;
+ SDL_bool vibration_supported;
SDL_bool touchpad_supported;
+ SDL_bool effects_supported;
SDL_bool enhanced_mode;
SDL_bool report_sensors;
SDL_bool report_touchpad;
@@ -306,8 +308,9 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
/* Get the device capabilities */
if (device->vendor_id == USB_VENDOR_SONY) {
- ctx->effects_supported = SDL_TRUE;
ctx->sensors_supported = SDL_TRUE;
+ ctx->lightbar_supported = SDL_TRUE;
+ ctx->vibration_supported = SDL_TRUE;
ctx->touchpad_supported = SDL_TRUE;
} else if ((size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
data[2] == 0x27) {
@@ -316,20 +319,24 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
#ifdef DEBUG_PS4_PROTOCOL
HIDAPI_DumpPacket("PS4 capabilities: size = %d", data, size);
#endif
- if ((capabilities & 0x0C) != 0) {
- ctx->effects_supported = SDL_TRUE;
- }
if ((capabilities & 0x02) != 0) {
ctx->sensors_supported = SDL_TRUE;
}
+ if ((capabilities & 0x04) != 0) {
+ ctx->lightbar_supported = SDL_TRUE;
+ }
+ if ((capabilities & 0x08) != 0) {
+ ctx->vibration_supported = SDL_TRUE;
+ }
if ((capabilities & 0x40) != 0) {
ctx->touchpad_supported = SDL_TRUE;
}
} else if (device->vendor_id == USB_VENDOR_RAZER) {
/* The Razer Raiju doesn't respond to the detection protocol, but has a touchpad and vibration */
- ctx->effects_supported = SDL_TRUE;
+ ctx->vibration_supported = SDL_TRUE;
ctx->touchpad_supported = SDL_TRUE;
}
+ ctx->effects_supported = (ctx->lightbar_supported || ctx->vibration_supported);
device->type = SDL_CONTROLLER_TYPE_PS4;
if (device->vendor_id == USB_VENDOR_SONY) {
@@ -516,22 +523,26 @@ HIDAPI_DriverPS4_UpdateEffects(SDL_HIDAPI_Device *device)
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
DS4EffectsState_t effects;
- if (!ctx->enhanced_mode) {
+ if (!ctx->enhanced_mode || !ctx->effects_supported) {
return SDL_Unsupported();
}
SDL_zero(effects);
- effects.ucRumbleLeft = ctx->rumble_left;
- effects.ucRumbleRight = ctx->rumble_right;
+ if (ctx->vibration_supported) {
+ effects.ucRumbleLeft = ctx->rumble_left;
+ effects.ucRumbleRight = ctx->rumble_right;
+ }
- /* Populate the LED state with the appropriate color from our lookup table */
- if (ctx->color_set) {
- effects.ucLedRed = ctx->led_red;
- effects.ucLedGreen = ctx->led_green;
- effects.ucLedBlue = ctx->led_blue;
- } else {
- SetLedsForPlayerIndex(&effects, ctx->player_index);
+ if (ctx->lightbar_supported) {
+ /* Populate the LED state with the appropriate color from our lookup table */
+ if (ctx->color_set) {
+ effects.ucLedRed = ctx->led_red;
+ effects.ucLedGreen = ctx->led_green;
+ effects.ucLedBlue = ctx->led_blue;
+ } else {
+ SetLedsForPlayerIndex(&effects, ctx->player_index);
+ }
}
return HIDAPI_DriverPS4_SendJoystickEffect(device, ctx->joystick, &effects, sizeof(effects));
}
@@ -634,6 +645,10 @@ HIDAPI_DriverPS4_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
{
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
+ if (!ctx->vibration_supported) {
+ return SDL_Unsupported();
+ }
+
ctx->rumble_left = (low_frequency_rumble >> 8);
ctx->rumble_right = (high_frequency_rumble >> 8);
@@ -652,8 +667,13 @@ HIDAPI_DriverPS4_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
Uint32 result = 0;
- if (ctx->enhanced_mode && ctx->effects_supported) {
- result |= SDL_JOYCAP_LED | SDL_JOYCAP_RUMBLE;
+ if (ctx->enhanced_mode) {
+ if (ctx->lightbar_supported) {
+ result |= SDL_JOYCAP_LED;
+ }
+ if (ctx->vibration_supported) {
+ result |= SDL_JOYCAP_RUMBLE;
+ }
}
return result;
@@ -664,6 +684,10 @@ HIDAPI_DriverPS4_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
{
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
+ if (!ctx->lightbar_supported) {
+ return SDL_Unsupported();
+ }
+
ctx->color_set = SDL_TRUE;
ctx->led_red = red;
ctx->led_green = green;
diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c
index 1508d4e..6f26c3b 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps5.c
@@ -200,9 +200,12 @@ typedef struct {
SDL_Joystick *joystick;
SDL_bool is_bluetooth;
SDL_bool use_alternate_report;
- SDL_bool effects_supported;
SDL_bool sensors_supported;
+ SDL_bool lightbar_supported;
+ SDL_bool vibration_supported;
+ SDL_bool playerled_supported;
SDL_bool touchpad_supported;
+ SDL_bool effects_supported;
SDL_bool enhanced_mode;
SDL_bool report_sensors;
SDL_bool report_touchpad;
@@ -410,28 +413,38 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
/* Get the device capabilities */
if (device->vendor_id == USB_VENDOR_SONY) {
- ctx->effects_supported = SDL_TRUE;
ctx->sensors_supported = SDL_TRUE;
+ ctx->lightbar_supported = SDL_TRUE;
+ ctx->vibration_supported = SDL_TRUE;
+ ctx->playerled_supported = SDL_TRUE;
ctx->touchpad_supported = SDL_TRUE;
} else if ((size = ReadFeatureReport(device->dev, k_EPS5FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
data[2] == 0x28) {
Uint8 capabilities = data[4];
+ Uint8 capabilities2 = data[20];
#ifdef DEBUG_PS5_PROTOCOL
HIDAPI_DumpPacket("PS5 capabilities: size = %d", data, size);
#endif
- if ((capabilities & 0x0C) != 0) {
- ctx->effects_supported = SDL_TRUE;
- }
if ((capabilities & 0x02) != 0) {
ctx->sensors_supported = SDL_TRUE;
}
+ if ((capabilities & 0x04) != 0) {
+ ctx->lightbar_supported = SDL_TRUE;
+ }
+ if ((capabilities & 0x08) != 0) {
+ ctx->vibration_supported = SDL_TRUE;
+ }
if ((capabilities & 0x40) != 0) {
ctx->touchpad_supported = SDL_TRUE;
}
+ if ((capabilities2 & 0x80) != 0) {
+ ctx->playerled_supported = SDL_TRUE;
+ }
ctx->use_alternate_report = SDL_TRUE;
}
+ ctx->effects_supported = (ctx->lightbar_supported || ctx->vibration_supported || ctx->playerled_supported);
device->type = SDL_CONTROLLER_TYPE_PS5;
if (device->vendor_id == USB_VENDOR_SONY) {
@@ -571,7 +584,7 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, int effect_mask)
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
DS5EffectsState_t effects;
- if (!ctx->enhanced_mode) {
+ if (!ctx->enhanced_mode || !ctx->effects_supported) {
return SDL_Unsupported();
}
@@ -586,52 +599,58 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, int effect_mask)
}
}
- if (ctx->rumble_left || ctx->rumble_right) {
- if (ctx->firmware_version < 0x0224) {
- effects.ucEnableBits1 |= 0x01; /* Enable rumble emulation */
+ if (ctx->vibration_supported) {
+ if (ctx->rumble_left || ctx->rumble_right) {
+ if (ctx->firmware_version < 0x0224) {
+ effects.ucEnableBits1 |= 0x01; /* Enable rumble emulation */
- /* Shift to reduce effective rumble strength to match Xbox controllers */
- effects.ucRumbleLeft = ctx->rumble_left >> 1;
- effects.ucRumbleRight = ctx->rumble_right >> 1;
- } else {
- effects.ucEnableBits3 |= 0x04; /* Enable improved rumble emulation on 2.24 firmware and newer */
+ /* Shift to reduce effective rumble strength to match Xbox controllers */
+ effects.ucRumbleLeft = ctx->rumble_left >> 1;
+ effects.ucRumbleRight = ctx->rumble_right >> 1;
+ } else {
+ effects.ucEnableBits3 |= 0x04; /* Enable improved rumble emulation on 2.24 firmware and newer */
- effects.ucRumbleLeft = ctx->rumble_left;
- effects.ucRumbleRight = ctx->rumble_right;
+ effects.ucRumbleLeft = ctx->rumble_left;
+ effects.ucRumbleRight = ctx->rumble_right;
+ }
+ effects.ucEnableBits1 |= 0x02; /* Disable audio haptics */
+ } else {
+ /* Leaving emulated rumble bits off will restore audio haptics */
}
- effects.ucEnableBits1 |= 0x02; /* Disable audio haptics */
- } else {
- /* Leaving emulated rumble bits off will restore audio haptics */
- }
- if ((effect_mask & k_EDS5EffectRumbleStart) != 0) {
- effects.ucEnableBits1 |= 0x02; /* Disable audio haptics */
- }
- if ((effect_mask & k_EDS5EffectRumble) != 0) {
- /* Already handled above */
- }
- if ((effect_mask & k_EDS5EffectLEDReset) != 0) {
- effects.ucEnableBits2 |= 0x08; /* Reset LED state */
+ if ((effect_mask & k_EDS5EffectRumbleStart) != 0) {
+ effects.ucEnableBits1 |= 0x02; /* Disable audio haptics */
+ }
+ if ((effect_mask & k_EDS5EffectRumble) != 0) {
+ /* Already handled above */
+ }
}
- if ((effect_mask & k_EDS5EffectLED) != 0) {
- effects.ucEnableBits2 |= 0x04; /* Enable LED color */
-
- /* Populate the LED state with the appropriate color from our lookup table */
- if (ctx->color_set) {
- effects.ucLedRed = ctx->led_red;
- effects.ucLedGreen = ctx->led_green;
- effects.ucLedBlue = ctx->led_blue;
- } else {
- SetLedsForPlayerIndex(&effects, ctx->player_index);
+ if (ctx->lightbar_supported) {
+ if ((effect_mask & k_EDS5EffectLEDReset) != 0) {
+ effects.ucEnableBits2 |= 0x08; /* Reset LED state */
+ }
+ if ((effect_mask & k_EDS5EffectLED) != 0) {
+ effects.ucEnableBits2 |= 0x04; /* Enable LED color */
+
+ /* Populate the LED state with the appropriate color from our lookup table */
+ if (ctx->color_set) {
+ effects.ucLedRed = ctx->led_red;
+ effects.ucLedGreen = ctx->led_green;
+ effects.ucLedBlue = ctx->led_blue;
+ } else {
+ SetLedsForPlayerIndex(&effects, ctx->player_index);
+ }
}
}
- if ((effect_mask & k_EDS5EffectPadLights) != 0) {
- effects.ucEnableBits2 |= 0x10; /* Enable touchpad lights */
+ if (ctx->playerled_supported) {
+ if ((effect_mask & k_EDS5EffectPadLights) != 0) {
+ effects.ucEnableBits2 |= 0x10; /* Enable touchpad lights */
- if (ctx->player_lights) {
- SetLightsForPlayerIndex(&effects, ctx->player_index);
- } else {
- effects.ucPadLights = 0x00;
+ if (ctx->player_lights) {
+ SetLightsForPlayerIndex(&effects, ctx->player_index);
+ } else {
+ effects.ucPadLights = 0x00;
+ }
}
}
if ((effect_mask & k_EDS5EffectMicLight) != 0) {
@@ -795,6 +814,10 @@ HIDAPI_DriverPS5_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
{
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
+ if (!ctx->vibration_supported) {
+ return SDL_Unsupported();
+ }
+
if (!ctx->rumble_left && !ctx->rumble_right) {
HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectRumbleStart);
}
@@ -817,8 +840,13 @@ HIDAPI_DriverPS5_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
Uint32 result = 0;
- if (ctx->enhanced_mode && ctx->effects_supported) {
- result |= SDL_JOYCAP_LED | SDL_JOYCAP_RUMBLE;
+ if (ctx->enhanced_mode) {
+ if (ctx->lightbar_supported) {
+ result |= SDL_JOYCAP_LED;
+ }
+ if (ctx->vibration_supported) {
+ result |= SDL_JOYCAP_RUMBLE;
+ }
}
return result;
@@ -829,6 +857,10 @@ HIDAPI_DriverPS5_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
{
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
+ if (!ctx->lightbar_supported) {
+ return SDL_Unsupported();
+ }
+
ctx->color_set = SDL_TRUE;
ctx->led_red = red;
ctx->led_green = green;