NeGcon: Add steering axis deadzone setting

This commit is contained in:
Albert Liu 2020-10-31 23:52:00 -07:00
parent b5b1c725c1
commit 3b51b993f3
3 changed files with 28 additions and 1 deletions

View File

@ -216,6 +216,9 @@ Controller::SettingList Controller::GetSettings(ControllerType type)
case ControllerType::NamcoGunCon: case ControllerType::NamcoGunCon:
return NamcoGunCon::StaticGetSettings(); return NamcoGunCon::StaticGetSettings();
case ControllerType::NeGcon:
return NeGcon::StaticGetSettings();
default: default:
return {}; return {};
} }

View File

@ -52,7 +52,11 @@ void NeGcon::SetAxisState(s32 axis_code, float value)
// Steering Axis: -1..1 -> 0..255 // Steering Axis: -1..1 -> 0..255
if (axis_code == static_cast<s32>(Axis::Steering)) if (axis_code == static_cast<s32>(Axis::Steering))
{ {
const u8 u8_value = static_cast<u8>(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<u8>(std::clamp(((float_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f));
SetAxisState(static_cast<Axis>(axis_code), u8_value); SetAxisState(static_cast<Axis>(axis_code), u8_value);
@ -242,3 +246,18 @@ u32 NeGcon::StaticGetVibrationMotorCount()
{ {
return 0; return 0;
} }
Controller::SettingList NeGcon::StaticGetSettings()
{
static constexpr std::array<SettingInfo, 1> 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);
}

View File

@ -39,6 +39,7 @@ public:
static AxisList StaticGetAxisNames(); static AxisList StaticGetAxisNames();
static ButtonList StaticGetButtonNames(); static ButtonList StaticGetButtonNames();
static u32 StaticGetVibrationMotorCount(); static u32 StaticGetVibrationMotorCount();
static SettingList StaticGetSettings();
ControllerType GetType() const override; ControllerType GetType() const override;
std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const override; std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const override;
@ -56,6 +57,8 @@ public:
void SetAxisState(Axis axis, u8 value); void SetAxisState(Axis axis, u8 value);
void SetButtonState(Button button, bool pressed); void SetButtonState(Button button, bool pressed);
void LoadSettings(const char* section) override;
private: private:
enum class TransferState : u8 enum class TransferState : u8
{ {
@ -75,4 +78,6 @@ private:
u16 m_button_state = UINT16_C(0xFFFF); u16 m_button_state = UINT16_C(0xFFFF);
TransferState m_transfer_state = TransferState::Idle; TransferState m_transfer_state = TransferState::Idle;
float m_steering_deadzone = 0.00f;
}; };