From 7df7ac57cc28f0be5ca7ee7fa609a732cab3082b Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 1 Oct 2021 01:47:14 +0200 Subject: [PATCH] input: log hid_get_feature_report return values --- rpcs3/Input/ds3_pad_handler.cpp | 19 +++++++++---------- rpcs3/Input/ds4_pad_handler.cpp | 24 +++++++++++++----------- rpcs3/Input/dualsense_pad_handler.cpp | 25 ++++++++++++++++++------- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/rpcs3/Input/ds3_pad_handler.cpp b/rpcs3/Input/ds3_pad_handler.cpp index 710ff45ff7..cc1aa85d10 100644 --- a/rpcs3/Input/ds3_pad_handler.cpp +++ b/rpcs3/Input/ds3_pad_handler.cpp @@ -279,25 +279,24 @@ void ds3_pad_handler::check_add_device(hid_device* hidDevice, std::string_view p u8 buf[0xFF]; buf[0] = 0xF2; - bool got_report = hid_get_feature_report(hidDevice, buf, 0xFF) >= 0; - if (!got_report) + int res = hid_get_feature_report(hidDevice, buf, 0xFF); + if (res < 0) { - buf[0] = 0; - got_report = hid_get_feature_report(hidDevice, buf, 0xFF) >= 0; + ds3_log.warning("check_add_device: hid_get_feature_report 0xF2 failed! Trying again with 0x0. (result=%d, error=%s)", res, hid_error(hidDevice)); + buf[0] = 0; + res = hid_get_feature_report(hidDevice, buf, 0xFF); } - if (!got_report) + if (res < 0) { - ds3_log.error("check_add_device: hid_get_feature_report failed! Reason: %s", hid_error(hidDevice)); + ds3_log.error("check_add_device: hid_get_feature_report 0x0 failed! result=%d, error=%s", res, hid_error(hidDevice)); hid_close(hidDevice); return; } device->report_id = buf[0]; #endif - { - for (wchar_t ch : wide_serial) - serial += static_cast(ch); - } + for (wchar_t ch : wide_serial) + serial += static_cast(ch); if (hid_set_nonblocking(hidDevice, 1) == -1) { diff --git a/rpcs3/Input/ds4_pad_handler.cpp b/rpcs3/Input/ds4_pad_handler.cpp index 6098976e34..85ea745613 100644 --- a/rpcs3/Input/ds4_pad_handler.cpp +++ b/rpcs3/Input/ds4_pad_handler.cpp @@ -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 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(ch); @@ -676,9 +678,9 @@ ds4_pad_handler::DataStatus ds4_pad_handler::get_data(DS4Device* device) // tells controller to send 0x11 reports std::array 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; } diff --git a/rpcs3/Input/dualsense_pad_handler.cpp b/rpcs3/Input/dualsense_pad_handler.cpp index c9383a363d..241b4f8aba 100644 --- a/rpcs3/Input/dualsense_pad_handler.cpp +++ b/rpcs3/Input/dualsense_pad_handler.cpp @@ -182,7 +182,14 @@ void dualsense_pad_handler::check_add_device(hid_device* hidDevice, std::string_ // 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. - if (hid_get_feature_report(hidDevice, buf.data(), 64) == 21) + int res = hid_get_feature_report(hidDevice, buf.data(), 64); + if (res < 0) + { + dualsense_log.error("check_add_device: hid_get_feature_report 0x09 failed! result=%d, error=%s", res, hid_error(hidDevice)); + return; + } + + if (res == 21) { serial = fmt::format("%x%x%x%x%x%x", buf[6], buf[5], buf[4], buf[3], buf[2], buf[1]); device->data_mode = DualSenseDevice::DualSenseDataMode::Enhanced; @@ -191,6 +198,8 @@ void dualsense_pad_handler::check_add_device(hid_device* hidDevice, std::string_ { // We're probably on Bluetooth in this case, but for whatever reason the feature report failed. // This will give us a less capable fallback. + dualsense_log.warning("check_add_device: hid_get_feature_report returned wrong size! Falling back to simple mode. (result=%d)", res); + device->data_mode = DualSenseDevice::DualSenseDataMode::Simple; for (wchar_t ch : wide_serial) serial += static_cast(ch); @@ -210,14 +219,16 @@ void dualsense_pad_handler::check_add_device(hid_device* hidDevice, std::string_ u32 fw_version{}; buf[0] = 0x20; - if (hid_get_feature_report(hidDevice, buf.data(), 64) == 65) + + res = hid_get_feature_report(hidDevice, buf.data(), 64); + if (res == 65) { hw_version = read_u32(&buf[24]); fw_version = read_u32(&buf[28]); } else { - dualsense_log.error("Could not retrieve firmware version"); + 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)); } if (hid_set_nonblocking(hidDevice, 1) == -1) @@ -413,9 +424,9 @@ bool dualsense_pad_handler::get_calibration_data(DualSenseDevice* dualsense_devi { buf[0] = 0x05; - if (hid_get_feature_report(dualsense_device->hidDevice, buf.data(), DUALSENSE_CALIBRATION_REPORT_SIZE) <= 0) + if (int res = hid_get_feature_report(dualsense_device->hidDevice, buf.data(), DUALSENSE_CALIBRATION_REPORT_SIZE); res <= 0) { - dualsense_log.error("get_calibration_data: hid_get_feature_report 0x05 failed! Reason: %s", hid_error(dualsense_device->hidDevice)); + 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)); return false; } @@ -440,9 +451,9 @@ bool dualsense_pad_handler::get_calibration_data(DualSenseDevice* dualsense_devi { buf[0] = 0x05; - if (hid_get_feature_report(dualsense_device->hidDevice, buf.data(), DUALSENSE_CALIBRATION_REPORT_SIZE) <= 0) + if (int res = hid_get_feature_report(dualsense_device->hidDevice, buf.data(), DUALSENSE_CALIBRATION_REPORT_SIZE); res <= 0) { - dualsense_log.error("get_calibration_data: hid_get_feature_report 0x05 failed! Reason: %s", hid_error(dualsense_device->hidDevice)); + 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)); return false; } }