Merge pull request #1031 from ggrtk/negcon-deadzone

NeGcon: Add steering axis deadzone setting
This commit is contained in:
Connor McLaughlin 2020-11-02 00:52:27 +10:00 committed by GitHub
commit 79aa1cece7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View file

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

View file

@ -52,7 +52,11 @@ void NeGcon::SetAxisState(s32 axis_code, float value)
// Steering Axis: -1..1 -> 0..255
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);
@ -242,3 +246,18 @@ u32 NeGcon::StaticGetVibrationMotorCount()
{
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 ButtonList StaticGetButtonNames();
static u32 StaticGetVibrationMotorCount();
static SettingList StaticGetSettings();
ControllerType GetType() 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 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;
};