input: log hid_get_feature_report return values

This commit is contained in:
Megamouse 2021-10-01 01:47:14 +02:00
parent e5793acd78
commit 7df7ac57cc
3 changed files with 40 additions and 28 deletions

View file

@ -382,9 +382,9 @@ bool ds4_pad_handler::GetCalibrationData(DS4Device* ds4Dev) const
{
buf[0] = 0x05;
if (hid_get_feature_report(ds4Dev->hidDevice, buf.data(), DS4_FEATURE_REPORT_0x05_SIZE) <= 0)
if (int res = hid_get_feature_report(ds4Dev->hidDevice, buf.data(), DS4_FEATURE_REPORT_0x05_SIZE); res <= 0)
{
ds4_log.error("GetCalibrationData: hid_get_feature_report 0x05 failed! Reason: %s", hid_error(ds4Dev->hidDevice));
ds4_log.error("GetCalibrationData: hid_get_feature_report 0x05 for bluetooth controller failed! result=%d, error=%s", res, hid_error(ds4Dev->hidDevice));
return false;
}
@ -408,9 +408,9 @@ bool ds4_pad_handler::GetCalibrationData(DS4Device* ds4Dev) const
else
{
buf[0] = 0x02;
if (hid_get_feature_report(ds4Dev->hidDevice, buf.data(), DS4_FEATURE_REPORT_0x02_SIZE) <= 0)
if (int res = hid_get_feature_report(ds4Dev->hidDevice, buf.data(), DS4_FEATURE_REPORT_0x02_SIZE); res <= 0)
{
ds4_log.error("GetCalibrationData: hid_get_feature_report 0x02 failed! Reason: %s", hid_error(ds4Dev->hidDevice));
ds4_log.error("GetCalibrationData: hid_get_feature_report 0x02 for wired controller failed! result=%d, error=%s", res, hid_error(ds4Dev->hidDevice));
return false;
}
}
@ -527,12 +527,13 @@ void ds4_pad_handler::check_add_device(hid_device* hidDevice, std::string_view p
std::string serial;
// There isnt a nice 'portable' way with hidapi to detect bt vs wired as the pid/vid's are the same
// Let's try getting 0x81 feature report, which should will return mac address on wired, and should error on bluetooth
// Let's try getting 0x81 feature report, which should return the mac address on wired, and should an error on bluetooth
std::array<u8, 64> buf{};
buf[0] = 0x81;
if (const auto bytes_read = hid_get_feature_report(hidDevice, buf.data(), DS4_FEATURE_REPORT_0x81_SIZE); bytes_read > 0)
int res = hid_get_feature_report(hidDevice, buf.data(), DS4_FEATURE_REPORT_0x81_SIZE);
if (res > 0)
{
if (bytes_read != DS4_FEATURE_REPORT_0x81_SIZE)
if (res != DS4_FEATURE_REPORT_0x81_SIZE)
{
// Controller may not be genuine. These controllers do not have feature 0x81 implemented and calibration data is in bluetooth format even in USB mode!
ds4_log.warning("check_add_device: DS4 controller may not be genuine. Workaround enabled.");
@ -540,9 +541,9 @@ void ds4_pad_handler::check_add_device(hid_device* hidDevice, std::string_view p
// Read feature report 0x12 instead which is what the console uses.
buf[0] = 0x12;
buf[1] = 0;
if (hid_get_feature_report(hidDevice, buf.data(), DS4_FEATURE_REPORT_0x12_SIZE) == -1)
if (res = hid_get_feature_report(hidDevice, buf.data(), DS4_FEATURE_REPORT_0x12_SIZE); res < 0)
{
ds4_log.error("check_add_device: hid_get_feature_report 0x12 failed! Reason: %s", hid_error(hidDevice));
ds4_log.error("check_add_device: hid_get_feature_report 0x12 failed! result=%d, error=%s", res, hid_error(hidDevice));
}
}
@ -550,6 +551,7 @@ void ds4_pad_handler::check_add_device(hid_device* hidDevice, std::string_view p
}
else
{
ds4_log.warning("check_add_device: DS4 Bluetooth controller detected. (hid_get_feature_report 0x81 failed, result=%d, error=%s)", res, hid_error(hidDevice));
device->bt_controller = true;
for (wchar_t ch : wide_serial)
serial += static_cast<uchar>(ch);
@ -676,9 +678,9 @@ ds4_pad_handler::DataStatus ds4_pad_handler::get_data(DS4Device* device)
// tells controller to send 0x11 reports
std::array<u8, 64> buf_error{};
buf_error[0] = 0x2;
if (hid_get_feature_report(device->hidDevice, buf_error.data(), buf_error.size()) == -1)
if (int res = hid_get_feature_report(device->hidDevice, buf_error.data(), buf_error.size()); res < 0)
{
ds4_log.error("GetRawData: hid_get_feature_report 0x2 failed! Reason: %s", hid_error(device->hidDevice));
ds4_log.error("GetRawData: hid_get_feature_report 0x2 failed! result=%d, error=%s", res, hid_error(device->hidDevice));
}
return DataStatus::NoNewData;
}