diff --git a/rpcs3/Input/ds3_pad_handler.cpp b/rpcs3/Input/ds3_pad_handler.cpp index d36af783ff..cdd1fc3fd7 100644 --- a/rpcs3/Input/ds3_pad_handler.cpp +++ b/rpcs3/Input/ds3_pad_handler.cpp @@ -248,28 +248,28 @@ ds3_pad_handler::DataStatus ds3_pad_handler::get_data(ds3_device* ds3dev) if (!ds3dev) return DataStatus::ReadError; - auto& dbuf = ds3dev->buf; + ds3dev->padData = {}; #ifdef _WIN32 - dbuf[0] = ds3dev->report_id; - const int result = hid_get_feature_report(ds3dev->hidDevice, dbuf, sizeof(dbuf)); + ds3dev->padData[0] = ds3dev->report_id; + const int result = hid_get_feature_report(ds3dev->hidDevice, ds3dev->padData.data(), 64); #else - const int result = hid_read(ds3dev->hidDevice, dbuf, sizeof(dbuf)); + const int result = hid_read(ds3dev->hidDevice, ds3dev->padData.data(), 64); #endif if (result > 0) { #ifdef _WIN32 - if (dbuf[0] == ds3dev->report_id) + if (ds3dev->padData[0] == ds3dev->report_id) #else - if (dbuf[0] == 0x01 && dbuf[1] != 0xFF) + if (ds3dev->padData[0] == 0x01 && ds3dev->padData[1] != 0xFF) #endif { return DataStatus::NewData; } else { - ds3_log.warning("Unknown packet received:0x%02x", dbuf[0]); + ds3_log.warning("Unknown packet received:0x%02x", ds3dev->padData[0]); return DataStatus::NoNewData; } } @@ -289,7 +289,7 @@ std::unordered_map ds3_pad_handler::get_button_values(const std::share if (!dev) return key_buf; - auto& dbuf = dev->buf; + auto& dbuf = dev->padData; const u8 lsx = dbuf[6 + DS3_HID_OFFSET]; const u8 lsy = dbuf[7 + DS3_HID_OFFSET]; @@ -358,14 +358,14 @@ void ds3_pad_handler::get_extended_info(const std::shared_ptr& device #ifdef _WIN32 // Official Sony Windows DS3 driver seems to do the same modification of this value as the ps3 - pad->m_sensors[0].m_value = *reinterpret_cast*>(&ds3dev->buf[41 + DS3_HID_OFFSET]); + pad->m_sensors[0].m_value = *reinterpret_cast*>(&ds3dev->padData[41 + DS3_HID_OFFSET]); #else // When getting raw values from the device this adjustement is needed - pad->m_sensors[0].m_value = 512 - (*reinterpret_cast*>(&ds3dev->buf[41]) - 512); + pad->m_sensors[0].m_value = 512 - (*reinterpret_cast*>(&ds3dev->padData[41]) - 512); #endif - pad->m_sensors[1].m_value = *reinterpret_cast*>(&ds3dev->buf[45 + DS3_HID_OFFSET]); - pad->m_sensors[2].m_value = *reinterpret_cast*>(&ds3dev->buf[43 + DS3_HID_OFFSET]); - pad->m_sensors[3].m_value = *reinterpret_cast*>(&ds3dev->buf[47 + DS3_HID_OFFSET]); + pad->m_sensors[1].m_value = *reinterpret_cast*>(&ds3dev->padData[45 + DS3_HID_OFFSET]); + pad->m_sensors[2].m_value = *reinterpret_cast*>(&ds3dev->padData[43 + DS3_HID_OFFSET]); + pad->m_sensors[3].m_value = *reinterpret_cast*>(&ds3dev->padData[47 + DS3_HID_OFFSET]); // Those are formulas used to adjust sensor values in sys_hid code but I couldn't find all the vars. //auto polish_value = [](s32 value, s32 dword_0x0, s32 dword_0x4, s32 dword_0x8, s32 dword_0xC, s32 dword_0x18, s32 dword_0x1C) -> u16 @@ -464,13 +464,27 @@ PadHandlerBase::connection ds3_pad_handler::update_connection(const std::shared_ void ds3_pad_handler::apply_pad_data(const std::shared_ptr& device, const std::shared_ptr& pad) { ds3_device* dev = static_cast(device.get()); - if (!dev || !dev->hidDevice || !pad) + if (!dev || !dev->hidDevice || !dev->config || !pad) return; - if (dev->large_motor != pad->m_vibrateMotors[0].m_value || dev->small_motor != pad->m_vibrateMotors[1].m_value) + pad_config* config = dev->config; + + const int idx_l = config->switch_vibration_motors ? 1 : 0; + const int idx_s = config->switch_vibration_motors ? 0 : 1; + + const int speed_large = config->enable_vibration_motor_large ? pad->m_vibrateMotors[idx_l].m_value : vibration_min; + const int speed_small = config->enable_vibration_motor_small ? pad->m_vibrateMotors[idx_s].m_value : vibration_min; + + dev->new_output_data |= dev->large_motor != speed_large || dev->small_motor != speed_small; + + dev->large_motor = speed_large; + dev->small_motor = speed_small; + + if (dev->new_output_data) { - dev->large_motor = static_cast(pad->m_vibrateMotors[0].m_value); - dev->small_motor = static_cast(pad->m_vibrateMotors[1].m_value); - send_output_report(dev); + if (send_output_report(dev) >= 0) + { + dev->new_output_data = false; + } } } diff --git a/rpcs3/Input/ds3_pad_handler.h b/rpcs3/Input/ds3_pad_handler.h index 2430516e54..604f154df3 100644 --- a/rpcs3/Input/ds3_pad_handler.h +++ b/rpcs3/Input/ds3_pad_handler.h @@ -7,7 +7,6 @@ class ds3_device : public HidDevice { public: - u8 buf[64]{0}; #ifdef _WIN32 u8 report_id = 0; #endif diff --git a/rpcs3/Input/ds4_pad_handler.cpp b/rpcs3/Input/ds4_pad_handler.cpp index 021c4546fa..9d82f2a37a 100644 --- a/rpcs3/Input/ds4_pad_handler.cpp +++ b/rpcs3/Input/ds4_pad_handler.cpp @@ -706,7 +706,6 @@ ds4_pad_handler::DataStatus ds4_pad_handler::get_data(DS4Device* device) return DataStatus::NoNewData; const int battery_offset = offset + DS4_INPUT_REPORT_BATTERY_OFFSET; - device->is_initialized = true; device->cableState = (buf[battery_offset] >> 4) & 0x01; device->batteryLevel = buf[battery_offset] & 0x0F; @@ -858,10 +857,10 @@ void ds4_pad_handler::get_extended_info(const std::shared_ptr& device void ds4_pad_handler::apply_pad_data(const std::shared_ptr& device, const std::shared_ptr& pad) { DS4Device* ds4_dev = static_cast(device.get()); - if (!ds4_dev || !ds4_dev->hidDevice || !pad) + if (!ds4_dev || !ds4_dev->hidDevice || !ds4_dev->config || !pad) return; - auto config = ds4_dev->config; + pad_config* config = ds4_dev->config; // Attempt to send rumble no matter what const int idx_l = config->switch_vibration_motors ? 1 : 0; @@ -874,8 +873,6 @@ void ds4_pad_handler::apply_pad_data(const std::shared_ptr& device, c const bool lowBattery = ds4_dev->batteryLevel < 2; const bool isBlinking = ds4_dev->led_delay_on > 0 || ds4_dev->led_delay_off > 0; - bool newBlinkData = false; - // Blink LED when battery is low if (config->led_low_battery_blink) { @@ -884,14 +881,14 @@ void ds4_pad_handler::apply_pad_data(const std::shared_ptr& device, c { ds4_dev->led_delay_on = 0; ds4_dev->led_delay_off = 0; - newBlinkData = true; + ds4_dev->new_output_data = true; } // we are now wireless and low on battery -> blink - if (!isBlinking && wireless && lowBattery) + else if (!isBlinking && wireless && lowBattery) { ds4_dev->led_delay_on = 100; ds4_dev->led_delay_off = 100; - newBlinkData = true; + ds4_dev->new_output_data = true; } } @@ -905,16 +902,20 @@ void ds4_pad_handler::apply_pad_data(const std::shared_ptr& device, c config->colorR.set(combined_color >> 8); config->colorG.set(combined_color & 0xff); config->colorB.set(0); + ds4_dev->new_output_data = true; } } - ds4_dev->newVibrateData |= ds4_dev->large_motor != speed_large || ds4_dev->small_motor != speed_small || newBlinkData; + ds4_dev->new_output_data |= ds4_dev->large_motor != speed_large || ds4_dev->small_motor != speed_small; ds4_dev->large_motor = speed_large; ds4_dev->small_motor = speed_small; - if (ds4_dev->newVibrateData && send_output_report(ds4_dev) >= 0) + if (ds4_dev->new_output_data) { - ds4_dev->newVibrateData = false; + if (send_output_report(ds4_dev) >= 0) + { + ds4_dev->new_output_data = false; + } } } diff --git a/rpcs3/Input/ds4_pad_handler.h b/rpcs3/Input/ds4_pad_handler.h index 2bf651fd53..7cde470cb3 100644 --- a/rpcs3/Input/ds4_pad_handler.h +++ b/rpcs3/Input/ds4_pad_handler.h @@ -11,12 +11,9 @@ public: bool btCon{false}; bool hasCalibData{false}; std::array calibData{}; - bool newVibrateData{true}; - std::array padData{}; u8 batteryLevel{0}; u8 last_battery_level{0}; u8 cableState{0}; - bool is_initialized{false}; }; class ds4_pad_handler final : public hid_pad_handler diff --git a/rpcs3/Input/dualsense_pad_handler.cpp b/rpcs3/Input/dualsense_pad_handler.cpp index d57c661ae7..ad6053048a 100644 --- a/rpcs3/Input/dualsense_pad_handler.cpp +++ b/rpcs3/Input/dualsense_pad_handler.cpp @@ -918,10 +918,10 @@ int dualsense_pad_handler::send_output_report(DualSenseDevice* device) void dualsense_pad_handler::apply_pad_data(const std::shared_ptr& device, const std::shared_ptr& pad) { DualSenseDevice* dualsense_dev = static_cast(device.get()); - if (!dualsense_dev || !dualsense_dev->hidDevice || !pad) + if (!dualsense_dev || !dualsense_dev->hidDevice || !dualsense_dev->config || !pad) return; - auto config = dualsense_dev->config; + pad_config* config = dualsense_dev->config; // Attempt to send rumble no matter what const int idx_l = config->switch_vibration_motors ? 1 : 0; @@ -930,16 +930,16 @@ void dualsense_pad_handler::apply_pad_data(const std::shared_ptr& dev const int speed_large = config->enable_vibration_motor_large ? pad->m_vibrateMotors[idx_l].m_value : vibration_min; const int speed_small = config->enable_vibration_motor_small ? pad->m_vibrateMotors[idx_s].m_value : vibration_min; - dualsense_dev->newVibrateData |= dualsense_dev->large_motor != speed_large || dualsense_dev->small_motor != speed_small; + dualsense_dev->new_output_data |= dualsense_dev->large_motor != speed_large || dualsense_dev->small_motor != speed_small; dualsense_dev->large_motor = speed_large; dualsense_dev->small_motor = speed_small; - if (dualsense_dev->newVibrateData) + if (dualsense_dev->new_output_data) { if (send_output_report(dualsense_dev) >= 0) { - dualsense_dev->newVibrateData = false; + dualsense_dev->new_output_data = false; } } } diff --git a/rpcs3/Input/dualsense_pad_handler.h b/rpcs3/Input/dualsense_pad_handler.h index 028d8fa84a..549e4cab9e 100644 --- a/rpcs3/Input/dualsense_pad_handler.h +++ b/rpcs3/Input/dualsense_pad_handler.h @@ -19,8 +19,6 @@ public: bool has_calib_data{false}; std::array calib_data{}; DualSenseDataMode dataMode{DualSenseDataMode::Simple}; - std::array padData{}; - bool newVibrateData{true}; bool init_lightbar{true}; bool update_lightbar{true}; bool update_player_leds{true}; diff --git a/rpcs3/Input/hid_pad_handler.h b/rpcs3/Input/hid_pad_handler.h index f81b2e2f57..71b1335111 100644 --- a/rpcs3/Input/hid_pad_handler.h +++ b/rpcs3/Input/hid_pad_handler.h @@ -31,6 +31,8 @@ class HidDevice : public PadDevice public: hid_device* hidDevice{nullptr}; std::string path{""}; + std::array padData{}; + bool new_output_data{true}; u8 large_motor{0}; u8 small_motor{0}; u8 led_delay_on{0};