mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-05 06:26:49 +00:00
HID: properly check return values and report IDs
This commit is contained in:
parent
4912202cfa
commit
09875a5180
3 changed files with 41 additions and 40 deletions
|
|
@ -176,16 +176,16 @@ void dualsense_pad_handler::check_add_device(hid_device* hidDevice, std::string_
|
|||
|
||||
std::string serial;
|
||||
|
||||
std::array<u8, 65> buf{};
|
||||
std::array<u8, 64> buf{};
|
||||
buf[0] = 0x09;
|
||||
|
||||
// This will give us the bluetooth mac address of the device, regardless if we are on wired or bluetooth.
|
||||
// So we can't use this to determine if it is a bluetooth device or not.
|
||||
// Will also enable enhanced feature reports for bluetooth.
|
||||
int res = hid_get_feature_report(hidDevice, buf.data(), 64);
|
||||
if (res < 0)
|
||||
int res = hid_get_feature_report(hidDevice, buf.data(), buf.size());
|
||||
if (res < 0 || buf[0] != 0x09)
|
||||
{
|
||||
dualsense_log.error("check_add_device: hid_get_feature_report 0x09 failed! result=%d, error=%s", res, hid_error(hidDevice));
|
||||
dualsense_log.error("check_add_device: hid_get_feature_report 0x09 failed! result=%d, buf[0]=0x%x, error=%s", res, buf[0], hid_error(hidDevice));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -222,14 +222,14 @@ void dualsense_pad_handler::check_add_device(hid_device* hidDevice, std::string_
|
|||
buf[0] = 0x20;
|
||||
|
||||
res = hid_get_feature_report(hidDevice, buf.data(), DUALSENSE_VERSION_REPORT_SIZE);
|
||||
if (res > 0) // Old versions return 65, newer versions return 64
|
||||
if (res != DUALSENSE_VERSION_REPORT_SIZE || buf[0] != 0x20) // Old versions return 65, newer versions return 64
|
||||
{
|
||||
hw_version = read_u32(&buf[24]);
|
||||
fw_version = read_u32(&buf[28]);
|
||||
dualsense_log.error("check_add_device: hid_get_feature_report 0x20 failed! Could not retrieve firmware version! result=%d, buf[0]=0x%x, error=%s", res, buf[0], hid_error(hidDevice));
|
||||
}
|
||||
else
|
||||
{
|
||||
dualsense_log.error("check_add_device: hid_get_feature_report 0x20 failed! Could not retrieve firmware version! result=%d, error=%s", res, hid_error(hidDevice));
|
||||
hw_version = read_u32(&buf[24]);
|
||||
fw_version = read_u32(&buf[28]);
|
||||
}
|
||||
|
||||
if (hid_set_nonblocking(hidDevice, 1) == -1)
|
||||
|
|
@ -427,9 +427,9 @@ bool dualsense_pad_handler::get_calibration_data(DualSenseDevice* dualsense_devi
|
|||
buf = {};
|
||||
buf[0] = 0x05;
|
||||
|
||||
if (int res = hid_get_feature_report(dualsense_device->hidDevice, buf.data(), DUALSENSE_CALIBRATION_REPORT_SIZE); res <= 0)
|
||||
if (int res = hid_get_feature_report(dualsense_device->hidDevice, buf.data(), DUALSENSE_CALIBRATION_REPORT_SIZE); res != DUALSENSE_CALIBRATION_REPORT_SIZE || buf[0] != 0x05)
|
||||
{
|
||||
dualsense_log.error("get_calibration_data: hid_get_feature_report 0x05 for bluetooth controller failed! result=%d, error=%s", res, hid_error(dualsense_device->hidDevice));
|
||||
dualsense_log.error("get_calibration_data: hid_get_feature_report 0x05 for bluetooth controller failed! result=%d, buf[0]=0x%x, error=%s", res, buf[0], hid_error(dualsense_device->hidDevice));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -454,9 +454,9 @@ bool dualsense_pad_handler::get_calibration_data(DualSenseDevice* dualsense_devi
|
|||
{
|
||||
buf[0] = 0x05;
|
||||
|
||||
if (int res = hid_get_feature_report(dualsense_device->hidDevice, buf.data(), DUALSENSE_CALIBRATION_REPORT_SIZE); res <= 0)
|
||||
if (int res = hid_get_feature_report(dualsense_device->hidDevice, buf.data(), DUALSENSE_CALIBRATION_REPORT_SIZE); res != DUALSENSE_CALIBRATION_REPORT_SIZE || buf[0] != 0x05)
|
||||
{
|
||||
dualsense_log.error("get_calibration_data: hid_get_feature_report 0x05 for wired controller failed! result=%d, error=%s", res, hid_error(dualsense_device->hidDevice));
|
||||
dualsense_log.error("get_calibration_data: hid_get_feature_report 0x05 for wired controller failed! result=%d, buf[0]=0x%x, error=%s", res, buf[0], hid_error(dualsense_device->hidDevice));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue