From 13844686151283e6175b2a70e1b4db333db9dfe8 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 29 Apr 2024 00:50:02 +1000 Subject: [PATCH] JogCon: Add ForceFeedbackDevice binding --- src/core/jogcon.cpp | 18 ++++++++++++++++++ src/core/jogcon.h | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/src/core/jogcon.cpp b/src/core/jogcon.cpp index 3556991d3..dd6dc8a62 100644 --- a/src/core/jogcon.cpp +++ b/src/core/jogcon.cpp @@ -869,8 +869,13 @@ static const Controller::ControllerBindingInfo s_binding_info[] = { AXIS("RRight", TRANSLATE_NOOP("JogCon", "Right Stick Right"), ICON_PF_RIGHT_ANALOG_RIGHT, JogCon::HalfAxis::RRight, GenericInputBinding::RightStickRight), AXIS("RDown", TRANSLATE_NOOP("JogCon", "Right Stick Down"), ICON_PF_RIGHT_ANALOG_DOWN, JogCon::HalfAxis::RDown, GenericInputBinding::RightStickDown), AXIS("RUp", TRANSLATE_NOOP("JogCon", "Right Stick Up"), ICON_PF_RIGHT_ANALOG_UP, JogCon::HalfAxis::RUp, GenericInputBinding::RightStickUp), + // clang-format on + {"ForceFeedbackDevice", TRANSLATE_NOOP("JogCon", "Force Feedback Device"), nullptr, + static_cast(JogCon::Button::Count) + static_cast(JogCon::HalfAxis::Count), InputBindingInfo::Type::Device, + GenericInputBinding::Unknown}, + #undef AXIS #undef BUTTON }; @@ -935,4 +940,17 @@ void JogCon::LoadSettings(SettingsInterface& si, const char* section) m_rumble_bias = static_cast(std::min(si.GetIntValue(section, "VibrationBias", 8), 255)); m_invert_left_stick = static_cast(si.GetIntValue(section, "InvertLeftStick", 0)); m_invert_right_stick = static_cast(si.GetIntValue(section, "InvertRightStick", 0)); + + std::string force_feedback_device_name = si.GetStringValue(section, "ForceFeedbackDevice"); + if (m_force_feedback_device_name != force_feedback_device_name) + { + m_force_feedback_device_name = std::move(force_feedback_device_name); + m_force_feedback_device.reset(); + if (!m_force_feedback_device_name.empty()) + { + m_force_feedback_device = InputManager::CreateForceFeedbackDevice(m_force_feedback_device_name); + if (!m_force_feedback_device) + Log_ErrorFmt("Failed to create force feedback device {}", m_force_feedback_device_name); + } + } } diff --git a/src/core/jogcon.h b/src/core/jogcon.h index 792be6e26..94d18cb85 100644 --- a/src/core/jogcon.h +++ b/src/core/jogcon.h @@ -8,6 +8,8 @@ #include #include +class ForceFeedbackDevice; + class JogCon final : public Controller { public: @@ -189,4 +191,7 @@ private: JogconDirection jog_direction = JogconDirection::JOGCON_DIR_NONE; u8 jog_rotations = 0x0; JogconCommand jog_last_command = JogconCommand::JOGCON_CMD_NONE; + + std::string m_force_feedback_device_name; + std::unique_ptr m_force_feedback_device; };