From bd4f155bbbdc4be34505535e4bd936ae12671925 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 17 Jul 2023 17:08:17 -0700
Subject: [PATCH] Fixed LED pending check failing when the controller timestamp
is very large
In this case we know the controller has been on for a while and the Bluetooth connection LED cycle is complete.
Also fixed the timestamp being zero the first time it is checked
---
src/joystick/hidapi/SDL_hidapi_ps5.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c
index 4805f33aa635..a116c8fb7b81 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps5.c
@@ -722,7 +722,7 @@ static void HIDAPI_DriverPS5_CheckPendingLEDReset(SDL_HIDAPI_Device *device)
packet->rgucSensorTimestamp[1],
packet->rgucSensorTimestamp[2],
packet->rgucSensorTimestamp[3]);
- if ((Sint32)(connection_complete - timestamp) <= 0) {
+ if (timestamp >= connection_complete) {
led_reset_complete = SDL_TRUE;
}
} else {
@@ -1398,15 +1398,15 @@ static SDL_bool HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
/* This is the extended report, we can enable effects now */
HIDAPI_DriverPS5_SetEnhancedMode(device, joystick);
}
- if (ctx->led_reset_state == k_EDS5LEDResetStatePending) {
- HIDAPI_DriverPS5_CheckPendingLEDReset(device);
- }
HIDAPI_DriverPS5_HandleStatePacketCommon(joystick, device->dev, ctx, (PS5StatePacketCommon_t *)&data[2]);
if (ctx->use_alternate_report) {
HIDAPI_DriverPS5_HandleStatePacketAlt(joystick, device->dev, ctx, (PS5StatePacketAlt_t *)&data[2]);
} else {
HIDAPI_DriverPS5_HandleStatePacket(joystick, device->dev, ctx, (PS5StatePacket_t *)&data[2]);
}
+ if (ctx->led_reset_state == k_EDS5LEDResetStatePending) {
+ HIDAPI_DriverPS5_CheckPendingLEDReset(device);
+ }
break;
default:
#ifdef DEBUG_JOYSTICK