From cc826a7cc6e329a31547f8b7d1d0606bd35dae6d Mon Sep 17 00:00:00 2001 From: Netsplits Date: Sat, 3 Jul 2021 13:38:30 +0200 Subject: [PATCH] Update focus position value only if really changed --- src/SwitchInput.cpp | 9 +++++---- src/SwitchInput.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/SwitchInput.cpp b/src/SwitchInput.cpp index e7d36b2..7ef9de3 100644 --- a/src/SwitchInput.cpp +++ b/src/SwitchInput.cpp @@ -290,10 +290,11 @@ void RotaryEncoder::increment(int8_t incVal) { } // otherwise run through all the possibilities + uint16_t v; if(incVal >= 0) { if(currentReading != maximumValue) { - currentReading = min((uint16_t)(currentReading + incVal), maximumValue); - callback(currentReading); + v = min((uint16_t)(currentReading + incVal), maximumValue); + if (callback(v)) currentReading = v; } } else if(currentReading != 0 && currentReading < abs(incVal)) { @@ -301,8 +302,8 @@ void RotaryEncoder::increment(int8_t incVal) { callback(currentReading); } else if(currentReading != 0) { - currentReading += incVal; - callback(currentReading); + v = currentReading + incVal; + if (callback(v)) currentReading = v; } } diff --git a/src/SwitchInput.h b/src/SwitchInput.h index 0d822eb..9e41473 100644 --- a/src/SwitchInput.h +++ b/src/SwitchInput.h @@ -89,7 +89,7 @@ typedef void(*KeyCallbackFn)(pinid_t key, bool heldDown); * The signature of a callback function for rotary encoders, registered when initialising the encoder setupUpDownButtonEncoder * @param newValue the value the encoder changed to */ -typedef void(*EncoderCallbackFn)(int newValue); +typedef bool(*EncoderCallbackFn)(int newValue); /** * An internal class that represents the state of a single key being managed by switches.