From a7503d79a986ea84cdecd5b08ca42c59218442b1 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 22 Aug 2024 19:31:00 +1000 Subject: [PATCH 1/3] Change L2/R2 input threshold from >0 to separate on/off thresholds above 127. This should fix the "only works once" issue and also avoid glitches. Tested with xbox controller and keyboard. Add TRACE-level logging for this. --- src/input/controller.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/input/controller.cpp b/src/input/controller.cpp index 4a3db16332..afc92176be 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -5,6 +5,7 @@ #include "core/libraries/kernel/time_management.h" #include "core/libraries/pad/pad.h" #include "input/controller.h" +#include "common/logging/log.h" namespace Input { @@ -99,18 +100,32 @@ void GameController::Axis(int id, Input::Axis axis, int value) { state.axes[axis_id] = value; + // Scaled value is 0 .. 255 + // Rest point for L2/R2 is usually ~127 but may drift + // It may also differ across controllers + // Use some hysteresis to avoid glitches. 0->255 will also work just slightly later + + const int ON_THRESHOLD = 150; + const int OFF_THRESHOLD = 135; + if (axis == Input::Axis::TriggerLeft) { - if (value > 0) { + LOG_TRACE(Input, "TriggerLeft {}", value); + if (value > ON_THRESHOLD) { + LOG_TRACE(Input, "L2 ON"); state.buttonsState |= Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L2; - } else { + } else if (value < OFF_THRESHOLD) { + LOG_TRACE(Input, "L2 OFF"); state.buttonsState &= ~Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L2; } } if (axis == Input::Axis::TriggerRight) { - if (value > 0) { + LOG_TRACE(Input, "TriggerRight {}", value); + if (value > ON_THRESHOLD) { + LOG_TRACE(Input, "R2 ON"); state.buttonsState |= Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R2; - } else { + } else if (value < OFF_THRESHOLD) { + LOG_TRACE(Input, "R2 OFF"); state.buttonsState &= ~Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R2; } } From 86a64648c5e8e2d81c958be3695733cb88f8b399 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 23 Aug 2024 15:24:00 +1000 Subject: [PATCH 2/3] Adjust L2/R2 button thresholds --- src/input/controller.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/input/controller.cpp b/src/input/controller.cpp index afc92176be..6104e4c5c6 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -100,13 +100,13 @@ void GameController::Axis(int id, Input::Axis axis, int value) { state.axes[axis_id] = value; + // Derive digital buttons from the analog trigger // Scaled value is 0 .. 255 - // Rest point for L2/R2 is usually ~127 but may drift - // It may also differ across controllers - // Use some hysteresis to avoid glitches. 0->255 will also work just slightly later + // Rest point for L2/R2 is ideally 0 but may drift + // Use some hysteresis to avoid glitches - const int ON_THRESHOLD = 150; - const int OFF_THRESHOLD = 135; + const int ON_THRESHOLD = 31; // 255 / 8 + const int OFF_THRESHOLD = 16; // 255 / 16 + 1 if (axis == Input::Axis::TriggerLeft) { LOG_TRACE(Input, "TriggerLeft {}", value); From 3ad4ff9c215616e4aa1c79284f4d795b627df68f Mon Sep 17 00:00:00 2001 From: j Date: Sun, 25 Aug 2024 13:02:17 +1000 Subject: [PATCH 3/3] formatting --- src/input/controller.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/input/controller.cpp b/src/input/controller.cpp index 6104e4c5c6..bbc5fb02f6 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -2,10 +2,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include "common/logging/log.h" #include "core/libraries/kernel/time_management.h" #include "core/libraries/pad/pad.h" #include "input/controller.h" -#include "common/logging/log.h" namespace Input { @@ -105,7 +105,7 @@ void GameController::Axis(int id, Input::Axis axis, int value) { // Rest point for L2/R2 is ideally 0 but may drift // Use some hysteresis to avoid glitches - const int ON_THRESHOLD = 31; // 255 / 8 + const int ON_THRESHOLD = 31; // 255 / 8 const int OFF_THRESHOLD = 16; // 255 / 16 + 1 if (axis == Input::Axis::TriggerLeft) {