1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

Qt/Input: keep LED colors when setting vibration and merge pad functions

This commit is contained in:
Megamouse 2019-05-26 09:43:04 +02:00
parent 5760aa2e57
commit fb1d8cb548
11 changed files with 43 additions and 58 deletions

View File

@ -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<void(u16, std::string, std::string, int[])>& /*callback*/, const std::function<void(std::string)>& /*fail_callback*/, bool /*get_blacklist*/ = false, const std::vector<std::string>& /*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<std::string> ListDevices() = 0;
//Callback called during pad_thread::ThreadFunc

View File

@ -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<ds3_device> device = get_device(padId);
if (device == nullptr || device->handle == nullptr)

View File

@ -134,7 +134,7 @@ public:
bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override;
void ThreadProc() override;
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, std::string, int[])>& buttonCallback, const std::function<void(std::string)>& fail_callback, bool get_blacklist = false, const std::vector<std::string>& 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:

View File

@ -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<DS4Device> 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<DS4Device> 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++;
}
}
// 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);
}

View File

@ -143,8 +143,7 @@ public:
bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override;
void ThreadProc() override;
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, std::string, int[])>& buttonCallback, const std::function<void(std::string)>& fail_callback, bool get_blacklist = false, const std::vector<std::string>& 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:

View File

@ -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);

View File

@ -339,7 +339,7 @@ public:
void ThreadProc() override;
void Close();
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, std::string, int[])>& callback, const std::function<void(std::string)>& fail_callback, bool get_blacklist = false, const std::vector<std::string>& 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;

View File

@ -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<QColor>())
{
led_color = ui->b_led->property("led").value<QColor>();
}
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);
}
}

View File

@ -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);

View File

@ -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)

View File

@ -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> pad, const std::string& device) override;
void ThreadProc() override;
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, std::string, int[])>& callback, const std::function<void(std::string)>& fail_callback, bool get_blacklist = false, const std::vector<std::string>& 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: