From 3b51b993f3d32ba868484f0f3413976c40816eee Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:52:00 -0700 Subject: [PATCH] NeGcon: Add steering axis deadzone setting --- src/core/controller.cpp | 3 +++ src/core/negcon.cpp | 21 ++++++++++++++++++++- src/core/negcon.h | 5 +++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/core/controller.cpp b/src/core/controller.cpp index b83d66ac7..6f99ba320 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -216,6 +216,9 @@ Controller::SettingList Controller::GetSettings(ControllerType type) case ControllerType::NamcoGunCon: return NamcoGunCon::StaticGetSettings(); + case ControllerType::NeGcon: + return NeGcon::StaticGetSettings(); + default: return {}; } diff --git a/src/core/negcon.cpp b/src/core/negcon.cpp index 0c20318b1..a12367633 100644 --- a/src/core/negcon.cpp +++ b/src/core/negcon.cpp @@ -52,7 +52,11 @@ void NeGcon::SetAxisState(s32 axis_code, float value) // Steering Axis: -1..1 -> 0..255 if (axis_code == static_cast(Axis::Steering)) { - const u8 u8_value = static_cast(std::clamp(((value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f)); + const float float_value = + (std::abs(value) < m_steering_deadzone) ? + 0.0f : + std::copysign((std::abs(value) - m_steering_deadzone) / (1.0f - m_steering_deadzone), value); + const u8 u8_value = static_cast(std::clamp(((float_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f)); SetAxisState(static_cast(axis_code), u8_value); @@ -242,3 +246,18 @@ u32 NeGcon::StaticGetVibrationMotorCount() { return 0; } + +Controller::SettingList NeGcon::StaticGetSettings() +{ + static constexpr std::array settings = { + {SettingInfo::Type::Float, "SteeringDeadzone", TRANSLATABLE("NeGcon", "Steering Axis Deadzone"), + TRANSLATABLE("NeGcon", "Sets deadzone size for steering axis."), "0.00f", "0.00f", "0.99f", "0.01f"}}; + + return SettingList(settings.begin(), settings.end()); +} + +void NeGcon::LoadSettings(const char* section) +{ + Controller::LoadSettings(section); + m_steering_deadzone = g_host_interface->GetFloatSettingValue(section, "SteeringDeadzone", 0.10f); +} diff --git a/src/core/negcon.h b/src/core/negcon.h index 0ff3388ef..4dff225ea 100644 --- a/src/core/negcon.h +++ b/src/core/negcon.h @@ -39,6 +39,7 @@ public: static AxisList StaticGetAxisNames(); static ButtonList StaticGetButtonNames(); static u32 StaticGetVibrationMotorCount(); + static SettingList StaticGetSettings(); ControllerType GetType() const override; std::optional GetAxisCodeByName(std::string_view axis_name) const override; @@ -56,6 +57,8 @@ public: void SetAxisState(Axis axis, u8 value); void SetButtonState(Button button, bool pressed); + void LoadSettings(const char* section) override; + private: enum class TransferState : u8 { @@ -75,4 +78,6 @@ private: u16 m_button_state = UINT16_C(0xFFFF); TransferState m_transfer_state = TransferState::Idle; + + float m_steering_deadzone = 0.00f; };