From 71d748ef041b5f3181bbe880b37dc290ea9e14b9 Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Sun, 21 Feb 2021 16:12:41 -0800 Subject: [PATCH] AnalogController: Fix regression in analog mode toggling --- src/core/analog_controller.cpp | 51 ++++++++++++++++++++-------------- src/core/analog_controller.h | 1 + 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index 58dccc3b3..1dc86ae76 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -130,7 +130,12 @@ void AnalogController::SetButtonState(Button button, bool pressed) { // analog toggle if (pressed) - m_analog_toggle_queued = true; + { + if (m_command == Command::Idle) + ProcessAnalogModeToggle(); + else + m_analog_toggle_queued = true; + } return; } @@ -197,26 +202,7 @@ void AnalogController::ResetTransferState() { if (m_analog_toggle_queued) { - if (m_analog_locked) - { - g_host_interface->AddFormattedOSDMessage( - 5.0f, - m_analog_mode ? - g_host_interface->TranslateString("AnalogController", "Controller %u is locked to analog mode by the game.") : - g_host_interface->TranslateString("AnalogController", "Controller %u is locked to digital mode by the game."), - m_index + 1u); - } - else - { - SetAnalogMode(!m_analog_mode); - - // Manually toggling controller mode resets and disables rumble configuration - m_rumble_unlocked = false; - ResetRumbleConfig(); - - // TODO: Mode switch detection (0x00 returned on certain commands instead of 0x5A) - } - + ProcessAnalogModeToggle(); m_analog_toggle_queued = false; } @@ -238,6 +224,29 @@ void AnalogController::SetAnalogMode(bool enabled) m_analog_mode = enabled; } +void AnalogController::ProcessAnalogModeToggle() +{ + if (m_analog_locked) + { + g_host_interface->AddFormattedOSDMessage( + 5.0f, + m_analog_mode ? + g_host_interface->TranslateString("AnalogController", "Controller %u is locked to analog mode by the game.") : + g_host_interface->TranslateString("AnalogController", "Controller %u is locked to digital mode by the game."), + m_index + 1u); + } + else + { + SetAnalogMode(!m_analog_mode); + + // Manually toggling controller mode resets and disables rumble configuration + m_rumble_unlocked = false; + ResetRumbleConfig(); + + // TODO: Mode switch detection (0x00 returned on certain commands instead of 0x5A) + } +} + void AnalogController::SetMotorState(u8 motor, u8 value) { DebugAssert(motor < NUM_MOTORS); diff --git a/src/core/analog_controller.h b/src/core/analog_controller.h index fdd45ae0b..96cb6a6b9 100644 --- a/src/core/analog_controller.h +++ b/src/core/analog_controller.h @@ -111,6 +111,7 @@ private: constexpr u8 GetStatusByte() const { return 0x5A; }; void SetAnalogMode(bool enabled); + void ProcessAnalogModeToggle(); void SetMotorState(u8 motor, u8 value); u8 GetExtraButtonMaskLSB() const; void ResetRumbleConfig();