From e4820bcbc105e3d2dafe1f9dcfebf5f1add34e8e Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Mon, 23 Nov 2020 17:35:34 -0800 Subject: [PATCH] AnalogController: Delay manual mode toggle to transfer state reset --- src/core/analog_controller.cpp | 36 +++++++++++++++++++--------------- src/core/analog_controller.h | 2 ++ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index dc0e9ac6e..f165cf0a3 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -102,22 +102,7 @@ void AnalogController::SetButtonState(Button button, bool pressed) { // analog toggle if (pressed) - { - 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); - } - } + m_analog_toggle_queued = true; return; } @@ -158,6 +143,25 @@ float AnalogController::GetVibrationMotorStrength(u32 motor) 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); + } + + m_analog_toggle_queued = false; + } + m_state = State::Idle; } diff --git a/src/core/analog_controller.h b/src/core/analog_controller.h index 2cf96fae1..21cbe635f 100644 --- a/src/core/analog_controller.h +++ b/src/core/analog_controller.h @@ -149,6 +149,8 @@ private: std::array(Axis::Count)> m_axis_state{}; + bool m_analog_toggle_queued = false; + // buttons are active low u16 m_button_state = UINT16_C(0xFFFF);