From 0248614add99c1df1bc7c9ff97091f678ff75aca Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 12:36:28 -0400 Subject: GC Adapter Implementation --- src/yuzu/configuration/configure_input_player.cpp | 131 +++++++++++++++------- src/yuzu/configuration/configure_input_player.h | 8 +- 2 files changed, 94 insertions(+), 45 deletions(-) (limited to 'src/yuzu') diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index a05fa64ba..81436af1b 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -19,13 +19,13 @@ #include "yuzu/configuration/configure_input_player.h" const std::array - ConfigureInputPlayer::analog_sub_buttons{{ - "up", - "down", - "left", - "right", - "modifier", - }}; +ConfigureInputPlayer::analog_sub_buttons{{ + "up", + "down", + "left", + "right", + "modifier", +}}; static void LayerGridElements(QGridLayout* grid, QWidget* item, QWidget* onTopOf) { const int index1 = grid->indexOf(item); @@ -70,6 +70,20 @@ static QString ButtonToText(const Common::ParamPackage& param) { return GetKeyName(param.Get("code", 0)); } + if (param.Get("engine", "") == "gcpad") { + if (param.Has("axis")) { + const QString axis_str = QString::fromStdString(param.Get("axis", "")); + const QString direction_str = QString::fromStdString(param.Get("direction", "")); + + return QObject::tr("Axis %1%2").arg(axis_str, direction_str); + } + if (param.Has("button")) { + const QString button_str = QString::number(int(std::log2(param.Get("button", 0)))); + return QObject::tr("Button %1").arg(button_str); + } + return GetKeyName(param.Get("code", 0)); + } + if (param.Get("engine", "") == "sdl") { if (param.Has("hat")) { const QString hat_str = QString::fromStdString(param.Get("hat", "")); @@ -106,7 +120,7 @@ static QString AnalogToText(const Common::ParamPackage& param, const std::string return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); } - if (param.Get("engine", "") == "sdl") { + if (param.Get("engine", "") == "sdl" || param.Get("engine", "") == "gcpad") { if (dir == "modifier") { return QObject::tr("[unused]"); } @@ -137,13 +151,13 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i setFocusPolicy(Qt::ClickFocus); button_map = { - ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, - ui->buttonLStick, ui->buttonRStick, ui->buttonL, ui->buttonR, - ui->buttonZL, ui->buttonZR, ui->buttonPlus, ui->buttonMinus, - ui->buttonDpadLeft, ui->buttonDpadUp, ui->buttonDpadRight, ui->buttonDpadDown, + ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, + ui->buttonLStick, ui->buttonRStick, ui->buttonL, ui->buttonR, + ui->buttonZL, ui->buttonZR, ui->buttonPlus, ui->buttonMinus, + ui->buttonDpadLeft, ui->buttonDpadUp, ui->buttonDpadRight, ui->buttonDpadDown, ui->buttonLStickLeft, ui->buttonLStickUp, ui->buttonLStickRight, ui->buttonLStickDown, ui->buttonRStickLeft, ui->buttonRStickUp, ui->buttonRStickRight, ui->buttonRStickDown, - ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot, + ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot, }; analog_map_buttons = {{ @@ -164,11 +178,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i }}; debug_hidden = { - ui->buttonSL, ui->labelSL, - ui->buttonSR, ui->labelSR, - ui->buttonLStick, ui->labelLStickPressed, - ui->buttonRStick, ui->labelRStickPressed, - ui->buttonHome, ui->labelHome, + ui->buttonSL, ui->labelSL, + ui->buttonSR, ui->labelSR, + ui->buttonLStick, ui->labelLStickPressed, + ui->buttonRStick, ui->labelRStickPressed, + ui->buttonHome, ui->labelHome, ui->buttonScreenshot, ui->labelScreenshot, }; @@ -207,12 +221,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i case Settings::ControllerType::RightJoycon: layout_hidden = { ui->left_body_button, ui->left_buttons_button, - ui->left_body_label, ui->left_buttons_label, - ui->buttonL, ui->labelL, - ui->buttonZL, ui->labelZL, - ui->labelScreenshot, ui->buttonScreenshot, - ui->buttonMinus, ui->labelMinus, - ui->LStick, ui->Dpad, + ui->left_body_label, ui->left_buttons_label, + ui->buttonL, ui->labelL, + ui->buttonZL, ui->labelZL, + ui->labelScreenshot, ui->buttonScreenshot, + ui->buttonMinus, ui->labelMinus, + ui->LStick, ui->Dpad, }; break; } @@ -247,9 +261,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i } button->setContextMenuPolicy(Qt::CustomContextMenu); - connect(button, &QPushButton::clicked, [=] { + connect(button, &QPushButton::clicked, [=] + { HandleClick(button_map[button_id], - [=](Common::ParamPackage params) { + [=](Common::ParamPackage params) + { // Workaround for ZL & ZR for analog triggers like on XBOX controllors. // Analog triggers (from controllers like the XBOX controller) would not // work due to a different range of their signals (from 0 to 255 on @@ -267,13 +283,16 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i }, InputCommon::Polling::DeviceType::Button); }); - connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { + connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) + { QMenu context_menu; - context_menu.addAction(tr("Clear"), [&] { + context_menu.addAction(tr("Clear"), [&] + { buttons_param[button_id].Clear(); button_map[button_id]->setText(tr("[not set]")); }); - context_menu.addAction(tr("Restore Default"), [&] { + context_menu.addAction(tr("Restore Default"), [&] + { buttons_param[button_id] = Common::ParamPackage{ InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); @@ -290,22 +309,27 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i } analog_button->setContextMenuPolicy(Qt::CustomContextMenu); - connect(analog_button, &QPushButton::clicked, [=]() { + connect(analog_button, &QPushButton::clicked, [=]() + { HandleClick(analog_map_buttons[analog_id][sub_button_id], - [=](const Common::ParamPackage& params) { + [=](const Common::ParamPackage& params) + { SetAnalogButton(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]); }, InputCommon::Polling::DeviceType::Button); }); connect(analog_button, &QPushButton::customContextMenuRequested, - [=](const QPoint& menu_location) { + [=](const QPoint& menu_location) + { QMenu context_menu; - context_menu.addAction(tr("Clear"), [&] { + context_menu.addAction(tr("Clear"), [&] + { analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); }); - context_menu.addAction(tr("Restore Default"), [&] { + context_menu.addAction(tr("Restore Default"), [&] + { Common::ParamPackage params{InputCommon::GenerateKeyboardParam( Config::default_analogs[analog_id][sub_button_id])}; SetAnalogButton(params, analogs_param[analog_id], @@ -317,11 +341,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i menu_location)); }); } - connect(analog_map_stick[analog_id], &QPushButton::clicked, [=] { + connect(analog_map_stick[analog_id], &QPushButton::clicked, [=] + { if (QMessageBox::information( this, tr("Information"), tr("After pressing OK, first move your joystick horizontally, " - "and then vertically."), + "and then vertically."), QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { HandleClick( analog_map_stick[analog_id], @@ -330,9 +355,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i } }); - connect(analog_map_deadzone_and_modifier_slider[analog_id], &QSlider::valueChanged, [=] { + connect(analog_map_deadzone_and_modifier_slider[analog_id], &QSlider::valueChanged, [=] + { const float slider_value = analog_map_deadzone_and_modifier_slider[analog_id]->value(); - if (analogs_param[analog_id].Get("engine", "") == "sdl") { + if (analogs_param[analog_id].Get("engine", "") == "sdl" || + analogs_param[analog_id].Get("engine", "") == "gcpad") { analog_map_deadzone_and_modifier_slider_label[analog_id]->setText( tr("Deadzone: %1%").arg(slider_value)); analogs_param[analog_id].Set("deadzone", slider_value / 100.0f); @@ -350,8 +377,23 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i timeout_timer->setSingleShot(true); connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); }); - connect(poll_timer.get(), &QTimer::timeout, [this] { + connect(poll_timer.get(), &QTimer::timeout, [this] + { Common::ParamPackage params; + if (InputCommon::GetGCButtons()->IsPolling()) { + params = InputCommon::GetGCButtons()->GetNextInput(); + if (params.Has("engine")) { + SetPollingResult(params, false); + return; + } + } + if (InputCommon::GetGCAnalogs()->IsPolling()) { + params = InputCommon::GetGCAnalogs()->GetNextInput(); + if (params.Has("engine")) { + SetPollingResult(params, false); + return; + } + } for (auto& poller : device_pollers) { params = poller->GetNextInput(); if (params.Has("engine")) { @@ -463,7 +505,7 @@ void ConfigureInputPlayer::LoadConfiguration() { for (std::size_t i = 0; i < colors.size(); ++i) { controller_color_buttons[i]->setStyleSheet( QStringLiteral("QPushButton { background-color: %1 }") - .arg(controller_colors[i].name())); + .arg(controller_colors[i].name())); } } @@ -534,7 +576,7 @@ void ConfigureInputPlayer::UpdateButtonLabels() { analog_map_deadzone_and_modifier_slider_label[analog_id]; if (param.Has("engine")) { - if (param.Get("engine", "") == "sdl") { + if (param.Get("engine", "") == "sdl" || param.Get("engine", "") == "gcpad") { if (!param.Has("deadzone")) { param.Set("deadzone", 0.1f); } @@ -583,6 +625,10 @@ void ConfigureInputPlayer::HandleClick( grabKeyboard(); grabMouse(); + if (type == InputCommon::Polling::DeviceType::Button) + InputCommon::GetGCButtons()->BeginConfiguration(); + else + InputCommon::GetGCAnalogs()->BeginConfiguration(); timeout_timer->start(5000); // Cancel after 5 seconds poll_timer->start(200); // Check for new inputs every 200ms } @@ -596,6 +642,9 @@ void ConfigureInputPlayer::SetPollingResult(const Common::ParamPackage& params, poller->Stop(); } + InputCommon::GetGCButtons()->EndConfiguration(); + InputCommon::GetGCAnalogs()->EndConfiguration(); + if (!abort) { (*input_setter)(params); } diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h index 95afa5375..dad2a80ec 100644 --- a/src/yuzu/configuration/configure_input_player.h +++ b/src/yuzu/configuration/configure_input_player.h @@ -31,7 +31,7 @@ class ConfigureInputPlayer; } class ConfigureInputPlayer : public QDialog { - Q_OBJECT +Q_OBJECT public: explicit ConfigureInputPlayer(QWidget* parent, std::size_t player_index, bool debug = false); @@ -92,15 +92,15 @@ private: /// A group of five QPushButtons represent one analog input. The buttons each represent up, /// down, left, right, and modifier, respectively. std::array, Settings::NativeAnalog::NumAnalogs> - analog_map_buttons; + analog_map_buttons; /// Analog inputs are also represented each with a single button, used to configure with an /// actual analog stick std::array analog_map_stick; std::array - analog_map_deadzone_and_modifier_slider; + analog_map_deadzone_and_modifier_slider; std::array - analog_map_deadzone_and_modifier_slider_label; + analog_map_deadzone_and_modifier_slider_label; static const std::array analog_sub_buttons; -- cgit v1.2.3 From c94583d867fd909d8731ba50e085352aae0e6885 Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 15:31:57 -0400 Subject: Clang Formatting --- src/core/hle/service/hid/controllers/npad.cpp | 42 +++---- src/input_common/gcadapter/gc_adapter.cpp | 90 +++++++++----- src/input_common/gcadapter/gc_adapter.h | 16 ++- src/input_common/gcadapter/gc_poller.cpp | 56 ++++----- src/input_common/gcadapter/gc_poller.h | 5 +- src/input_common/main.h | 3 +- src/input_common/udp/client.cpp | 6 +- src/yuzu/configuration/configure_input_player.cpp | 140 ++++++++++------------ src/yuzu/configuration/configure_input_player.h | 8 +- 9 files changed, 184 insertions(+), 182 deletions(-) (limited to 'src/yuzu') diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index d92325cb5..c55d900e2 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -44,7 +44,7 @@ static Controller_NPad::NPadControllerType MapSettingsTypeToNPad(Settings::Contr case Settings::ControllerType::RightJoycon: return Controller_NPad::NPadControllerType::JoyRight; default: - UNREACHABLE(); + UNREACHABLE(); return Controller_NPad::NPadControllerType::JoyDual; } } @@ -93,10 +93,7 @@ u32 Controller_NPad::IndexToNPad(std::size_t index) { }; } -Controller_NPad::Controller_NPad(Core::System& system) - : ControllerBase(system), system(system) { -} - +Controller_NPad::Controller_NPad(Core::System& system) : ControllerBase(system), system(system) {} Controller_NPad::~Controller_NPad() = default; void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) { @@ -109,7 +106,7 @@ void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) { controller.device_type.raw = 0; switch (controller_type) { case NPadControllerType::None: - UNREACHABLE(); + UNREACHABLE(); break; case NPadControllerType::Handheld: controller.joy_styles.handheld.Assign(1); @@ -197,8 +194,7 @@ void Controller_NPad::OnInit() { std::transform( Settings::values.players.begin(), Settings::values.players.end(), - connected_controllers.begin(), [](const Settings::PlayerInput& player) - { + connected_controllers.begin(), [](const Settings::PlayerInput& player) { return ControllerHolder{MapSettingsTypeToNPad(player.type), player.connected}; }); @@ -242,8 +238,7 @@ void Controller_NPad::OnLoadInputDevices() { } } -void Controller_NPad::OnRelease() { -} +void Controller_NPad::OnRelease() {} void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { const auto controller_idx = NPadIdToIndex(npad_id); @@ -281,31 +276,27 @@ void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { pad_state.d_down.Assign(button_state[DDown - BUTTON_HID_BEGIN]->GetStatus()); pad_state.l_stick_right.Assign( - analog_state[static_cast(JoystickId::Joystick_Left)]-> - GetAnalogDirectionStatus( + analog_state[static_cast(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus( Input::AnalogDirection::RIGHT)); pad_state.l_stick_left.Assign( - analog_state[static_cast(JoystickId::Joystick_Left)]-> - GetAnalogDirectionStatus( + analog_state[static_cast(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus( Input::AnalogDirection::LEFT)); pad_state.l_stick_up.Assign( - analog_state[static_cast(JoystickId::Joystick_Left)]-> - GetAnalogDirectionStatus( + analog_state[static_cast(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus( Input::AnalogDirection::UP)); pad_state.l_stick_down.Assign( - analog_state[static_cast(JoystickId::Joystick_Left)]-> - GetAnalogDirectionStatus( + analog_state[static_cast(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus( Input::AnalogDirection::DOWN)); pad_state.r_stick_right.Assign( analog_state[static_cast(JoystickId::Joystick_Right)] - ->GetAnalogDirectionStatus(Input::AnalogDirection::RIGHT)); + ->GetAnalogDirectionStatus(Input::AnalogDirection::RIGHT)); pad_state.r_stick_left.Assign(analog_state[static_cast(JoystickId::Joystick_Right)] - ->GetAnalogDirectionStatus(Input::AnalogDirection::LEFT)); + ->GetAnalogDirectionStatus(Input::AnalogDirection::LEFT)); pad_state.r_stick_up.Assign(analog_state[static_cast(JoystickId::Joystick_Right)] - ->GetAnalogDirectionStatus(Input::AnalogDirection::UP)); + ->GetAnalogDirectionStatus(Input::AnalogDirection::UP)); pad_state.r_stick_down.Assign(analog_state[static_cast(JoystickId::Joystick_Right)] - ->GetAnalogDirectionStatus(Input::AnalogDirection::DOWN)); + ->GetAnalogDirectionStatus(Input::AnalogDirection::DOWN)); pad_state.left_sl.Assign(button_state[SL - BUTTON_HID_BEGIN]->GetStatus()); pad_state.left_sr.Assign(button_state[SR - BUTTON_HID_BEGIN]->GetStatus()); @@ -372,7 +363,7 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* switch (controller_type) { case NPadControllerType::None: - UNREACHABLE(); + UNREACHABLE(); break; case NPadControllerType::Handheld: handheld_entry.connection_status.raw = 0; @@ -468,9 +459,8 @@ void Controller_NPad::SetSupportedNPadIdTypes(u8* data, std::size_t length) { continue; } const auto requested_controller = - i <= MAX_NPAD_ID - ? MapSettingsTypeToNPad(Settings::values.players[i].type) - : NPadControllerType::Handheld; + i <= MAX_NPAD_ID ? MapSettingsTypeToNPad(Settings::values.players[i].type) + : NPadControllerType::Handheld; if (!IsControllerSupported(requested_controller)) { const auto is_handheld = requested_controller == NPadControllerType::Handheld; if (is_handheld) { diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index d42261d61..dc04116ce 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -1,7 +1,7 @@ // Copyright 2014 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. -//* + #include "common/logging/log.h" #include "common/threadsafe_queue.h" #include "input_common/gcadapter/gc_adapter.h" @@ -45,35 +45,48 @@ GCPadStatus CheckStatus(int port, u8 adapter_payload[37]) { u8 b1 = adapter_payload[1 + (9 * port) + 1]; u8 b2 = adapter_payload[1 + (9 * port) + 2]; - if (b1 & (1 << 0)) + if (b1 & (1 << 0)) { pad.button |= PAD_BUTTON_A; - if (b1 & (1 << 1)) + } + if (b1 & (1 << 1)) { pad.button |= PAD_BUTTON_B; - if (b1 & (1 << 2)) + } + if (b1 & (1 << 2)) { pad.button |= PAD_BUTTON_X; - if (b1 & (1 << 3)) + } + if (b1 & (1 << 3)) { pad.button |= PAD_BUTTON_Y; + } - if (b1 & (1 << 4)) + if (b1 & (1 << 4)) { pad.button |= PAD_BUTTON_LEFT; - if (b1 & (1 << 5)) + } + if (b1 & (1 << 5)) { pad.button |= PAD_BUTTON_RIGHT; - if (b1 & (1 << 6)) + } + if (b1 & (1 << 6)) { pad.button |= PAD_BUTTON_DOWN; - if (b1 & (1 << 7)) + } + if (b1 & (1 << 7)) { pad.button |= PAD_BUTTON_UP; + } - if (b2 & (1 << 0)) + if (b2 & (1 << 0)) { pad.button |= PAD_BUTTON_START; - if (b2 & (1 << 1)) + } + if (b2 & (1 << 1)) { pad.button |= PAD_TRIGGER_Z; - if (b2 & (1 << 2)) + } + if (b2 & (1 << 2)) { pad.button |= PAD_TRIGGER_R; - if (b2 & (1 << 3)) + } + if (b2 & (1 << 3)) { pad.button |= PAD_TRIGGER_L; + } - if (get_origin) + if (get_origin) { pad.button |= PAD_GET_ORIGIN; + } pad.stickX = adapter_payload[1 + (9 * port) + 3]; pad.stickY = adapter_payload[1 + (9 * port) + 4]; @@ -86,7 +99,7 @@ GCPadStatus CheckStatus(int port, u8 adapter_payload[37]) { } void PadToState(GCPadStatus pad, GCState& state) { - //std::lock_guard lock{s_mutex}; + // std::lock_guard lock{s_mutex}; state.buttons.insert_or_assign(PAD_BUTTON_A, pad.button & PAD_BUTTON_A); state.buttons.insert_or_assign(PAD_BUTTON_B, pad.button & PAD_BUTTON_B); state.buttons.insert_or_assign(PAD_BUTTON_X, pad.button & PAD_BUTTON_X); @@ -125,7 +138,7 @@ static void Read() { std::begin(controller_payload_copy)); payload_size = payload_size_in; } - + GCPadStatus pad[4]; if (payload_size != sizeof(controller_payload_copy) || controller_payload_copy[0] != LIBUSB_DT_HID) { @@ -137,8 +150,9 @@ static void Read() { } for (int port = 0; port < 4; port++) { if (DeviceConnected(port) && configuring) { - if (pad[port].button != PAD_GET_ORIGIN) + if (pad[port].button != PAD_GET_ORIGIN) { pad_queue[port].Push(pad[port]); + } // Accounting for a threshold here because of some controller variance if (pad[port].stickX > pad[port].MAIN_STICK_CENTER_X + pad[port].THRESHOLD || @@ -186,8 +200,9 @@ static void ScanThreadFunc() { void Init() { - if (usb_adapter_handle != nullptr) + if (usb_adapter_handle != nullptr) { return; + } LOG_INFO(Input, "GC Adapter Initialization started"); current_status = NO_ADAPTER_DETECTED; @@ -197,10 +212,12 @@ void Init() { } void StartScanThread() { - if (detect_thread_running) + if (detect_thread_running) { return; - if (!libusb_ctx) + } + if (!libusb_ctx) { return; + } detect_thread_running = true; detect_thread = std::thread(ScanThreadFunc); @@ -212,15 +229,17 @@ void StopScanThread() { static void Setup() { // Reset the error status in case the adapter gets unplugged - if (current_status < 0) + if (current_status < 0) { current_status = NO_ADAPTER_DETECTED; + } - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE; - + } + libusb_device** devs; // pointer to list of connected usb devices - int cnt = libusb_get_device_list(libusb_ctx, &devs); //get the list of devices + int cnt = libusb_get_device_list(libusb_ctx, &devs); // get the list of devices for (int i = 0; i < cnt; i++) { if (CheckDeviceAccess(devs[i])) { @@ -247,9 +266,8 @@ static bool CheckDeviceAccess(libusb_device* device) { ret = libusb_open(device, &usb_adapter_handle); if (ret == LIBUSB_ERROR_ACCESS) { - LOG_ERROR(Input, - "Yuzu can not gain access to this device: ID %04X:%04X.", - desc.idVendor, desc.idProduct); + LOG_ERROR(Input, "Yuzu can not gain access to this device: ID %04X:%04X.", desc.idVendor, + desc.idProduct); return false; } if (ret) { @@ -260,8 +278,9 @@ static bool CheckDeviceAccess(libusb_device* device) { ret = libusb_kernel_driver_active(usb_adapter_handle, 0); if (ret == 1) { ret = libusb_detach_kernel_driver(usb_adapter_handle, 0); - if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) + if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) { LOG_ERROR(Input, "libusb_detach_kernel_driver failed with error = %d", ret); + } } if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) { @@ -290,8 +309,9 @@ static void GetGCEndpoint(libusb_device* device) { const libusb_interface_descriptor* interface = &interfaceContainer->altsetting[i]; for (u8 e = 0; e < interface->bNumEndpoints; e++) { const libusb_endpoint_descriptor* endpoint = &interface->endpoint[e]; - if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN) + if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN) { input_endpoint = endpoint->bEndpointAddress; + } } } } @@ -311,16 +331,20 @@ void Shutdown() { static void Reset() { std::unique_lock lock(initialization_mutex, std::defer_lock); - if (!lock.try_lock()) + if (!lock.try_lock()) { return; - if (current_status != ADAPTER_DETECTED) + } + if (current_status != ADAPTER_DETECTED) { return; + } - if (adapter_thread_running) + if (adapter_thread_running) { adapter_input_thread.join(); + } - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE; + } current_status = NO_ADAPTER_DETECTED; diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 9b02d1382..05ee73c65 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -1,11 +1,14 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + #pragma once #include -#include -#include #include +#include +#include #include "common/common_types.h" - enum { PAD_USE_ORIGIN = 0x0080, PAD_GET_ORIGIN = 0x2000, @@ -61,13 +64,8 @@ struct GCState { std::unordered_map axes; }; - namespace GCAdapter { -enum ControllerTypes { - CONTROLLER_NONE = 0, - CONTROLLER_WIRED = 1, - CONTROLLER_WIRELESS = 2 -}; +enum ControllerTypes { CONTROLLER_NONE = 0, CONTROLLER_WIRED = 1, CONTROLLER_WIRELESS = 2 }; enum { NO_ADAPTER_DETECTED = 0, diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 772bd8890..51b3362d6 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -1,10 +1,14 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + #include #include #include #include -#include "input_common/gcadapter/gc_poller.h" -#include "input_common/gcadapter/gc_adapter.h" #include "common/threadsafe_queue.h" +#include "input_common/gcadapter/gc_adapter.h" +#include "input_common/gcadapter/gc_poller.h" // Using extern as to avoid multply defined symbols. extern Common::SPSCQueue pad_queue[4]; @@ -14,9 +18,7 @@ namespace InputCommon { class GCButton final : public Input::ButtonDevice { public: - explicit GCButton(int port_, int button_, int axis_) - : port(port_), button(button_) { - } + explicit GCButton(int port_, int button_, int axis_) : port(port_), button(button_) {} ~GCButton() override; @@ -31,17 +33,14 @@ private: class GCAxisButton final : public Input::ButtonDevice { public: - explicit GCAxisButton(int port_, int axis_, float threshold_, - bool trigger_if_greater_) - : port(port_), axis(axis_), threshold(threshold_), - trigger_if_greater(trigger_if_greater_) { + explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_) + : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_) { } - bool GetStatus() const override { const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f; if (trigger_if_greater) { - return axis_value > 0.10f; //TODO(ameerj) : Fix threshold. + return axis_value > 0.10f; // TODO(ameerj) : Fix threshold. } return axis_value < -0.10f; } @@ -164,29 +163,30 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { void GCButtonFactory::BeginConfiguration() { polling = true; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::BeginConfiguration(); } void GCButtonFactory::EndConfiguration() { polling = false; - - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::EndConfiguration(); } class GCAnalog final : public Input::AnalogDevice { public: GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_) - : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) { - } + : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {} float GetAxis(int axis) const { std::lock_guard lock{mutex}; // division is not by a perfect 128 to account for some variance in center location - // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range [20-230] + // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range + // [20-230] return (state[port].axes.at(axis) - 128.0f) / 95.0f; } @@ -240,18 +240,16 @@ private: mutable std::mutex mutex; }; - /// An analog device factory that creates analog devices from GC Adapter -GCAnalogFactory::GCAnalogFactory() {}; - +GCAnalogFactory::GCAnalogFactory(){}; /** -* Creates analog device from joystick axes -* @param params contains parameters for creating the device: -* - "port": the nth gcpad on the adapter -* - "axis_x": the index of the axis to be bind as x-axis -* - "axis_y": the index of the axis to be bind as y-axis -*/ + * Creates analog device from joystick axes + * @param params contains parameters for creating the device: + * - "port": the nth gcpad on the adapter + * - "axis_x": the index of the axis to be bind as x-axis + * - "axis_y": the index of the axis to be bind as y-axis + */ std::unique_ptr GCAnalogFactory::Create(const Common::ParamPackage& params) { const std::string guid = params.Get("guid", "0"); const int port = params.Get("port", 0); @@ -264,15 +262,17 @@ std::unique_ptr GCAnalogFactory::Create(const Common::Param void GCAnalogFactory::BeginConfiguration() { polling = true; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::BeginConfiguration(); } void GCAnalogFactory::EndConfiguration() { polling = false; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::EndConfiguration(); } diff --git a/src/input_common/gcadapter/gc_poller.h b/src/input_common/gcadapter/gc_poller.h index d115b1d2a..43aa9e93a 100644 --- a/src/input_common/gcadapter/gc_poller.h +++ b/src/input_common/gcadapter/gc_poller.h @@ -1,3 +1,7 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + #pragma once #include @@ -5,7 +9,6 @@ namespace InputCommon { - /** * A button device factory representing a gcpad. It receives gcpad events and forward them * to all button devices it created. diff --git a/src/input_common/main.h b/src/input_common/main.h index be2e7a6c4..9e1528c88 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h @@ -7,8 +7,8 @@ #include #include #include -#include "input_common/gcadapter/gc_poller.h" #include "input_common/gcadapter/gc_adapter.h" +#include "input_common/gcadapter/gc_poller.h" namespace Common { class ParamPackage; @@ -38,7 +38,6 @@ class GCAnalogFactory; GCButtonFactory* GetGCButtons(); GCAnalogFactory* GetGCAnalogs(); - /// Generates a serialized param package for creating a keyboard button device std::string GenerateKeyboardParam(int key_code); diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index da5227058..4c9794ce2 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -225,8 +225,7 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie } else { failure_callback(); } - }) - .detach(); + }).detach(); } CalibrationConfigurationJob::CalibrationConfigurationJob( @@ -280,8 +279,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( complete_event.Wait(); socket.Stop(); worker_thread.join(); - }) - .detach(); + }).detach(); } CalibrationConfigurationJob::~CalibrationConfigurationJob() { diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 81436af1b..c1a0c423b 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -19,13 +19,13 @@ #include "yuzu/configuration/configure_input_player.h" const std::array -ConfigureInputPlayer::analog_sub_buttons{{ - "up", - "down", - "left", - "right", - "modifier", -}}; + ConfigureInputPlayer::analog_sub_buttons{{ + "up", + "down", + "left", + "right", + "modifier", + }}; static void LayerGridElements(QGridLayout* grid, QWidget* item, QWidget* onTopOf) { const int index1 = grid->indexOf(item); @@ -151,13 +151,13 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i setFocusPolicy(Qt::ClickFocus); button_map = { - ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, - ui->buttonLStick, ui->buttonRStick, ui->buttonL, ui->buttonR, - ui->buttonZL, ui->buttonZR, ui->buttonPlus, ui->buttonMinus, - ui->buttonDpadLeft, ui->buttonDpadUp, ui->buttonDpadRight, ui->buttonDpadDown, + ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, + ui->buttonLStick, ui->buttonRStick, ui->buttonL, ui->buttonR, + ui->buttonZL, ui->buttonZR, ui->buttonPlus, ui->buttonMinus, + ui->buttonDpadLeft, ui->buttonDpadUp, ui->buttonDpadRight, ui->buttonDpadDown, ui->buttonLStickLeft, ui->buttonLStickUp, ui->buttonLStickRight, ui->buttonLStickDown, ui->buttonRStickLeft, ui->buttonRStickUp, ui->buttonRStickRight, ui->buttonRStickDown, - ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot, + ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot, }; analog_map_buttons = {{ @@ -178,11 +178,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i }}; debug_hidden = { - ui->buttonSL, ui->labelSL, - ui->buttonSR, ui->labelSR, - ui->buttonLStick, ui->labelLStickPressed, - ui->buttonRStick, ui->labelRStickPressed, - ui->buttonHome, ui->labelHome, + ui->buttonSL, ui->labelSL, + ui->buttonSR, ui->labelSR, + ui->buttonLStick, ui->labelLStickPressed, + ui->buttonRStick, ui->labelRStickPressed, + ui->buttonHome, ui->labelHome, ui->buttonScreenshot, ui->labelScreenshot, }; @@ -221,12 +221,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i case Settings::ControllerType::RightJoycon: layout_hidden = { ui->left_body_button, ui->left_buttons_button, - ui->left_body_label, ui->left_buttons_label, - ui->buttonL, ui->labelL, - ui->buttonZL, ui->labelZL, - ui->labelScreenshot, ui->buttonScreenshot, - ui->buttonMinus, ui->labelMinus, - ui->LStick, ui->Dpad, + ui->left_body_label, ui->left_buttons_label, + ui->buttonL, ui->labelL, + ui->buttonZL, ui->labelZL, + ui->labelScreenshot, ui->buttonScreenshot, + ui->buttonMinus, ui->labelMinus, + ui->LStick, ui->Dpad, }; break; } @@ -261,38 +261,34 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i } button->setContextMenuPolicy(Qt::CustomContextMenu); - connect(button, &QPushButton::clicked, [=] - { - HandleClick(button_map[button_id], - [=](Common::ParamPackage params) - { - // Workaround for ZL & ZR for analog triggers like on XBOX controllors. - // Analog triggers (from controllers like the XBOX controller) would not - // work due to a different range of their signals (from 0 to 255 on - // analog triggers instead of -32768 to 32768 on analog joysticks). The - // SDL driver misinterprets analog triggers as analog joysticks. - // TODO: reinterpret the signal range for analog triggers to map the - // values correctly. This is required for the correct emulation of the - // analog triggers of the GameCube controller. - if (button_id == Settings::NativeButton::ZL || - button_id == Settings::NativeButton::ZR) { - params.Set("direction", "+"); - params.Set("threshold", "0.5"); - } - buttons_param[button_id] = std::move(params); - }, - InputCommon::Polling::DeviceType::Button); + connect(button, &QPushButton::clicked, [=] { + HandleClick( + button_map[button_id], + [=](Common::ParamPackage params) { + // Workaround for ZL & ZR for analog triggers like on XBOX controllors. + // Analog triggers (from controllers like the XBOX controller) would not + // work due to a different range of their signals (from 0 to 255 on + // analog triggers instead of -32768 to 32768 on analog joysticks). The + // SDL driver misinterprets analog triggers as analog joysticks. + // TODO: reinterpret the signal range for analog triggers to map the + // values correctly. This is required for the correct emulation of the + // analog triggers of the GameCube controller. + if (button_id == Settings::NativeButton::ZL || + button_id == Settings::NativeButton::ZR) { + params.Set("direction", "+"); + params.Set("threshold", "0.5"); + } + buttons_param[button_id] = std::move(params); + }, + InputCommon::Polling::DeviceType::Button); }); - connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) - { + connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { QMenu context_menu; - context_menu.addAction(tr("Clear"), [&] - { + context_menu.addAction(tr("Clear"), [&] { buttons_param[button_id].Clear(); button_map[button_id]->setText(tr("[not set]")); }); - context_menu.addAction(tr("Restore Default"), [&] - { + context_menu.addAction(tr("Restore Default"), [&] { buttons_param[button_id] = Common::ParamPackage{ InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); @@ -309,27 +305,23 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i } analog_button->setContextMenuPolicy(Qt::CustomContextMenu); - connect(analog_button, &QPushButton::clicked, [=]() - { - HandleClick(analog_map_buttons[analog_id][sub_button_id], - [=](const Common::ParamPackage& params) - { - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); - }, - InputCommon::Polling::DeviceType::Button); + connect(analog_button, &QPushButton::clicked, [=]() { + HandleClick( + analog_map_buttons[analog_id][sub_button_id], + [=](const Common::ParamPackage& params) { + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + }, + InputCommon::Polling::DeviceType::Button); }); connect(analog_button, &QPushButton::customContextMenuRequested, - [=](const QPoint& menu_location) - { + [=](const QPoint& menu_location) { QMenu context_menu; - context_menu.addAction(tr("Clear"), [&] - { + context_menu.addAction(tr("Clear"), [&] { analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); }); - context_menu.addAction(tr("Restore Default"), [&] - { + context_menu.addAction(tr("Restore Default"), [&] { Common::ParamPackage params{InputCommon::GenerateKeyboardParam( Config::default_analogs[analog_id][sub_button_id])}; SetAnalogButton(params, analogs_param[analog_id], @@ -341,12 +333,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i menu_location)); }); } - connect(analog_map_stick[analog_id], &QPushButton::clicked, [=] - { + connect(analog_map_stick[analog_id], &QPushButton::clicked, [=] { if (QMessageBox::information( this, tr("Information"), tr("After pressing OK, first move your joystick horizontally, " - "and then vertically."), + "and then vertically."), QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { HandleClick( analog_map_stick[analog_id], @@ -355,8 +346,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i } }); - connect(analog_map_deadzone_and_modifier_slider[analog_id], &QSlider::valueChanged, [=] - { + connect(analog_map_deadzone_and_modifier_slider[analog_id], &QSlider::valueChanged, [=] { const float slider_value = analog_map_deadzone_and_modifier_slider[analog_id]->value(); if (analogs_param[analog_id].Get("engine", "") == "sdl" || analogs_param[analog_id].Get("engine", "") == "gcpad") { @@ -377,8 +367,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i timeout_timer->setSingleShot(true); connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); }); - connect(poll_timer.get(), &QTimer::timeout, [this] - { + connect(poll_timer.get(), &QTimer::timeout, [this] { Common::ParamPackage params; if (InputCommon::GetGCButtons()->IsPolling()) { params = InputCommon::GetGCButtons()->GetNextInput(); @@ -505,7 +494,7 @@ void ConfigureInputPlayer::LoadConfiguration() { for (std::size_t i = 0; i < colors.size(); ++i) { controller_color_buttons[i]->setStyleSheet( QStringLiteral("QPushButton { background-color: %1 }") - .arg(controller_colors[i].name())); + .arg(controller_colors[i].name())); } } @@ -625,10 +614,11 @@ void ConfigureInputPlayer::HandleClick( grabKeyboard(); grabMouse(); - if (type == InputCommon::Polling::DeviceType::Button) + if (type == InputCommon::Polling::DeviceType::Button) { InputCommon::GetGCButtons()->BeginConfiguration(); - else + } else { InputCommon::GetGCAnalogs()->BeginConfiguration(); + } timeout_timer->start(5000); // Cancel after 5 seconds poll_timer->start(200); // Check for new inputs every 200ms } diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h index dad2a80ec..95afa5375 100644 --- a/src/yuzu/configuration/configure_input_player.h +++ b/src/yuzu/configuration/configure_input_player.h @@ -31,7 +31,7 @@ class ConfigureInputPlayer; } class ConfigureInputPlayer : public QDialog { -Q_OBJECT + Q_OBJECT public: explicit ConfigureInputPlayer(QWidget* parent, std::size_t player_index, bool debug = false); @@ -92,15 +92,15 @@ private: /// A group of five QPushButtons represent one analog input. The buttons each represent up, /// down, left, right, and modifier, respectively. std::array, Settings::NativeAnalog::NumAnalogs> - analog_map_buttons; + analog_map_buttons; /// Analog inputs are also represented each with a single button, used to configure with an /// actual analog stick std::array analog_map_stick; std::array - analog_map_deadzone_and_modifier_slider; + analog_map_deadzone_and_modifier_slider; std::array - analog_map_deadzone_and_modifier_slider_label; + analog_map_deadzone_and_modifier_slider_label; static const std::array analog_sub_buttons; -- cgit v1.2.3 From 121af3646dad0f80453d2ffffa688dd4435d3acc Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 18:43:01 -0400 Subject: Singleton GC Adapter class, remove globals, fix naming convention Fix clang formatting Manual fix for configure_input_player formatting Add missing lib usb cmake command --- CMakeLists.txt | 6 + src/input_common/gcadapter/gc_adapter.cpp | 176 +++++++++++----------- src/input_common/gcadapter/gc_adapter.h | 145 ++++++++++++------ src/input_common/gcadapter/gc_poller.cpp | 125 +++++++-------- src/input_common/gcadapter/gc_poller.h | 3 + src/input_common/main.cpp | 2 + src/input_common/main.h | 4 +- src/input_common/udp/client.cpp | 6 +- src/yuzu/configuration/configure_input_player.cpp | 50 +++--- 9 files changed, 289 insertions(+), 228 deletions(-) (limited to 'src/yuzu') diff --git a/CMakeLists.txt b/CMakeLists.txt index b71071271..967968226 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -328,6 +328,12 @@ elseif(SDL2_FOUND) target_link_libraries(SDL2 INTERFACE "${SDL2_LIBRARIES}") endif() +# Ensure libusb is properly configured (based on dolphin libusb include) +find_package(LibUSB) +add_subdirectory(externals/libusb) +set(LIBUSB_LIBRARIES usb) + + # Prefer the -pthread flag on Linux. set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index dc04116ce..0696a96c7 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -3,45 +3,41 @@ // Refer to the license.txt file included. #include "common/logging/log.h" -#include "common/threadsafe_queue.h" #include "input_common/gcadapter/gc_adapter.h" -Common::SPSCQueue pad_queue[4]; -struct GCState state[4]; - namespace GCAdapter { +Adapter* Adapter::adapter_instance{nullptr}; -static libusb_device_handle* usb_adapter_handle = nullptr; -static u8 adapter_controllers_status[4] = { - ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE, - ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE}; - -static std::mutex s_mutex; - -static std::thread adapter_input_thread; -static bool adapter_thread_running; - -static std::mutex initialization_mutex; -static std::thread detect_thread; -static bool detect_thread_running = false; +Adapter::Adapter() { + if (usb_adapter_handle != nullptr) { + return; + } + LOG_INFO(Input, "GC Adapter Initialization started"); -static libusb_context* libusb_ctx; + current_status = NO_ADAPTER_DETECTED; + libusb_init(&libusb_ctx); -static u8 input_endpoint = 0; + StartScanThread(); +} -static bool configuring = false; +Adapter* Adapter::GetInstance() { + if (!adapter_instance) { + adapter_instance = new Adapter; + } + return adapter_instance; +} -GCPadStatus CheckStatus(int port, u8 adapter_payload[37]) { +GCPadStatus Adapter::CheckStatus(int port, u8 adapter_payload[37]) { GCPadStatus pad = {}; bool get_origin = false; - u8 type = adapter_payload[1 + (9 * port)] >> 4; - if (type) + ControllerTypes type = ControllerTypes(adapter_payload[1 + (9 * port)] >> 4); + if (type != ControllerTypes::None) get_origin = true; adapter_controllers_status[port] = type; - if (adapter_controllers_status[port] != ControllerTypes::CONTROLLER_NONE) { + if (adapter_controllers_status[port] != ControllerTypes::None) { u8 b1 = adapter_payload[1 + (9 * port) + 1]; u8 b2 = adapter_payload[1 + (9 * port) + 2]; @@ -88,18 +84,17 @@ GCPadStatus CheckStatus(int port, u8 adapter_payload[37]) { pad.button |= PAD_GET_ORIGIN; } - pad.stickX = adapter_payload[1 + (9 * port) + 3]; - pad.stickY = adapter_payload[1 + (9 * port) + 4]; - pad.substickX = adapter_payload[1 + (9 * port) + 5]; - pad.substickY = adapter_payload[1 + (9 * port) + 6]; - pad.triggerLeft = adapter_payload[1 + (9 * port) + 7]; - pad.triggerRight = adapter_payload[1 + (9 * port) + 8]; + pad.stick_x = adapter_payload[1 + (9 * port) + 3]; + pad.stick_y = adapter_payload[1 + (9 * port) + 4]; + pad.substick_x = adapter_payload[1 + (9 * port) + 5]; + pad.substick_y = adapter_payload[1 + (9 * port) + 6]; + pad.trigger_left = adapter_payload[1 + (9 * port) + 7]; + pad.trigger_right = adapter_payload[1 + (9 * port) + 8]; } return pad; } -void PadToState(GCPadStatus pad, GCState& state) { - // std::lock_guard lock{s_mutex}; +void Adapter::PadToState(GCPadStatus pad, GCState& state) { state.buttons.insert_or_assign(PAD_BUTTON_A, pad.button & PAD_BUTTON_A); state.buttons.insert_or_assign(PAD_BUTTON_B, pad.button & PAD_BUTTON_B); state.buttons.insert_or_assign(PAD_BUTTON_X, pad.button & PAD_BUTTON_X); @@ -112,15 +107,15 @@ void PadToState(GCPadStatus pad, GCState& state) { state.buttons.insert_or_assign(PAD_TRIGGER_Z, pad.button & PAD_TRIGGER_Z); state.buttons.insert_or_assign(PAD_TRIGGER_L, pad.button & PAD_TRIGGER_L); state.buttons.insert_or_assign(PAD_TRIGGER_R, pad.button & PAD_TRIGGER_R); - state.axes.insert_or_assign(STICK_X, pad.stickX); - state.axes.insert_or_assign(STICK_Y, pad.stickY); - state.axes.insert_or_assign(SUBSTICK_X, pad.substickX); - state.axes.insert_or_assign(SUBSTICK_Y, pad.substickY); - state.axes.insert_or_assign(TRIGGER_LEFT, pad.triggerLeft); - state.axes.insert_or_assign(TRIGGER_RIGHT, pad.triggerRight); + state.axes.insert_or_assign(static_cast(PadAxes::StickX), pad.stick_x); + state.axes.insert_or_assign(static_cast(PadAxes::StickY), pad.stick_y); + state.axes.insert_or_assign(static_cast(PadAxes::SubstickX), pad.substick_x); + state.axes.insert_or_assign(static_cast(PadAxes::SubstickY), pad.substick_y); + state.axes.insert_or_assign(static_cast(PadAxes::TriggerLeft), pad.trigger_left); + state.axes.insert_or_assign(static_cast(PadAxes::TriggerRight), pad.trigger_right); } -static void Read() { +void Adapter::Read() { LOG_INFO(Input, "GC Adapter Read() thread started"); int payload_size_in; @@ -145,8 +140,9 @@ static void Read() { LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size, controller_payload_copy[0]); } else { - for (int i = 0; i < 4; i++) - pad[i] = CheckStatus(i, controller_payload_copy); + for (int port = 0; port < 4; port++) { + pad[port] = CheckStatus(port, controller_payload_copy); + } } for (int port = 0; port < 4; port++) { if (DeviceConnected(port) && configuring) { @@ -155,28 +151,36 @@ static void Read() { } // Accounting for a threshold here because of some controller variance - if (pad[port].stickX > pad[port].MAIN_STICK_CENTER_X + pad[port].THRESHOLD || - pad[port].stickX < pad[port].MAIN_STICK_CENTER_X - pad[port].THRESHOLD) { - pad[port].axis_which = STICK_X; - pad[port].axis_value = pad[port].stickX; + if (pad[port].stick_x > + pad_constants.MAIN_STICK_CENTER_X + pad_constants.THRESHOLD || + pad[port].stick_x < + pad_constants.MAIN_STICK_CENTER_X - pad_constants.THRESHOLD) { + pad[port].axis = GCAdapter::PadAxes::StickX; + pad[port].axis_value = pad[port].stick_x; pad_queue[port].Push(pad[port]); } - if (pad[port].stickY > pad[port].MAIN_STICK_CENTER_Y + pad[port].THRESHOLD || - pad[port].stickY < pad[port].MAIN_STICK_CENTER_Y - pad[port].THRESHOLD) { - pad[port].axis_which = STICK_Y; - pad[port].axis_value = pad[port].stickY; + if (pad[port].stick_y > + pad_constants.MAIN_STICK_CENTER_Y + pad_constants.THRESHOLD || + pad[port].stick_y < + pad_constants.MAIN_STICK_CENTER_Y - pad_constants.THRESHOLD) { + pad[port].axis = GCAdapter::PadAxes::StickY; + pad[port].axis_value = pad[port].stick_y; pad_queue[port].Push(pad[port]); } - if (pad[port].substickX > pad[port].C_STICK_CENTER_X + pad[port].THRESHOLD || - pad[port].substickX < pad[port].C_STICK_CENTER_X - pad[port].THRESHOLD) { - pad[port].axis_which = SUBSTICK_X; - pad[port].axis_value = pad[port].substickX; + if (pad[port].substick_x > + pad_constants.C_STICK_CENTER_X + pad_constants.THRESHOLD || + pad[port].substick_x < + pad_constants.C_STICK_CENTER_X - pad_constants.THRESHOLD) { + pad[port].axis = GCAdapter::PadAxes::SubstickX; + pad[port].axis_value = pad[port].substick_x; pad_queue[port].Push(pad[port]); } - if (pad[port].substickY > pad[port].C_STICK_CENTER_Y + pad[port].THRESHOLD || - pad[port].substickY < pad[port].C_STICK_CENTER_Y - pad[port].THRESHOLD) { - pad[port].axis_which = SUBSTICK_Y; - pad[port].axis_value = pad[port].substickY; + if (pad[port].substick_y > + pad_constants.C_STICK_CENTER_Y + pad_constants.THRESHOLD || + pad[port].substick_y < + pad_constants.C_STICK_CENTER_Y - pad_constants.THRESHOLD) { + pad[port].axis = GCAdapter::PadAxes::SubstickY; + pad[port].axis_value = pad[port].substick_y; pad_queue[port].Push(pad[port]); } } @@ -186,7 +190,7 @@ static void Read() { } } -static void ScanThreadFunc() { +void Adapter::ScanThreadFunc() { LOG_INFO(Input, "GC Adapter scanning thread started"); while (detect_thread_running) { @@ -198,20 +202,7 @@ static void ScanThreadFunc() { } } -void Init() { - - if (usb_adapter_handle != nullptr) { - return; - } - LOG_INFO(Input, "GC Adapter Initialization started"); - - current_status = NO_ADAPTER_DETECTED; - libusb_init(&libusb_ctx); - - StartScanThread(); -} - -void StartScanThread() { +void Adapter::StartScanThread() { if (detect_thread_running) { return; } @@ -220,21 +211,21 @@ void StartScanThread() { } detect_thread_running = true; - detect_thread = std::thread(ScanThreadFunc); + detect_thread = std::thread([=] { ScanThreadFunc(); }); } -void StopScanThread() { +void Adapter::StopScanThread() { detect_thread.join(); } -static void Setup() { +void Adapter::Setup() { // Reset the error status in case the adapter gets unplugged if (current_status < 0) { current_status = NO_ADAPTER_DETECTED; } for (int i = 0; i < 4; i++) { - adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE; + adapter_controllers_status[i] = ControllerTypes::None; } libusb_device** devs; // pointer to list of connected usb devices @@ -250,7 +241,7 @@ static void Setup() { } } -static bool CheckDeviceAccess(libusb_device* device) { +bool Adapter::CheckDeviceAccess(libusb_device* device) { libusb_device_descriptor desc; int ret = libusb_get_device_descriptor(device, &desc); if (ret) { @@ -300,7 +291,7 @@ static bool CheckDeviceAccess(libusb_device* device) { return true; } -static void GetGCEndpoint(libusb_device* device) { +void Adapter::GetGCEndpoint(libusb_device* device) { libusb_config_descriptor* config = nullptr; libusb_get_config_descriptor(device, 0, &config); for (u8 ic = 0; ic < config->bNumInterfaces; ic++) { @@ -318,18 +309,17 @@ static void GetGCEndpoint(libusb_device* device) { adapter_thread_running = true; current_status = ADAPTER_DETECTED; - - adapter_input_thread = std::thread(Read); // Read input + adapter_input_thread = std::thread([=] { Read(); }); // Read input } -void Shutdown() { +Adapter::~Adapter() { StopScanThread(); Reset(); current_status = NO_ADAPTER_DETECTED; } -static void Reset() { +void Adapter::Reset() { std::unique_lock lock(initialization_mutex, std::defer_lock); if (!lock.try_lock()) { return; @@ -343,7 +333,7 @@ static void Reset() { } for (int i = 0; i < 4; i++) { - adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE; + adapter_controllers_status[i] = ControllerTypes::None; } current_status = NO_ADAPTER_DETECTED; @@ -355,20 +345,28 @@ static void Reset() { } } -bool DeviceConnected(int port) { - return adapter_controllers_status[port] != ControllerTypes::CONTROLLER_NONE; +bool Adapter::DeviceConnected(int port) { + return adapter_controllers_status[port] != ControllerTypes::None; } -void ResetDeviceType(int port) { - adapter_controllers_status[port] = ControllerTypes::CONTROLLER_NONE; +void Adapter::ResetDeviceType(int port) { + adapter_controllers_status[port] = ControllerTypes::None; } -void BeginConfiguration() { +void Adapter::BeginConfiguration() { configuring = true; } -void EndConfiguration() { +void Adapter::EndConfiguration() { configuring = false; } +std::array, 4>& Adapter::GetPadQueue() { + return pad_queue; +} + +std::array& Adapter::GetPadState() { + return state; +} + } // end of namespace GCAdapter diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 05ee73c65..3d5c41f9a 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -8,6 +8,9 @@ #include #include #include "common/common_types.h" +#include "common/threadsafe_queue.h" + +namespace GCAdapter { enum { PAD_USE_ORIGIN = 0x0080, @@ -33,29 +36,38 @@ enum PadButton { }; -enum PadAxes { STICK_X, STICK_Y, SUBSTICK_X, SUBSTICK_Y, TRIGGER_LEFT, TRIGGER_RIGHT }; +enum class PadAxes : u8 { + StickX, + StickY, + SubstickX, + SubstickY, + TriggerLeft, + TriggerRight, + Undefined, +}; +const struct GCPadConstants { + const u8 MAIN_STICK_CENTER_X = 0x80; + const u8 MAIN_STICK_CENTER_Y = 0x80; + const u8 MAIN_STICK_RADIUS = 0x7f; + const u8 C_STICK_CENTER_X = 0x80; + const u8 C_STICK_CENTER_Y = 0x80; + const u8 C_STICK_RADIUS = 0x7f; + + const u8 TRIGGER_CENTER = 20; + const u8 THRESHOLD = 10; +} pad_constants; struct GCPadStatus { - u16 button; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits - u8 stickX; // 0 <= stickX <= 255 - u8 stickY; // 0 <= stickY <= 255 - u8 substickX; // 0 <= substickX <= 255 - u8 substickY; // 0 <= substickY <= 255 - u8 triggerLeft; // 0 <= triggerLeft <= 255 - u8 triggerRight; // 0 <= triggerRight <= 255 - bool isConnected{true}; - - static const u8 MAIN_STICK_CENTER_X = 0x80; - static const u8 MAIN_STICK_CENTER_Y = 0x80; - static const u8 MAIN_STICK_RADIUS = 0x7f; - static const u8 C_STICK_CENTER_X = 0x80; - static const u8 C_STICK_CENTER_Y = 0x80; - static const u8 C_STICK_RADIUS = 0x7f; - - static const u8 TRIGGER_CENTER = 20; - static const u8 THRESHOLD = 10; + u16 button; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits + u8 stick_x; // 0 <= stick_x <= 255 + u8 stick_y; // 0 <= stick_y <= 255 + u8 substick_x; // 0 <= substick_x <= 255 + u8 substick_y; // 0 <= substick_y <= 255 + u8 trigger_left; // 0 <= trigger_left <= 255 + u8 trigger_right; // 0 <= trigger_right <= 255 + u8 port; - u8 axis_which = 255; + PadAxes axis = PadAxes::Undefined; u8 axis_value = 255; }; @@ -64,51 +76,88 @@ struct GCState { std::unordered_map axes; }; -namespace GCAdapter { -enum ControllerTypes { CONTROLLER_NONE = 0, CONTROLLER_WIRED = 1, CONTROLLER_WIRELESS = 2 }; +enum class ControllerTypes { None, Wired, Wireless }; enum { NO_ADAPTER_DETECTED = 0, ADAPTER_DETECTED = 1, }; -// Current adapter status: detected/not detected/in error (holds the error code) -static int current_status = NO_ADAPTER_DETECTED; +/// Singleton Adapter class +class Adapter { +public: + /// For retreiving the singleton instance + static Adapter* GetInstance(); + + /// Used for polling + void BeginConfiguration(); + void EndConfiguration(); + + std::array, 4>& GetPadQueue(); + std::array& GetPadState(); + +private: + /// Singleton instance. + static Adapter* adapter_instance; + + /// Initialize the GC Adapter capture and read sequence + Adapter(); -GCPadStatus CheckStatus(int port, u8 adapter_payload[37]); -/// Initialize the GC Adapter capture and read sequence -void Init(); + /// Close the adapter read thread and release the adapter + ~Adapter(); -/// Close the adapter read thread and release the adapter -void Shutdown(); + GCPadStatus CheckStatus(int port, u8 adapter_payload[37]); -/// Begin scanning for the GC Adapter. -void StartScanThread(); + void PadToState(GCPadStatus pad, GCState& state); -/// Stop scanning for the adapter -void StopScanThread(); + void Read(); + void ScanThreadFunc(); + /// Begin scanning for the GC Adapter. + void StartScanThread(); -/// Returns true if there is a device connected to port -bool DeviceConnected(int port); + /// Stop scanning for the adapter + void StopScanThread(); -/// Resets status of device connected to port -void ResetDeviceType(int port); + /// Returns true if there is a device connected to port + bool DeviceConnected(int port); -/// Returns true if we successfully gain access to GC Adapter -bool CheckDeviceAccess(libusb_device* device); + /// Resets status of device connected to port + void ResetDeviceType(int port); -/// Captures GC Adapter endpoint address, -void GetGCEndpoint(libusb_device* device); + /// Returns true if we successfully gain access to GC Adapter + bool CheckDeviceAccess(libusb_device* device); -/// For shutting down, clear all data, join all threads, release usb -void Reset(); + /// Captures GC Adapter endpoint address, + void GetGCEndpoint(libusb_device* device); -/// For use in initialization, querying devices to find the adapter -void Setup(); + /// For shutting down, clear all data, join all threads, release usb + void Reset(); -/// Used for polling -void BeginConfiguration(); + /// For use in initialization, querying devices to find the adapter + void Setup(); -void EndConfiguration(); + int current_status = NO_ADAPTER_DETECTED; + libusb_device_handle* usb_adapter_handle = nullptr; + ControllerTypes adapter_controllers_status[4] = {ControllerTypes::None, ControllerTypes::None, + ControllerTypes::None, ControllerTypes::None}; + + std::mutex s_mutex; + + std::thread adapter_input_thread; + bool adapter_thread_running; + + std::mutex initialization_mutex; + std::thread detect_thread; + bool detect_thread_running = false; + + libusb_context* libusb_ctx; + + u8 input_endpoint = 0; + + bool configuring = false; + + std::array, 4> pad_queue; + std::array state; +}; } // end of namespace GCAdapter diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 51b3362d6..0e591baca 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -10,35 +10,34 @@ #include "input_common/gcadapter/gc_adapter.h" #include "input_common/gcadapter/gc_poller.h" -// Using extern as to avoid multply defined symbols. -extern Common::SPSCQueue pad_queue[4]; -extern struct GCState state[4]; - namespace InputCommon { class GCButton final : public Input::ButtonDevice { public: - explicit GCButton(int port_, int button_, int axis_) : port(port_), button(button_) {} + explicit GCButton(int port_, int button_, int axis_, GCAdapter::Adapter* adapter) + : port(port_), button(button_), gcadapter(adapter) {} ~GCButton() override; bool GetStatus() const override { - return state[port].buttons.at(button); + return gcadapter->GetPadState()[port].buttons.at(button); } private: const int port; const int button; + GCAdapter::Adapter* gcadapter; }; class GCAxisButton final : public Input::ButtonDevice { public: - explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_) - : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_) { - } + explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, + GCAdapter::Adapter* adapter) + : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), + gcadapter(adapter) {} bool GetStatus() const override { - const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f; + const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; if (trigger_if_greater) { return axis_value > 0.10f; // TODO(ameerj) : Fix threshold. } @@ -50,14 +49,15 @@ private: const int axis; float threshold; bool trigger_if_greater; + GCAdapter::Adapter* gcadapter; }; GCButtonFactory::GCButtonFactory() { - GCAdapter::Init(); + adapter = GCAdapter::Adapter::GetInstance(); } GCButton::~GCButton() { - GCAdapter::Shutdown(); + // GCAdapter::Shutdown(); } std::unique_ptr GCButtonFactory::Create(const Common::ParamPackage& params) { @@ -77,76 +77,76 @@ std::unique_ptr GCButtonFactory::Create(const Common::Param trigger_if_greater = true; LOG_ERROR(Input, "Unknown direction {}", direction_name); } - return std::make_unique(port, axis, threshold, trigger_if_greater); + return std::make_unique(port, axis, threshold, trigger_if_greater, adapter); } std::unique_ptr button = - std::make_unique(port, button_id, params.Get("axis", 0)); + std::make_unique(port, button_id, params.Get("axis", 0), adapter); return std::move(button); } Common::ParamPackage GCButtonFactory::GetNextInput() { Common::ParamPackage params; - GCPadStatus pad; + GCAdapter::GCPadStatus pad; for (int i = 0; i < 4; i++) { - while (pad_queue[i].Pop(pad)) { + while (adapter->GetPadQueue()[i].Pop(pad)) { // This while loop will break on the earliest detected button params.Set("engine", "gcpad"); params.Set("port", i); // I was debating whether to keep these verbose for ease of reading // or to use a while loop shifting the bits to test and set the value. - if (pad.button & PAD_BUTTON_A) { - params.Set("button", PAD_BUTTON_A); + if (pad.button & GCAdapter::PAD_BUTTON_A) { + params.Set("button", GCAdapter::PAD_BUTTON_A); break; } - if (pad.button & PAD_BUTTON_B) { - params.Set("button", PAD_BUTTON_B); + if (pad.button & GCAdapter::PAD_BUTTON_B) { + params.Set("button", GCAdapter::PAD_BUTTON_B); break; } - if (pad.button & PAD_BUTTON_X) { - params.Set("button", PAD_BUTTON_X); + if (pad.button & GCAdapter::PAD_BUTTON_X) { + params.Set("button", GCAdapter::PAD_BUTTON_X); break; } - if (pad.button & PAD_BUTTON_Y) { - params.Set("button", PAD_BUTTON_Y); + if (pad.button & GCAdapter::PAD_BUTTON_Y) { + params.Set("button", GCAdapter::PAD_BUTTON_Y); break; } - if (pad.button & PAD_BUTTON_DOWN) { - params.Set("button", PAD_BUTTON_DOWN); + if (pad.button & GCAdapter::PAD_BUTTON_DOWN) { + params.Set("button", GCAdapter::PAD_BUTTON_DOWN); break; } - if (pad.button & PAD_BUTTON_LEFT) { - params.Set("button", PAD_BUTTON_LEFT); + if (pad.button & GCAdapter::PAD_BUTTON_LEFT) { + params.Set("button", GCAdapter::PAD_BUTTON_LEFT); break; } - if (pad.button & PAD_BUTTON_RIGHT) { - params.Set("button", PAD_BUTTON_RIGHT); + if (pad.button & GCAdapter::PAD_BUTTON_RIGHT) { + params.Set("button", GCAdapter::PAD_BUTTON_RIGHT); break; } - if (pad.button & PAD_BUTTON_UP) { - params.Set("button", PAD_BUTTON_UP); + if (pad.button & GCAdapter::PAD_BUTTON_UP) { + params.Set("button", GCAdapter::PAD_BUTTON_UP); break; } - if (pad.button & PAD_TRIGGER_L) { - params.Set("button", PAD_TRIGGER_L); + if (pad.button & GCAdapter::PAD_TRIGGER_L) { + params.Set("button", GCAdapter::PAD_TRIGGER_L); break; } - if (pad.button & PAD_TRIGGER_R) { - params.Set("button", PAD_TRIGGER_R); + if (pad.button & GCAdapter::PAD_TRIGGER_R) { + params.Set("button", GCAdapter::PAD_TRIGGER_R); break; } - if (pad.button & PAD_TRIGGER_Z) { - params.Set("button", PAD_TRIGGER_Z); + if (pad.button & GCAdapter::PAD_TRIGGER_Z) { + params.Set("button", GCAdapter::PAD_TRIGGER_Z); break; } - if (pad.button & PAD_BUTTON_START) { - params.Set("button", PAD_BUTTON_START); + if (pad.button & GCAdapter::PAD_BUTTON_START) { + params.Set("button", GCAdapter::PAD_BUTTON_START); break; } // For Axis button implementation - if (pad.axis_which != 255) { - params.Set("axis", pad.axis_which); - params.Set("button", PAD_STICK); + if (pad.axis != GCAdapter::PadAxes::Undefined) { + params.Set("axis", static_cast(pad.axis)); + params.Set("button", GCAdapter::PAD_STICK); if (pad.axis_value > 128) { params.Set("direction", "+"); params.Set("threshold", "0.5"); @@ -164,30 +164,30 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { void GCButtonFactory::BeginConfiguration() { polling = true; for (int i = 0; i < 4; i++) { - pad_queue[i].Clear(); + adapter->GetPadQueue()[i].Clear(); } - GCAdapter::BeginConfiguration(); + adapter->BeginConfiguration(); } void GCButtonFactory::EndConfiguration() { polling = false; for (int i = 0; i < 4; i++) { - pad_queue[i].Clear(); + adapter->GetPadQueue()[i].Clear(); } - GCAdapter::EndConfiguration(); + adapter->EndConfiguration(); } class GCAnalog final : public Input::AnalogDevice { public: - GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_) - : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {} + GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, GCAdapter::Adapter* adapter) + : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} float GetAxis(int axis) const { std::lock_guard lock{mutex}; // division is not by a perfect 128 to account for some variance in center location // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range // [20-230] - return (state[port].axes.at(axis) - 128.0f) / 95.0f; + return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; } std::tuple GetAnalog(int axis_x, int axis_y) const { @@ -238,10 +238,13 @@ private: const int axis_y; const float deadzone; mutable std::mutex mutex; + GCAdapter::Adapter* gcadapter; }; /// An analog device factory that creates analog devices from GC Adapter -GCAnalogFactory::GCAnalogFactory(){}; +GCAnalogFactory::GCAnalogFactory() { + adapter = GCAdapter::Adapter::GetInstance(); +}; /** * Creates analog device from joystick axes @@ -257,35 +260,36 @@ std::unique_ptr GCAnalogFactory::Create(const Common::Param const int axis_y = params.Get("axis_y", 1); const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, .99f); - return std::make_unique(port, axis_x, axis_y, deadzone); + return std::make_unique(port, axis_x, axis_y, deadzone, adapter); } void GCAnalogFactory::BeginConfiguration() { polling = true; for (int i = 0; i < 4; i++) { - pad_queue[i].Clear(); + adapter->GetPadQueue()[i].Clear(); } - GCAdapter::BeginConfiguration(); + adapter->BeginConfiguration(); } void GCAnalogFactory::EndConfiguration() { polling = false; for (int i = 0; i < 4; i++) { - pad_queue[i].Clear(); + adapter->GetPadQueue()[i].Clear(); } - GCAdapter::EndConfiguration(); + adapter->EndConfiguration(); } Common::ParamPackage GCAnalogFactory::GetNextInput() { - GCPadStatus pad; + GCAdapter::GCPadStatus pad; for (int i = 0; i < 4; i++) { - while (pad_queue[i].Pop(pad)) { - if (pad.axis_which == 255 || std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { + while (adapter->GetPadQueue()[i].Pop(pad)) { + if (pad.axis == GCAdapter::PadAxes::Undefined || + std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { continue; } // An analog device needs two axes, so we need to store the axis for later and wait for // a second SDL event. The axes also must be from the same joystick. - const int axis = pad.axis_which; + const u8 axis = static_cast(pad.axis); if (analog_x_axis == -1) { analog_x_axis = axis; controller_number = i; @@ -307,4 +311,5 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { } return params; } + } // namespace InputCommon diff --git a/src/input_common/gcadapter/gc_poller.h b/src/input_common/gcadapter/gc_poller.h index 43aa9e93a..29b8c0b7c 100644 --- a/src/input_common/gcadapter/gc_poller.h +++ b/src/input_common/gcadapter/gc_poller.h @@ -35,6 +35,7 @@ public: } private: + GCAdapter::Adapter* adapter; bool polling = false; }; @@ -54,9 +55,11 @@ public: } private: + GCAdapter::Adapter* adapter; int analog_x_axis = -1; int analog_y_axis = -1; int controller_number = -1; bool polling = false; }; + } // namespace InputCommon diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 7fc0e2db4..536e5c80a 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -2,11 +2,13 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include #include #include "common/param_package.h" #include "input_common/analog_from_button.h" +#include "input_common/gcadapter/gc_adapter.h" #include "input_common/gcadapter/gc_poller.h" #include "input_common/keyboard.h" #include "input_common/main.h" diff --git a/src/input_common/main.h b/src/input_common/main.h index 9e1528c88..c26222f21 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h @@ -32,10 +32,8 @@ class MotionEmu; /// Gets the motion emulation factory. MotionEmu* GetMotionEmu(); -class GCButtonFactory; -class GCAnalogFactory; - GCButtonFactory* GetGCButtons(); + GCAnalogFactory* GetGCAnalogs(); /// Generates a serialized param package for creating a keyboard button device diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 4c9794ce2..da5227058 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -225,7 +225,8 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie } else { failure_callback(); } - }).detach(); + }) + .detach(); } CalibrationConfigurationJob::CalibrationConfigurationJob( @@ -279,7 +280,8 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( complete_event.Wait(); socket.Stop(); worker_thread.join(); - }).detach(); + }) + .detach(); } CalibrationConfigurationJob::~CalibrationConfigurationJob() { diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index c1a0c423b..c7d3f4510 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -262,25 +262,24 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i button->setContextMenuPolicy(Qt::CustomContextMenu); connect(button, &QPushButton::clicked, [=] { - HandleClick( - button_map[button_id], - [=](Common::ParamPackage params) { - // Workaround for ZL & ZR for analog triggers like on XBOX controllors. - // Analog triggers (from controllers like the XBOX controller) would not - // work due to a different range of their signals (from 0 to 255 on - // analog triggers instead of -32768 to 32768 on analog joysticks). The - // SDL driver misinterprets analog triggers as analog joysticks. - // TODO: reinterpret the signal range for analog triggers to map the - // values correctly. This is required for the correct emulation of the - // analog triggers of the GameCube controller. - if (button_id == Settings::NativeButton::ZL || - button_id == Settings::NativeButton::ZR) { - params.Set("direction", "+"); - params.Set("threshold", "0.5"); - } - buttons_param[button_id] = std::move(params); - }, - InputCommon::Polling::DeviceType::Button); + HandleClick(button_map[button_id], + [=](Common::ParamPackage params) { + // Workaround for ZL & ZR for analog triggers like on XBOX controllors. + // Analog triggers (from controllers like the XBOX controller) would not + // work due to a different range of their signals (from 0 to 255 on + // analog triggers instead of -32768 to 32768 on analog joysticks). The + // SDL driver misinterprets analog triggers as analog joysticks. + // TODO: reinterpret the signal range for analog triggers to map the + // values correctly. This is required for the correct emulation of the + // analog triggers of the GameCube controller. + if (button_id == Settings::NativeButton::ZL || + button_id == Settings::NativeButton::ZR) { + params.Set("direction", "+"); + params.Set("threshold", "0.5"); + } + buttons_param[button_id] = std::move(params); + }, + InputCommon::Polling::DeviceType::Button); }); connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { QMenu context_menu; @@ -306,13 +305,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i analog_button->setContextMenuPolicy(Qt::CustomContextMenu); connect(analog_button, &QPushButton::clicked, [=]() { - HandleClick( - analog_map_buttons[analog_id][sub_button_id], - [=](const Common::ParamPackage& params) { - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); - }, - InputCommon::Polling::DeviceType::Button); + HandleClick(analog_map_buttons[analog_id][sub_button_id], + [=](const Common::ParamPackage& params) { + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + }, + InputCommon::Polling::DeviceType::Button); }); connect(analog_button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { -- cgit v1.2.3 From 901bc09dd7ee1ae90e2cbbc454cd039a1825b80d Mon Sep 17 00:00:00 2001 From: Ameer Date: Mon, 22 Jun 2020 22:02:50 -0400 Subject: Small quality of life indication that mapped button is GC --- src/yuzu/configuration/configure_input_player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/yuzu') diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index c7d3f4510..1d7418122 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -75,11 +75,11 @@ static QString ButtonToText(const Common::ParamPackage& param) { const QString axis_str = QString::fromStdString(param.Get("axis", "")); const QString direction_str = QString::fromStdString(param.Get("direction", "")); - return QObject::tr("Axis %1%2").arg(axis_str, direction_str); + return QObject::tr("GC Axis %1%2").arg(axis_str, direction_str); } if (param.Has("button")) { const QString button_str = QString::number(int(std::log2(param.Get("button", 0)))); - return QObject::tr("Button %1").arg(button_str); + return QObject::tr("GC Button %1").arg(button_str); } return GetKeyName(param.Get("code", 0)); } -- cgit v1.2.3 From 6b7c8e469b2d7943cd7771648659bc362e5d1ddd Mon Sep 17 00:00:00 2001 From: Ameer Date: Thu, 2 Jul 2020 15:54:44 -0400 Subject: Add LR triggers as axes, half press to initiate a press, add GC axis id in config, clarify some code blocks for better readability --- src/input_common/gcadapter/gc_adapter.cpp | 12 ++++ src/input_common/gcadapter/gc_poller.cpp | 32 ++++++---- src/yuzu/configuration/configure_input_player.cpp | 71 +++++++++++++++-------- 3 files changed, 80 insertions(+), 35 deletions(-) (limited to 'src/yuzu') diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 1ddb9cdb4..82f97572f 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -144,6 +144,18 @@ void Adapter::Read() { pads[port].axis_value = pads[port].substick_y; pad_queue[port].Push(pads[port]); } + if (pads[port].trigger_left > pads[port].TRIGGER_CENTER + pads[port].THRESHOLD || + pads[port].trigger_left < pads[port].TRIGGER_CENTER - pads[port].THRESHOLD) { + pads[port].axis = GCAdapter::PadAxes::TriggerLeft; + pads[port].axis_value = pads[port].trigger_left; + pad_queue[port].Push(pads[port]); + } + if (pads[port].trigger_right > pads[port].TRIGGER_CENTER + pads[port].THRESHOLD || + pads[port].trigger_right < pads[port].TRIGGER_CENTER - pads[port].THRESHOLD) { + pads[port].axis = GCAdapter::PadAxes::TriggerRight; + pads[port].axis_value = pads[port].trigger_right; + pad_queue[port].Push(pads[port]); + } } PadToState(pads[port], state[port]); } diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index a9de9fedf..a04c507b8 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -34,7 +34,13 @@ public: explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, GCAdapter::Adapter* adapter) : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), - gcadapter(adapter) {} + gcadapter(adapter) { + // L/R triggers range is only in positive direction beginning near 0 + // 0.0 threshold equates to near half trigger press, but threshold accounts for variability. + if (axis > 3) { + threshold *= -0.5; + } + } bool GetStatus() const override { const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; @@ -60,10 +66,20 @@ GCButton::~GCButton() = default; std::unique_ptr GCButtonFactory::Create(const Common::ParamPackage& params) { const int button_id = params.Get("button", 0); const int port = params.Get("port", 0); + + constexpr int PAD_STICK_ID = static_cast(GCAdapter::PadButton::PAD_STICK); + + // button is not an axis/stick button + if (button_id != PAD_STICK_ID) { + std::unique_ptr button = + std::make_unique(port, button_id, params.Get("axis", 0), adapter.get()); + return std::move(button); + } + // For Axis buttons, used by the binary sticks. - if (params.Has("axis")) { + if (button_id == PAD_STICK_ID) { const int axis = params.Get("axis", 0); - const float threshold = params.Get("threshold", 0.5f); + const float threshold = params.Get("threshold", 0.25f); const std::string direction_name = params.Get("direction", ""); bool trigger_if_greater; if (direction_name == "+") { @@ -77,10 +93,6 @@ std::unique_ptr GCButtonFactory::Create(const Common::Param return std::make_unique(port, axis, threshold, trigger_if_greater, adapter.get()); } - - std::unique_ptr button = - std::make_unique(port, button_id, params.Get("axis", 0), adapter.get()); - return std::move(button); } Common::ParamPackage GCButtonFactory::GetNextInput() { @@ -106,10 +118,10 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { params.Set("button", static_cast(GCAdapter::PadButton::PAD_STICK)); if (pad.axis_value > 128) { params.Set("direction", "+"); - params.Set("threshold", "0.5"); + params.Set("threshold", "0.25"); } else { params.Set("direction", "-"); - params.Set("threshold", "-0.5"); + params.Set("threshold", "-0.25"); } break; } @@ -232,7 +244,7 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { continue; } // An analog device needs two axes, so we need to store the axis for later and wait for - // a second SDL event. The axes also must be from the same joystick. + // a second input event. The axes also must be from the same joystick. const u8 axis = static_cast(pad.axis); if (analog_x_axis == -1) { analog_x_axis = axis; diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 1d7418122..49b8c8386 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -120,7 +120,7 @@ static QString AnalogToText(const Common::ParamPackage& param, const std::string return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); } - if (param.Get("engine", "") == "sdl" || param.Get("engine", "") == "gcpad") { + if (param.Get("engine", "") == "sdl") { if (dir == "modifier") { return QObject::tr("[unused]"); } @@ -140,6 +140,25 @@ static QString AnalogToText(const Common::ParamPackage& param, const std::string return {}; } + if (param.Get("engine", "") == "gcpad") { + if (dir == "modifier") { + return QObject::tr("[unused]"); + } + + if (dir == "left" || dir == "right") { + const QString axis_x_str = QString::fromStdString(param.Get("axis_x", "")); + + return QObject::tr("GC Axis %1").arg(axis_x_str); + } + + if (dir == "up" || dir == "down") { + const QString axis_y_str = QString::fromStdString(param.Get("axis_y", "")); + + return QObject::tr("GC Axis %1").arg(axis_y_str); + } + + return {}; + } return QObject::tr("[unknown]"); } @@ -262,24 +281,25 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i button->setContextMenuPolicy(Qt::CustomContextMenu); connect(button, &QPushButton::clicked, [=] { - HandleClick(button_map[button_id], - [=](Common::ParamPackage params) { - // Workaround for ZL & ZR for analog triggers like on XBOX controllors. - // Analog triggers (from controllers like the XBOX controller) would not - // work due to a different range of their signals (from 0 to 255 on - // analog triggers instead of -32768 to 32768 on analog joysticks). The - // SDL driver misinterprets analog triggers as analog joysticks. - // TODO: reinterpret the signal range for analog triggers to map the - // values correctly. This is required for the correct emulation of the - // analog triggers of the GameCube controller. - if (button_id == Settings::NativeButton::ZL || - button_id == Settings::NativeButton::ZR) { - params.Set("direction", "+"); - params.Set("threshold", "0.5"); - } - buttons_param[button_id] = std::move(params); - }, - InputCommon::Polling::DeviceType::Button); + HandleClick( + button_map[button_id], + [=](Common::ParamPackage params) { + // Workaround for ZL & ZR for analog triggers like on XBOX controllors. + // Analog triggers (from controllers like the XBOX controller) would not + // work due to a different range of their signals (from 0 to 255 on + // analog triggers instead of -32768 to 32768 on analog joysticks). The + // SDL driver misinterprets analog triggers as analog joysticks. + // TODO: reinterpret the signal range for analog triggers to map the + // values correctly. This is required for the correct emulation of the + // analog triggers of the GameCube controller. + if (button_id == Settings::NativeButton::ZL || + button_id == Settings::NativeButton::ZR) { + params.Set("direction", "+"); + params.Set("threshold", "0.5"); + } + buttons_param[button_id] = std::move(params); + }, + InputCommon::Polling::DeviceType::Button); }); connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { QMenu context_menu; @@ -305,12 +325,13 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i analog_button->setContextMenuPolicy(Qt::CustomContextMenu); connect(analog_button, &QPushButton::clicked, [=]() { - HandleClick(analog_map_buttons[analog_id][sub_button_id], - [=](const Common::ParamPackage& params) { - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); - }, - InputCommon::Polling::DeviceType::Button); + HandleClick( + analog_map_buttons[analog_id][sub_button_id], + [=](const Common::ParamPackage& params) { + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + }, + InputCommon::Polling::DeviceType::Button); }); connect(analog_button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { -- cgit v1.2.3 From 6e1639c7b004d13aba77549131ecee793fcc4065 Mon Sep 17 00:00:00 2001 From: Ameer Date: Thu, 2 Jul 2020 16:51:16 -0400 Subject: Fix unnecessary diffs --- src/input_common/keyboard.cpp | 3 +- src/input_common/main.cpp | 2 + src/input_common/sdl/sdl_impl.cpp | 1 - src/yuzu/configuration/configure_input_player.cpp | 50 +++++++++++------------ 4 files changed, 27 insertions(+), 29 deletions(-) (limited to 'src/yuzu') diff --git a/src/input_common/keyboard.cpp b/src/input_common/keyboard.cpp index eb6c3112b..afb8e6612 100644 --- a/src/input_common/keyboard.cpp +++ b/src/input_common/keyboard.cpp @@ -49,9 +49,8 @@ public: void ChangeKeyStatus(int key_code, bool pressed) { std::lock_guard guard{mutex}; for (const KeyButtonPair& pair : list) { - if (pair.key_code == key_code) { + if (pair.key_code == key_code) pair.key_button->status.store(pressed); - } } } diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index f13420b38..fd0af1019 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -45,6 +45,7 @@ void Init() { #ifdef HAVE_SDL2 sdl = SDL::Init(); #endif + udp = CemuhookUDP::Init(); } @@ -111,6 +112,7 @@ std::vector> GetPollers(DeviceType type) { #ifdef HAVE_SDL2 pollers = sdl->GetPollers(type); #endif + return pollers; } diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 6b264f2a6..675b477fa 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp @@ -444,7 +444,6 @@ private: class SDLAnalogFactory final : public Input::Factory { public: explicit SDLAnalogFactory(SDLState& state_) : state(state_) {} - /** * Creates analog device from joystick axes * @param params contains parameters for creating the device: diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 49b8c8386..00433926d 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -281,25 +281,24 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i button->setContextMenuPolicy(Qt::CustomContextMenu); connect(button, &QPushButton::clicked, [=] { - HandleClick( - button_map[button_id], - [=](Common::ParamPackage params) { - // Workaround for ZL & ZR for analog triggers like on XBOX controllors. - // Analog triggers (from controllers like the XBOX controller) would not - // work due to a different range of their signals (from 0 to 255 on - // analog triggers instead of -32768 to 32768 on analog joysticks). The - // SDL driver misinterprets analog triggers as analog joysticks. - // TODO: reinterpret the signal range for analog triggers to map the - // values correctly. This is required for the correct emulation of the - // analog triggers of the GameCube controller. - if (button_id == Settings::NativeButton::ZL || - button_id == Settings::NativeButton::ZR) { - params.Set("direction", "+"); - params.Set("threshold", "0.5"); - } - buttons_param[button_id] = std::move(params); - }, - InputCommon::Polling::DeviceType::Button); + HandleClick(button_map[button_id], + [=](Common::ParamPackage params) { + // Workaround for ZL & ZR for analog triggers like on XBOX controllors. + // Analog triggers (from controllers like the XBOX controller) would not + // work due to a different range of their signals (from 0 to 255 on + // analog triggers instead of -32768 to 32768 on analog joysticks). The + // SDL driver misinterprets analog triggers as analog joysticks. + // TODO: reinterpret the signal range for analog triggers to map the + // values correctly. This is required for the correct emulation of the + // analog triggers of the GameCube controller. + if (button_id == Settings::NativeButton::ZL || + button_id == Settings::NativeButton::ZR) { + params.Set("direction", "+"); + params.Set("threshold", "0.5"); + } + buttons_param[button_id] = std::move(params); + }, + InputCommon::Polling::DeviceType::Button); }); connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { QMenu context_menu; @@ -325,13 +324,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i analog_button->setContextMenuPolicy(Qt::CustomContextMenu); connect(analog_button, &QPushButton::clicked, [=]() { - HandleClick( - analog_map_buttons[analog_id][sub_button_id], - [=](const Common::ParamPackage& params) { - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); - }, - InputCommon::Polling::DeviceType::Button); + HandleClick(analog_map_buttons[analog_id][sub_button_id], + [=](const Common::ParamPackage& params) { + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + }, + InputCommon::Polling::DeviceType::Button); }); connect(analog_button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { -- cgit v1.2.3