|
18 | 18 | /// @version 1.0.1 change CAPS Enums
|
19 | 19 | ///
|
20 | 20 | /// @date 2022-14-11
|
21 |
| -/// @version 1.1.0 The ButtonSL class can now provide a status after the specified time period |
| 21 | +/// @version 1.1.0 The ButtonSL class can now provide a status after the specified time period |
22 | 22 | /// for a long button press, even if the button remains permanently pressed.
|
23 | 23 | ///
|
24 | 24 | /// @date 2023-12-06
|
25 | 25 | /// @version 1.1.4 Repeated debounce in the button class removed.
|
26 | 26 | ///
|
| 27 | +/// @date 2024-07-06 |
| 28 | +/// @version 1.1.5 The autorelease is only executed once as long as the button has not been released. |
| 29 | +/// Previously, if the button was held down continuously, the autorelease was executed |
| 30 | +/// every time the time for a long button press expired. |
| 31 | +/// |
27 | 32 | /// @copyright Copyright (c) 2022
|
28 | 33 | /// MIT license, check license.md for more information
|
29 | 34 | /// All text above must be included in any redistribution
|
@@ -58,7 +63,7 @@ bool Button::tick() {
|
58 | 63 | case HIGH:
|
59 | 64 | if (millis() - timeStamp > dbTime_ms) {
|
60 | 65 | // If the button press is equal to the specified debounce time, confirm the button press with true.
|
61 |
| - flag = true; |
| 66 | + flag = true; |
62 | 67 | }
|
63 | 68 | break;
|
64 | 69 | }
|
@@ -87,15 +92,16 @@ ButtonState ButtonSL::tick() {
|
87 | 92 | state = digitalRead(pin);
|
88 | 93 | if (state == activeState && compareState != activeState) {
|
89 | 94 | timeStamp = now;
|
| 95 | + hasReleased = false; |
90 | 96 | } else if (state != activeState && compareState == activeState) {
|
91 | 97 | timeStamp = now - timeStamp;
|
92 | 98 | if (timeStamp >= dbTime_ms && !hasReleased) { // released after debounce time?
|
93 | 99 | return (timeStamp >= time_ms) ? ButtonState::longPressed : ButtonState::shortPressed;
|
94 | 100 | }
|
95 |
| - hasReleased = false; |
96 |
| - } else if (release && (compareState == activeState)) { |
| 101 | + // hasReleased = false; |
| 102 | + } else if (autoRelease && not hasReleased && (compareState == activeState)) { |
97 | 103 | if (now - timeStamp >= time_ms) {
|
98 |
| - state = !compareState; |
| 104 | + // state = !compareState; |
99 | 105 | hasReleased = true;
|
100 | 106 | timeStamp = time_ms;
|
101 | 107 | return ButtonState::longPressed;
|
|
0 commit comments