From fb1d8cb548598eca61c50bcb5353144cb0c36cbc Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sun, 26 May 2019 09:43:04 +0200 Subject: [PATCH] Qt/Input: keep LED colors when setting vibration and merge pad functions --- rpcs3/Emu/Io/PadHandler.h | 3 +- rpcs3/ds3_pad_handler.cpp | 2 +- rpcs3/ds3_pad_handler.h | 2 +- rpcs3/ds4_pad_handler.cpp | 40 +++++---------------------- rpcs3/ds4_pad_handler.h | 3 +- rpcs3/evdev_joystick_handler.cpp | 2 +- rpcs3/evdev_joystick_handler.h | 2 +- rpcs3/rpcs3qt/pad_settings_dialog.cpp | 38 +++++++++++++++---------- rpcs3/rpcs3qt/pad_settings_dialog.h | 3 ++ rpcs3/xinput_pad_handler.cpp | 2 +- rpcs3/xinput_pad_handler.h | 4 +-- 11 files changed, 43 insertions(+), 58 deletions(-) diff --git a/rpcs3/Emu/Io/PadHandler.h b/rpcs3/Emu/Io/PadHandler.h index 4edfbd4315..beee7cc3aa 100644 --- a/rpcs3/Emu/Io/PadHandler.h +++ b/rpcs3/Emu/Io/PadHandler.h @@ -488,8 +488,7 @@ public: virtual ~PadHandlerBase() = default; //Sets window to config the controller(optional) virtual void GetNextButtonPress(const std::string& /*padId*/, const std::function& /*callback*/, const std::function& /*fail_callback*/, bool /*get_blacklist*/ = false, const std::vector& /*buttons*/ = {}) {} - virtual void TestVibration(const std::string& /*padId*/, u32 /*largeMotor*/, u32 /*smallMotor*/) {} - virtual void SetLED(const std::string& /*padId*/, s32 /*r*/, s32 /*g*/, s32 /*b*/) {} + virtual void SetPadData(const std::string& /*padId*/, u32 /*largeMotor*/, u32 /*smallMotor*/, s32 /*r*/, s32 /*g*/, s32 /*b*/) {} //Return list of devices for that handler virtual std::vector ListDevices() = 0; //Callback called during pad_thread::ThreadFunc diff --git a/rpcs3/ds3_pad_handler.cpp b/rpcs3/ds3_pad_handler.cpp index 9be2b312d5..2dc3db4665 100644 --- a/rpcs3/ds3_pad_handler.cpp +++ b/rpcs3/ds3_pad_handler.cpp @@ -238,7 +238,7 @@ void ds3_pad_handler::ThreadProc() } } -void ds3_pad_handler::TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) +void ds3_pad_handler::SetPadData(const std::string& padId, u32 largeMotor, u32 smallMotor, s32/* r*/, s32/* g*/, s32 b/* b*/) { std::shared_ptr device = get_device(padId); if (device == nullptr || device->handle == nullptr) diff --git a/rpcs3/ds3_pad_handler.h b/rpcs3/ds3_pad_handler.h index da77972c38..05592b0006 100644 --- a/rpcs3/ds3_pad_handler.h +++ b/rpcs3/ds3_pad_handler.h @@ -134,7 +134,7 @@ public: bool bindPadToDevice(std::shared_ptr pad, const std::string& device) override; void ThreadProc() override; void GetNextButtonPress(const std::string& padId, const std::function& buttonCallback, const std::function& fail_callback, bool get_blacklist = false, const std::vector& buttons = {}) override; - void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override; + void SetPadData(const std::string& padId, u32 largeMotor, u32 smallMotor, s32 r, s32 g, s32 b) override; void init_config(pad_config* cfg, const std::string& name) override; private: diff --git a/rpcs3/ds4_pad_handler.cpp b/rpcs3/ds4_pad_handler.cpp index 41f01cf075..eb4a1fec40 100644 --- a/rpcs3/ds4_pad_handler.cpp +++ b/rpcs3/ds4_pad_handler.cpp @@ -222,7 +222,7 @@ void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::fu return callback(0, "", padId, preview_values); } -void ds4_pad_handler::TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) +void ds4_pad_handler::SetPadData(const std::string& padId, u32 largeMotor, u32 smallMotor, s32 r, s32 g, s32 b) { std::shared_ptr device = GetDevice(padId); if (device == nullptr || device->hidDevice == nullptr) @@ -247,41 +247,15 @@ void ds4_pad_handler::TestVibration(const std::string& padId, u32 largeMotor, u3 } } - // Start/Stop the engines :) - SendVibrateData(device); -} - -void ds4_pad_handler::SetLED(const std::string& padId, s32 r, s32 g, s32 b) -{ - std::shared_ptr device = GetDevice(padId); - if (device == nullptr || device->hidDevice == nullptr) - return; - - int index = 0; - for (int i = 0; i < MAX_GAMEPADS; i++) + // Set new LED color + if (r >= 0 && g >= 0 && b >= 0 && r <= 255 && g <= 255 && b <= 255) { - if (g_cfg_input.player[i]->handler == pad_handler::ds4) - { - if (g_cfg_input.player[i]->device.to_string() == padId) - { - m_pad_configs[index].load(); - device->config = &m_pad_configs[index]; - break; - } - index++; - } + device->config->colorR.set(r); + device->config->colorG.set(g); + device->config->colorB.set(b); } - // disable pulse - device->led_delay_on = 0; - device->led_delay_off = 0; - - // set new color - device->config->colorR.set(r); - device->config->colorG.set(g); - device->config->colorB.set(b); - - // Show new color :) + // Start/Stop the engines :) SendVibrateData(device); } diff --git a/rpcs3/ds4_pad_handler.h b/rpcs3/ds4_pad_handler.h index 67361ccc60..958ed540d9 100644 --- a/rpcs3/ds4_pad_handler.h +++ b/rpcs3/ds4_pad_handler.h @@ -143,8 +143,7 @@ public: bool bindPadToDevice(std::shared_ptr pad, const std::string& device) override; void ThreadProc() override; void GetNextButtonPress(const std::string& padId, const std::function& buttonCallback, const std::function& fail_callback, bool get_blacklist = false, const std::vector& buttons = {}) override; - void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override; - void SetLED(const std::string& padId, s32 r, s32 g, s32 b) override; + void SetPadData(const std::string& padId, u32 largeMotor, u32 smallMotor, s32 r, s32 g, s32 b) override; void init_config(pad_config* cfg, const std::string& name) override; private: diff --git a/rpcs3/evdev_joystick_handler.cpp b/rpcs3/evdev_joystick_handler.cpp index a497ddf0ce..c2f8ef3cd4 100644 --- a/rpcs3/evdev_joystick_handler.cpp +++ b/rpcs3/evdev_joystick_handler.cpp @@ -478,7 +478,7 @@ void evdev_joystick_handler::SetRumble(EvdevDevice* device, u16 large, u16 small device->force_small = small; } -void evdev_joystick_handler::TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) +void evdev_joystick_handler::SetPadData(const std::string& padId, u32 largeMotor, u32 smallMotor, s32/* r*/, s32/* g*/, s32/* b*/) { // Get our evdev device EvdevDevice* dev = get_device(padId); diff --git a/rpcs3/evdev_joystick_handler.h b/rpcs3/evdev_joystick_handler.h index 5ab8279f58..f8b23e9b26 100644 --- a/rpcs3/evdev_joystick_handler.h +++ b/rpcs3/evdev_joystick_handler.h @@ -339,7 +339,7 @@ public: void ThreadProc() override; void Close(); void GetNextButtonPress(const std::string& padId, const std::function& callback, const std::function& fail_callback, bool get_blacklist = false, const std::vector& buttons = {}) override; - void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override; + void SetPadData(const std::string& padId, u32 largeMotor, u32 smallMotor, s32 r, s32 g, s32 b) override; private: void TranslateButtonPress(u64 keyCode, bool& pressed, u16& value, bool ignore_threshold = false) override; diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.cpp b/rpcs3/rpcs3qt/pad_settings_dialog.cpp index 337eed031f..8bd777e0f7 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/pad_settings_dialog.cpp @@ -277,12 +277,12 @@ void pad_settings_dialog::InitButtons() return; } - ui->chb_vibration_switch->isChecked() ? m_handler->TestVibration(m_device_name, m_min_force, m_max_force) - : m_handler->TestVibration(m_device_name, m_max_force, m_min_force); + ui->chb_vibration_switch->isChecked() ? SetPadData(m_min_force, m_max_force) + : SetPadData(m_max_force, m_min_force); QTimer::singleShot(300, [this]() { - m_handler->TestVibration(m_device_name, m_min_force, m_min_force); + SetPadData(m_min_force, m_min_force); }); }); @@ -293,28 +293,28 @@ void pad_settings_dialog::InitButtons() return; } - ui->chb_vibration_switch->isChecked() ? m_handler->TestVibration(m_device_name, m_max_force, m_min_force) - : m_handler->TestVibration(m_device_name, m_min_force, m_max_force); + ui->chb_vibration_switch->isChecked() ? SetPadData(m_max_force, m_min_force) + : SetPadData(m_min_force, m_max_force); QTimer::singleShot(300, [this]() { - m_handler->TestVibration(m_device_name, m_min_force, m_min_force); + SetPadData(m_min_force, m_min_force); }); }); connect(ui->chb_vibration_switch, &QCheckBox::clicked, [this](bool checked) { - checked ? m_handler->TestVibration(m_device_name, m_min_force, m_max_force) - : m_handler->TestVibration(m_device_name, m_max_force, m_min_force); + checked ? SetPadData(m_min_force, m_max_force) + : SetPadData(m_max_force, m_min_force); QTimer::singleShot(200, [this, checked]() { - checked ? m_handler->TestVibration(m_device_name, m_max_force, m_min_force) - : m_handler->TestVibration(m_device_name, m_min_force, m_max_force); + checked ? SetPadData(m_max_force, m_min_force) + : SetPadData(m_min_force, m_max_force); QTimer::singleShot(200, [this]() { - m_handler->TestVibration(m_device_name, m_min_force, m_min_force); + SetPadData(m_min_force, m_min_force); }); }); }); @@ -341,7 +341,7 @@ void pad_settings_dialog::InitButtons() if (dlg.exec() == QColorDialog::Accepted) { const QColor newColor = dlg.selectedColor(); - m_handler->SetLED(m_device_name, newColor.red(), newColor.green(), newColor.blue()); + m_handler->SetPadData(m_device_name, 0, 0, newColor.red(), newColor.green(), newColor.blue()); ui->b_led->setIcon(gui::utils::get_colorized_icon(QIcon(":/Icons/controllers.png"), Qt::black, newColor)); ui->b_led->setProperty("led", newColor); } @@ -426,6 +426,16 @@ void pad_settings_dialog::InitButtons() }); } +void pad_settings_dialog::SetPadData(u32 large_motor, u32 small_motor) +{ + QColor led_color(m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB); + if (ui->b_led->property("led").canConvert()) + { + led_color = ui->b_led->property("led").value(); + } + m_handler->SetPadData(m_device_name, large_motor, small_motor, led_color.red(), led_color.green(), led_color.blue()); +} + void pad_settings_dialog::SwitchPadInfo(const std::string& pad_name, bool is_connected) { for (int i = 0; i < ui->chooseDevice->count(); i++) @@ -555,7 +565,7 @@ void pad_settings_dialog::ReloadButtons() // Enable and repaint the LED Button m_enable_led = m_handler->has_led(); - m_handler->SetLED(m_device_name, m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB); + m_handler->SetPadData(m_device_name, 0, 0, m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB); const QColor led_color(m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB); ui->b_led->setIcon(gui::utils::get_colorized_icon(QIcon(":/Icons/controllers.png"), Qt::black, led_color)); @@ -763,7 +773,7 @@ void pad_settings_dialog::UpdateLabel(bool is_reset) const QColor led_color(m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB); ui->b_led->setProperty("led", led_color); ui->b_led->setIcon(gui::utils::get_colorized_icon(QIcon(":/Icons/controllers.png"), Qt::black, led_color)); - m_handler->SetLED(m_device_name, m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB); + m_handler->SetPadData(m_device_name, 0, 0, m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB); } } diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.h b/rpcs3/rpcs3qt/pad_settings_dialog.h index 1504619694..ad83bef1f4 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.h +++ b/rpcs3/rpcs3qt/pad_settings_dialog.h @@ -148,6 +148,9 @@ private: // Input timer. Its Callback handles the input QTimer m_timer_input; + // Set vibrate data while keeping the current color + void SetPadData(u32 large_motor, u32 small_motor); + /** Update all the Button Labels with current button mapping */ void UpdateLabel(bool is_reset = false); void SwitchPadInfo(const std::string& name, bool is_connected); diff --git a/rpcs3/xinput_pad_handler.cpp b/rpcs3/xinput_pad_handler.cpp index 52772fde05..7455780c04 100644 --- a/rpcs3/xinput_pad_handler.cpp +++ b/rpcs3/xinput_pad_handler.cpp @@ -136,7 +136,7 @@ void xinput_pad_handler::GetNextButtonPress(const std::string& padId, const std: return callback(0, "", padId, preview_values); } -void xinput_pad_handler::TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) +void xinput_pad_handler::SetPadData(const std::string& padId, u32 largeMotor, u32 smallMotor, s32/* r*/, s32/* g*/, s32/* b*/) { int device_number = GetDeviceNumber(padId); if (device_number < 0) diff --git a/rpcs3/xinput_pad_handler.h b/rpcs3/xinput_pad_handler.h index a389395f34..8bf2d91d6e 100644 --- a/rpcs3/xinput_pad_handler.h +++ b/rpcs3/xinput_pad_handler.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "Utilities/Config.h" #include "Emu/Io/PadHandler.h" @@ -108,7 +108,7 @@ public: bool bindPadToDevice(std::shared_ptr pad, const std::string& device) override; void ThreadProc() override; void GetNextButtonPress(const std::string& padId, const std::function& callback, const std::function& fail_callback, bool get_blacklist = false, const std::vector& buttons = {}) override; - void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override; + void SetPadData(const std::string& padId, u32 largeMotor, u32 smallMotor, s32 r, s32 g, s32 b) override; void init_config(pad_config* cfg, const std::string& name) override; private: