Skip to content

Commit 8d5bf05

Browse files
committed
Fixed detecting 8BitDo sensor timestamp on older firmware
Also updated the reported sensor rate over USB for new firmware
1 parent 0ac1241 commit 8d5bf05

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/joystick/hidapi/SDL_hidapi_8bitdo.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,17 @@ static bool HIDAPI_Driver8BitDo_InitDevice(SDL_HIDAPI_Device *device)
187187
for (int attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
188188
int size = ReadFeatureReport(device->dev, SDL_8BITDO_FEATURE_REPORTID_ENABLE_SDL_REPORTID, data, sizeof(data));
189189
if (size > 0) {
190+
#ifdef DEBUG_8BITDO_PROTOCOL
191+
HIDAPI_DumpPacket("8BitDo features packet: size = %d", data, size);
192+
#endif
190193
ctx->sensors_supported = true;
191194
ctx->rumble_supported = true;
192195
ctx->powerstate_supported = true;
193196

194-
if (data[13] == SDL_8BITDO_SENSOR_TIMESTAMP_ENABLE) {
197+
if (size >= 14 && data[13] == SDL_8BITDO_SENSOR_TIMESTAMP_ENABLE) {
195198
ctx->sensor_timestamp_supported = true;
196199
}
200+
197201
// Set the serial number to the Bluetooth MAC address
198202
if (size >= 12 && data[10] != 0) {
199203
char serial[18];
@@ -231,18 +235,36 @@ static void HIDAPI_Driver8BitDo_SetDevicePlayerIndex(SDL_HIDAPI_Device *device,
231235

232236
static Uint64 HIDAPI_Driver8BitDo_GetIMURateForProductID(SDL_HIDAPI_Device *device)
233237
{
238+
SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)device->context;
239+
234240
// TODO: If sensor time stamp is sent, these fixed settings from observation can be replaced
235241
switch (device->product_id) {
236-
// Note, This is estimated by observation of Bluetooth packets received in the testcontroller tool
237-
case USB_PRODUCT_8BITDO_SN30_PRO_BT:
238-
case USB_PRODUCT_8BITDO_SF30_PRO_BT:
239-
return 90; // Observed to be anywhere between 60-90 hz. Possibly lossy in current state
240242
case USB_PRODUCT_8BITDO_SF30_PRO:
243+
case USB_PRODUCT_8BITDO_SF30_PRO_BT:
241244
case USB_PRODUCT_8BITDO_SN30_PRO:
242-
return 100;
245+
case USB_PRODUCT_8BITDO_SN30_PRO_BT:
246+
if (device->is_bluetooth) {
247+
// Note, This is estimated by observation of Bluetooth packets received in the testcontroller tool
248+
return 70; // Observed to be anywhere between 60-90 hz. Possibly lossy in current state
249+
} else if (ctx->sensor_timestamp_supported) {
250+
// This firmware appears to update at 200 Hz over USB
251+
return 200;
252+
} else {
253+
// This firmware appears to update at 100 Hz over USB
254+
return 100;
255+
}
243256
case USB_PRODUCT_8BITDO_PRO_2:
244-
case USB_PRODUCT_8BITDO_PRO_2_BT:// Note, labelled as "BT" but appears this way when wired. Observed bluetooth packet rate seems to be 80-90hz
245-
return (device->is_bluetooth ? 85 : 100);
257+
case USB_PRODUCT_8BITDO_PRO_2_BT: // Note, labeled as "BT" but appears this way when wired.
258+
if (device->is_bluetooth) {
259+
// Note, This is estimated by observation of Bluetooth packets received in the testcontroller tool
260+
return 85; // Observed Bluetooth packet rate seems to be 80-90hz
261+
} else if (ctx->sensor_timestamp_supported) {
262+
// This firmware appears to update at 200 Hz over USB
263+
return 200;
264+
} else {
265+
// This firmware appears to update at 100 Hz over USB
266+
return 100;
267+
}
246268
case USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS:
247269
default:
248270
return 120;

0 commit comments

Comments
 (0)