Skip to content

Commit ed2cdce

Browse files
endriftslouken
authored andcommitted
switch2: Read user calibration data
1 parent f3a9f66 commit ed2cdce

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

src/joystick/hidapi/SDL_hidapi_switch2.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,25 +355,24 @@ static bool HIDAPI_DriverSwitch2_InitUSB(SDL_HIDAPI_Device *device)
355355
flash_read_command[12] = 0x80;
356356
res = SendBulkData(ctx, flash_read_command, sizeof(flash_read_command));
357357
if (res < 0) {
358-
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't request calibration data: %d", res);
358+
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't request factory calibration data: %d", res);
359359
} else {
360360
res = RecvBulkData(ctx, calibration_data, sizeof(calibration_data));
361361
if (res < 0) {
362-
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read calibration data: %d", res);
362+
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read factory calibration data: %d", res);
363363
} else {
364364
ParseStickCalibration(&ctx->left_stick, &calibration_data[0x38]);
365365
}
366366
}
367367

368-
369368
flash_read_command[12] = 0xC0;
370369
res = SendBulkData(ctx, flash_read_command, sizeof(flash_read_command));
371370
if (res < 0) {
372-
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't request calibration data: %d", res);
371+
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't request factory calibration data: %d", res);
373372
} else {
374373
res = RecvBulkData(ctx, calibration_data, sizeof(calibration_data));
375374
if (res < 0) {
376-
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read calibration data: %d", res);
375+
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read factory calibration data: %d", res);
377376
} else {
378377
ParseStickCalibration(&ctx->right_stick, &calibration_data[0x38]);
379378
}
@@ -384,18 +383,46 @@ static bool HIDAPI_DriverSwitch2_InitUSB(SDL_HIDAPI_Device *device)
384383
flash_read_command[13] = 0x31;
385384
res = SendBulkData(ctx, flash_read_command, sizeof(flash_read_command));
386385
if (res < 0) {
387-
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read calibration data: %d", res);
386+
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't request factory calibration data: %d", res);
388387
} else {
389388
res = RecvBulkData(ctx, calibration_data, sizeof(calibration_data));
390389
if (res < 0) {
391-
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read calibration data: %d", res);
390+
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read factory calibration data: %d", res);
392391
} else {
393392
ctx->left_trigger_max = calibration_data[0x10];
394393
ctx->right_trigger_max = calibration_data[0x11];
395394
}
396395
}
397396
}
398397

398+
flash_read_command[12] = 0x40;
399+
flash_read_command[13] = 0xC0;
400+
flash_read_command[14] = 0x1F;
401+
res = SendBulkData(ctx, flash_read_command, sizeof(flash_read_command));
402+
if (res < 0) {
403+
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't request user calibration data: %d", res);
404+
} else {
405+
res = RecvBulkData(ctx, calibration_data, sizeof(calibration_data));
406+
if (res < 0) {
407+
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't request user calibration data: %d", res);
408+
} else if (calibration_data[0x10] == 0xb2 && calibration_data[0x11] == 0xa1) {
409+
ParseStickCalibration(&ctx->left_stick, &calibration_data[0x12]);
410+
}
411+
}
412+
413+
flash_read_command[12] = 0x80;
414+
res = SendBulkData(ctx, flash_read_command, sizeof(flash_read_command));
415+
if (res < 0) {
416+
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't request user calibration data: %d", res);
417+
} else {
418+
res = RecvBulkData(ctx, calibration_data, sizeof(calibration_data));
419+
if (res < 0) {
420+
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Couldn't read user calibration data: %d", res);
421+
} else if (calibration_data[0x10] == 0xb2 && calibration_data[0x11] == 0xa1) {
422+
ParseStickCalibration(&ctx->right_stick, &calibration_data[0x12]);
423+
}
424+
}
425+
399426
return true;
400427
}
401428

0 commit comments

Comments
 (0)