11/* ***********************************************
2- Toggle Library for Arduino - Version 3.1.0
2+ Toggle Library for Arduino - Version 3.1.1
33 by dlloydev https://github.com/Dlloydev/Toggle
44 Licensed under the MIT License.
55 ************************************************/
@@ -167,7 +167,7 @@ uint32_t Toggle::getElapsedMs() {
167167 return (micros () - startUs) * 0.001 ;
168168}
169169
170- uint8_t Toggle::pressCode () {
170+ uint8_t Toggle::pressCode (bool debug ) {
171171 static uint8_t pCode = 0 , code = 0 ;
172172 static uint32_t elapsedMs = 0 ;
173173
@@ -179,14 +179,16 @@ uint8_t Toggle::pressCode() {
179179 case PB_DEFAULT:
180180 setTimerMode (2 ); // onChange
181181 elapsedMs = getElapsedMs ();
182- if (pCode && ( elapsedMs > CLICK::LONG)) _state = PB_DONE;
182+ if (pCode && isReleased () && ( elapsedMs > ( CLICK::LONG + CLICK::MULTI) )) _state = PB_DONE;
183183 if (onChange ()) startUs = micros ();
184184 if (onPress ()) {
185- // Serial.print(F(" releasedMs: ")); Serial.print(elapsedMs); Serial.print(F(" ") );
185+ // Serial.print(F(" Released:\t ")); Serial.print(elapsedMs); Serial.println(" ms" );
186186 _state = PB_ON_PRESS;
187187 }
188188 if (onRelease ()) {
189- // Serial.print(F(" pressedMs: ")); Serial.print(elapsedMs); Serial.print(F(" "));
189+ if (debug) {
190+ Serial.print (F (" Pressed:\t " )); Serial.print (elapsedMs); Serial.println (" ms" );
191+ }
190192 _state = PB_ON_RELEASE;
191193 }
192194 break ;
@@ -218,24 +220,26 @@ uint8_t Toggle::pressCode() {
218220 break ;
219221
220222 case PB_DONE:
223+ if (debug) {
224+ Serial.print (F (" Code:\t\t " )); Serial.println (pCode, HEX); Serial.println ();
225+ }
221226 code = pCode;
222227 pCode = 0 ;
223228 _state = PB_DEFAULT;
224- return code;
229+ if (code) return code;
225230 break ;
226231
227232 default :
228233 _state = PB_DEFAULT;
229234 break ;
230235 }
231- return code ;
236+ return 0 ;
232237}
233238
234- /* ************* debouncer ***********************************************************************
239+ /* ************* debouncer ************************************************************************
235240 The debounceInput() function by default uses a robust algorithm that ignores up to 2 spurious
236241 signal transitions (glitches) and only adds up to 2 sample periods time lag to the output signal.
237- Optionally, this can be changed to 1 glitch with 1 sample lag or to immediate response mode.
238- *************************************************************************************************/
242+ **************************************************************************************************/
239243uint8_t Toggle::debounceInput (uint8_t bit) {
240244 pOut = out;
241245 uint8_t a, b, c, bits = 2 ;
0 commit comments