Skip to content

Commit 3951cae

Browse files
committed
Ignore the PS4 packet CRC if it's not being set correctly
This fixes handling the 8BitDo SN30 Pro with the 2.00 firmware in PS4 mode Fixes #7270
1 parent f1d9c36 commit 3951cae

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/joystick/hidapi/SDL_hidapi_ps4.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ typedef struct
147147
Uint8 led_blue;
148148
Uint64 sensor_ticks;
149149
Uint16 last_tick;
150+
Uint16 valid_crc_packets; /* wrapping counter */
150151
PS4StatePacket_t last_state;
151152
} SDL_DriverPS4_Context;
152153

@@ -1026,7 +1027,18 @@ static SDL_bool HIDAPI_DriverPS4_IsPacketValid(SDL_DriverPS4_Context *ctx, Uint8
10261027
case k_EPS4ReportIdBluetoothState8:
10271028
case k_EPS4ReportIdBluetoothState9:
10281029
/* Bluetooth state packets have two additional bytes at the beginning, the first notes if HID data is present */
1029-
if (size >= 78 && (data[1] & 0x80) && VerifyCRC(data, 78)) {
1030+
if (size >= 78 && (data[1] & 0x80)) {
1031+
if (VerifyCRC(data, 78)) {
1032+
++ctx->valid_crc_packets;
1033+
} else {
1034+
if (ctx->valid_crc_packets > 0) {
1035+
--ctx->valid_crc_packets;
1036+
}
1037+
if (ctx->valid_crc_packets >= 3) {
1038+
/* We're generally getting valid CRC, but failed one */
1039+
return SDL_FALSE;
1040+
}
1041+
}
10301042
return SDL_TRUE;
10311043
}
10321044
break;

0 commit comments

Comments
 (0)