From 35fe951dfdea82a77d7ec6591dd91d37639aa283 Mon Sep 17 00:00:00 2001 From: Ivanovich <108089081+ivanao92@users.noreply.github.com> Date: Tue, 7 Jan 2025 00:18:51 -0300 Subject: [PATCH] Fix: Correct comment for push() and add setSwitchDebounceDelay(int) The comment for push() function was mistakenly copied from the rotate() function, leading to inaccurate documentation. Updated the comment to accurately describe the behavior of push(). Additionally, added the setSwitchDebounceDelay(int) function to allow customizing the debounce time for the switch, while maintaining compatibility with existing projects. --- src/SimpleRotary.cpp | 34 ++++++++++++++++++++++++++-------- src/SimpleRotary.h | 1 + 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/SimpleRotary.cpp b/src/SimpleRotary.cpp index e8e2a59..3e8a724 100644 --- a/src/SimpleRotary.cpp +++ b/src/SimpleRotary.cpp @@ -79,6 +79,25 @@ void SimpleRotary::setDebounceDelay(int i) } +/** + SET SWITCH DEBOUNCE DELAY + Sets the debounce delay time for the encoder's switch in milliseconds. + + This number shold be set as small as possible to maintain responsiveness while avoiding spurious activations. + Higher values can cause missed inputs, especially with fast or repeated presses. + Finding this value will vary from one rotary encoder to another and can be found simply with + trial and error. + + You can turn this feature off by setting the delay value to 0. + + @since v1.1.4; +**/ +void SimpleRotary::setSwitchDebounceDelay(int i) +{ + _debounceSDelay = i; +} + + /** SET ERROR CORRECTION DELAY Sets the error correction delay delay time in milliseconds. @@ -143,15 +162,14 @@ byte SimpleRotary::rotate() /** GET BUTTON PUSH - Gets the status of the pushbutton + Gets the status of the switch. - Returned values - 0x00 = Not turned. - 0x01 = Clockwise; - 0x02 = Counter-Clockwise - - @since v0.1; - @return byte, value of turned knob. + Returned values: + 0x00 = Button not pressed. + 0x01 = Button pressed. + + @since v0.1 + @return byte, status of the switch. **/ byte SimpleRotary::push(){ _updateTime(); diff --git a/src/SimpleRotary.h b/src/SimpleRotary.h index c69756c..fe0c76c 100644 --- a/src/SimpleRotary.h +++ b/src/SimpleRotary.h @@ -14,6 +14,7 @@ class SimpleRotary byte pushType(int i); void setTrigger(byte i); void setDebounceDelay(int i); + void setSwitchDebounceDelay(int i); void setErrorDelay(int i); void resetPush();