Skip to content

Commit

Permalink
Change L2/R2 input threshold from >0 to separate on/off thresholds ab…
Browse files Browse the repository at this point in the history
…ove 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.
  • Loading branch information
j committed Aug 22, 2024
1 parent 834a25f commit d80899a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/input/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit d80899a

Please sign in to comment.