From debfd53618a7949d4d5aec5dd05ae1d215cbd244 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 17 Sep 2020 19:56:26 +1000 Subject: [PATCH] AnalogController: Use range for large motor, add bias Seems the bias is needed for FF8. --- src/core/analog_controller.cpp | 19 +++++++++++++++---- src/core/analog_controller.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index 686fe0bad..0c5267dde 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -138,7 +138,12 @@ u32 AnalogController::GetVibrationMotorCount() const float AnalogController::GetVibrationMotorStrength(u32 motor) { DebugAssert(motor < NUM_MOTORS); - return static_cast(m_motor_state[motor]) * (1.0f / 255.0f); + if (m_motor_state[motor] == 0) + return 0.0f; + + return static_cast( + std::min(static_cast(m_motor_state[motor]) + static_cast(m_rumble_bias), 255)) / + 255.0f; } void AnalogController::ResetTransferState() @@ -282,7 +287,7 @@ bool AnalogController::Transfer(const u8 data_in, u8* data_out) case State::GetStateButtonsMSB: { if (m_rumble_unlocked) - SetMotorState(0, (data_in != 0) ? 255 : 0); + SetMotorState(0, data_in); *data_out = Truncate8(m_button_state >> 8); m_state = m_analog_mode ? State::GetStateRightAxisX : State::Idle; @@ -500,7 +505,7 @@ u32 AnalogController::StaticGetVibrationMotorCount() Controller::SettingList AnalogController::StaticGetSettings() { - static constexpr std::array settings = { + static constexpr std::array settings = { {{SettingInfo::Type::Boolean, "AutoEnableAnalog", TRANSLATABLE("AnalogController", "Enable Analog Mode on Reset"), TRANSLATABLE("AnalogController", "Automatically enables analog mode when the console is reset/powered on."), "false"}, @@ -509,7 +514,11 @@ Controller::SettingList AnalogController::StaticGetSettings() "AnalogController", "Sets the analog stick axis scaling factor. A value between 1.30 and 1.40 is recommended when using recent " "controllers, e.g. DualShock 4, Xbox One Controller."), - "1.00f", "0.01f", "1.50f", "0.01f"}}}; + "1.00f", "0.01f", "1.50f", "0.01f"}, + {SettingInfo::Type::Integer, "VibrationBias", TRANSLATABLE("AnalogController", "Vibration Bias"), + TRANSLATABLE("AnalogController", "Sets the rumble bias value. If rumble in some games is too weak or not " + "functioning, try increasing this value."), + "8", "0", "255", "1"}}}; return SettingList(settings.begin(), settings.end()); } @@ -518,4 +527,6 @@ void AnalogController::LoadSettings(const char* section) { Controller::LoadSettings(section); m_auto_enable_analog = g_host_interface->GetBoolSettingValue(section, "AutoEnableAnalog", false); + m_rumble_bias = + static_cast(std::min(g_host_interface->GetIntSettingValue(section, "VibrationBias", false), 255)); } diff --git a/src/core/analog_controller.h b/src/core/analog_controller.h index 1774b4305..c4995b1a1 100644 --- a/src/core/analog_controller.h +++ b/src/core/analog_controller.h @@ -135,6 +135,7 @@ private: u32 m_index; bool m_auto_enable_analog = false; + u8 m_rumble_bias = 8; bool m_analog_mode = false; bool m_analog_locked = false;