From 70d7bdd3b2b43e7b7ba09984a298606b8af9dbbd Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Tue, 21 Dec 2021 04:58:17 +0000 Subject: [PATCH] Tick threshold should be a reflection of the actual change in the encoder's value. --- Button.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Button.cpp b/Button.cpp index 4fbe3d9..b47ed9c 100644 --- a/Button.cpp +++ b/Button.cpp @@ -127,10 +127,9 @@ bool EncoderButton::Update(Joystick* js) { bool changed = false; long new_value = encoder->read(); - if (new_value > last_value) { - ticks++; - } else if (new_value < last_value) { - ticks--; + if (new_value != last_value) { + ticks += last_value - new_value; + last_value = new_value; } if (ticks >= tick_threshold) { @@ -146,6 +145,5 @@ bool EncoderButton::Update(Joystick* js) { ticks = 0; } - last_value = new_value; return changed; }