From 5cb437703fa441a08db295f8a916caedc3a581f2 Mon Sep 17 00:00:00 2001 From: german77 Date: Mon, 26 Dec 2022 12:49:49 -0600 Subject: yuzu: Add ring controller test button --- src/yuzu/configuration/configure_ringcon.cpp | 69 +++++ src/yuzu/configuration/configure_ringcon.h | 10 + src/yuzu/configuration/configure_ringcon.ui | 396 +++++++++++++++++---------- 3 files changed, 325 insertions(+), 150 deletions(-) (limited to 'src/yuzu') diff --git a/src/yuzu/configuration/configure_ringcon.cpp b/src/yuzu/configuration/configure_ringcon.cpp index 0cfe3b60e..697c36fb4 100644 --- a/src/yuzu/configuration/configure_ringcon.cpp +++ b/src/yuzu/configuration/configure_ringcon.cpp @@ -4,7 +4,9 @@ #include #include #include +#include #include +#include #include "core/hid/emulated_controller.h" #include "core/hid/hid_core.h" @@ -130,6 +132,13 @@ ConfigureRingController::ConfigureRingController(QWidget* parent, emulated_controller->SaveCurrentConfig(); emulated_controller->EnableConfiguration(); + Core::HID::ControllerUpdateCallback engine_callback{ + .on_change = [this](Core::HID::ControllerTriggerType type) { ControllerUpdate(type); }, + .is_npad_service = false, + }; + callback_key = emulated_controller->SetCallback(engine_callback); + is_controller_set = true; + LoadConfiguration(); for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { @@ -187,6 +196,9 @@ ConfigureRingController::ConfigureRingController(QWidget* parent, connect(ui->restore_defaults_button, &QPushButton::clicked, this, &ConfigureRingController::RestoreDefaults); + connect(ui->enable_ring_controller_button, &QPushButton::clicked, this, + &ConfigureRingController::EnableRingController); + timeout_timer->setSingleShot(true); connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); }); @@ -202,7 +214,13 @@ ConfigureRingController::ConfigureRingController(QWidget* parent, } ConfigureRingController::~ConfigureRingController() { + emulated_controller->SetPollingMode(Common::Input::PollingMode::Active); emulated_controller->DisableConfiguration(); + + if (is_controller_set) { + emulated_controller->DeleteCallback(callback_key); + is_controller_set = false; + } }; void ConfigureRingController::changeEvent(QEvent* event) { @@ -256,6 +274,57 @@ void ConfigureRingController::RestoreDefaults() { UpdateUI(); } +void ConfigureRingController::EnableRingController() { + const auto dialog_title = tr("Error enabling ring input"); + + is_ring_enabled = false; + ui->ring_controller_sensor_value->setText(tr("Not connected")); + + if (!Settings::values.enable_joycon_driver) { + QMessageBox::warning(this, dialog_title, tr("Direct Joycon driver is not enabled")); + return; + } + + ui->enable_ring_controller_button->setEnabled(false); + ui->enable_ring_controller_button->setText(tr("Configuring")); + // SetPollingMode is blocking. Allow to update the button status before calling the command + repaint(); + + const auto result = emulated_controller->SetPollingMode(Common::Input::PollingMode::Ring); + switch (result) { + case Common::Input::DriverResult::Success: + is_ring_enabled = true; + break; + case Common::Input::DriverResult::NotSupported: + QMessageBox::warning(this, dialog_title, + tr("The current mapped device doesn't support the ring controller")); + break; + case Common::Input::DriverResult::NoDeviceDetected: + QMessageBox::warning(this, dialog_title, + tr("The current mapped device doesn't have a ring attached")); + break; + default: + QMessageBox::warning(this, dialog_title, + tr("Unexpected driver result %1").arg(static_cast(result))); + break; + } + ui->enable_ring_controller_button->setEnabled(true); + ui->enable_ring_controller_button->setText(tr("Enable")); +} + +void ConfigureRingController::ControllerUpdate(Core::HID::ControllerTriggerType type) { + if (!is_ring_enabled) { + return; + } + if (type != Core::HID::ControllerTriggerType::RingController) { + return; + } + + const auto value = emulated_controller->GetRingSensorValues(); + const auto tex_value = QString::fromStdString(fmt::format("{:.3f}", value.raw_value)); + ui->ring_controller_sensor_value->setText(tex_value); +} + void ConfigureRingController::HandleClick( QPushButton* button, std::function new_input_setter, InputCommon::Polling::InputType type) { diff --git a/src/yuzu/configuration/configure_ringcon.h b/src/yuzu/configuration/configure_ringcon.h index 6e693e0dd..b23c27906 100644 --- a/src/yuzu/configuration/configure_ringcon.h +++ b/src/yuzu/configuration/configure_ringcon.h @@ -42,6 +42,12 @@ private: /// Restore all buttons to their default values. void RestoreDefaults(); + /// Sets current polling mode to ring input + void EnableRingController(); + + // Handles emulated controller events + void ControllerUpdate(Core::HID::ControllerTriggerType type); + /// Called when the button was pressed. void HandleClick(QPushButton* button, std::function new_input_setter, @@ -80,5 +86,9 @@ private: InputCommon::InputSubsystem* input_subsystem; Core::HID::EmulatedController* emulated_controller; + bool is_ring_enabled{}; + bool is_controller_set{}; + int callback_key; + std::unique_ptr ui; }; diff --git a/src/yuzu/configuration/configure_ringcon.ui b/src/yuzu/configuration/configure_ringcon.ui index 9ec634dd4..514dff372 100644 --- a/src/yuzu/configuration/configure_ringcon.ui +++ b/src/yuzu/configuration/configure_ringcon.ui @@ -6,8 +6,8 @@ 0 0 - 298 - 339 + 315 + 400 @@ -46,187 +46,283 @@ - - - - Ring Sensor Parameters - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - 0 - - - QLayout::SetDefaultConstraint - - - 3 - - - 6 - - - 3 - - - 0 - - - + + + + Virtual Ring Sensor Parameters + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + - 3 + 0 - - - - Pull - - - Qt::AlignCenter + + QLayout::SetDefaultConstraint + + + 3 + + + 6 + + + 3 + + + 0 + + + + + 3 - - - 3 + + + + Pull - - 3 - - - 3 + + Qt::AlignCenter - - 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Pull + + + + + + + + + + Push - - 3 + + Qt::AlignCenter - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - Pull - - - - - + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 70 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + Push + + + + + + + - - - - Push + + + + 3 - - Qt::AlignCenter + + QLayout::SetDefaultConstraint - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - + + 0 + + + 10 + + + 0 + + + 3 + + + - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - + - Push + Deadzone: 0% + + + Qt::AlignHCenter - + - - + + + + + + 100 + + + Qt::Horizontal + + + + - - - - + + + + + + + Direct Joycon Driver + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + - 3 + 0 - QLayout::SetDefaultConstraint + QLayout::SetDefaultConstraint - 0 + 3 - 10 + 6 - 0 + 3 - 3 + 10 - - - + + + 10 + + + 6 + + + 10 + + + 10 + + + 10 + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 76 + 20 + + + + + + + + Enable Ring Input + + + + + - Deadzone: 0% + Enable + + + + + + + Ring Sensor Value + + + + + + + Not connected - Qt::AlignHCenter + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + - - - - - - 100 - - - Qt::Horizontal - - + - - - - - + + + @@ -273,6 +369,6 @@ rejected() ConfigureRingController reject() - + -- cgit v1.2.3