diff --git a/Examples/SwitchCallbackExample/SwitchCallbackExample.ino b/Examples/SwitchCallbackExample/SwitchCallbackExample.ino index c23a832..5c3826f 100644 --- a/Examples/SwitchCallbackExample/SwitchCallbackExample.ino +++ b/Examples/SwitchCallbackExample/SwitchCallbackExample.ino @@ -1,15 +1,11 @@ #include "Arduino.h" #include "avdweb_Switch.h" -const byte toggleSwitchpin = 13; -const byte buttonGNDpin = 4; -const byte ButtonVCCpin = 2; -const byte Button10mspin = 12; +const byte toggleSwitchpin = 4; +const byte multiresponseButtonpin = 12; -Switch buttonGND = Switch(buttonGNDpin); // button to GND, use internal 20K pullup resistor Switch toggleSwitch = Switch(toggleSwitchpin); -Switch buttonVCC = Switch(ButtonVCCpin, INPUT, HIGH); // button to VCC, 10k pull-down resistor, no internal pull-up resistor, HIGH polarity -Switch button10ms = Switch(Button10mspin, INPUT_PULLUP, LOW, 1); // debounceTime 1ms +Switch multiresponseButton = Switch(multiresponseButtonpin); void buttonCallbackFunction(void* s) { Serial.print("Button: "); @@ -24,15 +20,16 @@ void toggleCallbackFunction(void* s) { void setup() { Serial.begin(9600); - buttonGND.setPushedCallback(&buttonCallbackFunction, (void*)"pushed"); - buttonGND.setReleasedCallback(&buttonCallbackFunction, (void*)"released"); + toggleSwitch.setPushedCallback(&toggleCallbackFunction, (void*)"turned on"); + toggleSwitch.setReleasedCallback(&toggleCallbackFunction, (void*)"turned off"); - toggleSwitch.setLongPressCallback(&toggleCallbackFunction, (void*)"long press"); - toggleSwitch.setDoubleClickCallback(&toggleCallbackFunction, (void*)"double click"); + multiresponseButton.setLongPressCallback(&buttonCallbackFunction, (void*)"long press"); + multiresponseButton.setDoubleClickCallback(&buttonCallbackFunction, (void*)"double click"); + multiresponseButton.setSingleClickCallback(&buttonCallbackFunction, (void*)"single click"); } void loop() { - buttonGND.poll(); toggleSwitch.poll(); + multiresponseButton.poll(); } diff --git a/Examples/SwitchExample/SwitchExample.ino b/Examples/SwitchExample/SwitchExample.ino new file mode 100644 index 0000000..e9c260a --- /dev/null +++ b/Examples/SwitchExample/SwitchExample.ino @@ -0,0 +1,46 @@ +#include "Arduino.h" +#include "avdweb_Switch.h" + +const byte pushButtonpin = 2; +const byte toggleSwitchpin = 4; +const byte multiresponseButtonpin = 12; +const byte alleventsButtonpin = 13; +int i; + +Switch pushButton = Switch(pushButtonpin); // button to GND, use internal 20K pullup resistor +Switch toggleSwitch = Switch(toggleSwitchpin); +Switch multiresponseButton = Switch(multiresponseButtonpin); +Switch alleventsButton = Switch(alleventsButtonpin); +// Other examples of constructors +// Switch pushButtonVCC = Switch(pushButtonpin, INPUT, HIGH); // button to VCC, 10k pull-down resistor, no internal pull-up resistor, HIGH polarity +// Switch pushButton1ms = Switch(pushButtonpin, INPUT_PULLUP, LOW, 1); // debounceTime 1ms + +void setup() +{ Serial.begin(9600); +} + +void loop() +{ // pushButton simple events + pushButton.poll(); + if(pushButton.switched()) Serial.print("pushButton switched "); + if(pushButton.pushed()) {Serial.print("pushButton pushed "); Serial.print(++i); Serial.println(" times");} + if(pushButton.released()) Serial.println("pushButton released"); + + // toggleSwitch report status only when changed + if(toggleSwitch.poll()) {Serial.print("toggleSwitch status changed to "); Serial.println(toggleSwitch.on());} + + // multiresponseButton complex events + multiresponseButton.poll(); + if(multiresponseButton.longPress()) Serial.println("multiresponseButton longPress"); + if(multiresponseButton.doubleClick()) Serial.println("multiresponseButton doubleClick"); + if(multiresponseButton.singleClick()) Serial.println("multiresponseButton singleClick"); + + // alleventsButton complex events + alleventsButton.poll(); + if(alleventsButton.switched()) {Serial.println("all_e_B switched."); Serial.print(" all_e_B status to "); Serial.print(alleventsButton.on()); Serial.println(".");} + if(alleventsButton.pushed()) {Serial.println(" all_e_B pushed.");} + if(alleventsButton.released()) Serial.println(" all_e_B released."); + if(alleventsButton.longPress()) Serial.println(" ==> all_e_B longPress."); + if(alleventsButton.doubleClick()) Serial.println(" ==> all_e_B doubleClick."); + if(alleventsButton.singleClick()) Serial.println(" ==> all_e_B singleClick."); +} diff --git a/Examples/Test_switch/Test_switch.ino b/Examples/Test_switch/Test_switch.ino deleted file mode 100644 index 43b39c3..0000000 --- a/Examples/Test_switch/Test_switch.ino +++ /dev/null @@ -1,30 +0,0 @@ -#include "Arduino.h" -#include "avdweb_Switch.h" - -const byte toggleSwitchpin = 13; -const byte buttonGNDpin = 4; -const byte ButtonVCCpin = 2; -const byte Button10mspin = 12; -int i; - -Switch buttonGND = Switch(buttonGNDpin); // button to GND, use internal 20K pullup resistor -Switch toggleSwitch = Switch(toggleSwitchpin); -Switch buttonVCC = Switch(ButtonVCCpin, INPUT, HIGH); // button to VCC, 10k pull-down resistor, no internal pull-up resistor, HIGH polarity -Switch button10ms = Switch(Button10mspin, INPUT_PULLUP, LOW, 1); // debounceTime 1ms - -void setup() -{ Serial.begin(9600); -} - -void loop() -{ buttonGND.poll(); - if(buttonGND.switched()) Serial.print("switched "); - if(buttonGND.pushed()) {Serial.print("pushed "); Serial.print(++i); Serial.print(" ");} - if(buttonGND.released()) Serial.println("released"); - - if(toggleSwitch.poll()) Serial.println(toggleSwitch.on()); - if(toggleSwitch.longPress()) Serial.print("longPress1 "); - if(toggleSwitch.longPress()) Serial.println("longPress2"); - if(toggleSwitch.doubleClick()) Serial.print("doubleClick1 "); - if(toggleSwitch.doubleClick()) Serial.println("doubleClick2"); -} diff --git a/README.md b/README.md index 4368993..85cece9 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Available at: https://github.com/avandalen/avdweb_Switch #### General features of the Switch library - Performs not just de-bouncing, but also de-glitching against EMC pulses. - External pull-up resistors are not required. -- Supports also long press and double click detection. +- Supports also long press, double click, and single click detection. - Callback functions. ## Introduction @@ -52,7 +52,7 @@ It returns "true" if the pin voltage agrees with the one defined by `polarity` ( #### pushed() -It returns "true" if a button was pushed (switched towards the on position). Use only for push buttons. Note that this is in fact "single-click". +It returns "true" if a button was pushed (switched towards the on position). Use only for push buttons. Note that this provides instant response and can be used as "single-click" if "double-click" and "long-press" are not watched events. "Pushed" occurs simultaneously with "double-click" and "long-press". #### released() @@ -68,6 +68,11 @@ It returns "true" if a push button is double clicked within 250ms (by default). The anteceding pushed() event can't be avoided, because to restrict the pushed() function to single clicks it would have to wait for a possible second click, which would introduce an annoying delay. So, the action on doubleClick() has to undo the previous action on pushed(). +#### singleClick() + +It returns "true" if a push button is clicked once and the requirements for doubleClick and longPress are not met. The event thus occur several miliseconds after the actual push, because it depends on the other events not happening after the push. Use this if three different interactions are needed in combination with doubleClick and longPress. Note that a singleClick() always will be preceded by pushed(). Use pushed() instead if immediate response is required and there is no interest in monitoring doubleClick and longPress. + + #### Example See the example in the library for a complete working program. @@ -104,7 +109,7 @@ void setup() { } ``` -The available callback setting functions are `setPushedCallback()`, `setReleasedCallback()`, `setLongPressCallback()`, and `setDoubleClickCallback()` which allow defining the functions that will be called on such events. If using a toggle switch and not a push button, the "pushed" event will be of interest when the switch is turned on, and "released" when it is turned off. +The available callback setting functions are `setPushedCallback()`, `setReleasedCallback()`, `setLongPressCallback()`, `setDoubleClickCallback()`, and `setSingleClickCallback()` which allow defining the functions that will be called on such events. If using a toggle switch and not a push button, the "pushed" event will be of interest when the switch is turned on, and "released" when it is turned off. If the conditions for more than one event occur simultaneously and there are callback functions registered for them, they will be executed in the order of the functions above. @@ -169,6 +174,10 @@ A long-press generates first a pushed event and after 300ms (by default) the lon The same happens with doubleClick, which also generates two pushed() events. When doubleClick is used, ignore the second pushed() result or don't call pushed(). When doubleClick is not needed, simply don't call doubleClick(). +#### Combining singleClick, doubleClick, and longPress events + +If these three events must be used toghether the best strategy is to stick to their get functions and avoid using pushed(). + ## Hardware considerations #### Connecting switches to the microcontroler @@ -222,68 +231,89 @@ Several discrete signals (updated at poll times) are created. The raw signal is ``` ..........................................DEGLITCHING.............................. - + ________________ _ - on | | | | _ - | | | | | | - | |_| |___| |__ - analog off_____|_____________________________|____________________________ - + on | | | | _ + | | | | | | + | |_| |___| |__ + analog off_____|_____________________________|____________________________ + ________________ _ _ - input _____| |_| |___| |_______________________________ - - poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ + input _____| |_| |___| |_______________________________ + + poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ equal 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 deglitchPeriod <--------><-- <-- <- <--------><--------><-------- ___________________________ - deglitched _________________| |__________________ + deglitched _________________| |__________________ deglitchTime ^ ^ ^ ^ ^ ^ ^ ..........................................DEBOUNCING............................. - debouncePeriod <--------------------------------> + debouncePeriod <--------------------------------> _________________________________ - debounced _________________| |____________ + debounced _________________| |____________ _ _ - _switched _________________| |_______________________________| |__________ - - switchedTime ^ ^ - + _switched _________________| |_______________________________| |__________ + + switchedTime ^ ^ + ********************************************************************************** ........................................DOUBLE CLICK.............................. - - __________ ______ - debounced ________| |_______| |_____________________________ - poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ + __________ ______ + debounced ________| |_______| |_____________________________ + + poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ _ _ - pushed _________| |________________| |__________________________________ - - pushedTime ^ ^ + pushed _________| |________________| |__________________________________ - doubleClickPeriod <-------------------------------------> + pushedTime ^ ^ + _ _ + released ____________________| |____________| |___________________________ + + releasedTime ^ ^ + + doubleClickPeriod <-------------------------------------> _ _doubleClick ___________________________| |__________________________________ - + ........................................LONG PRESS................................ - - ___________________________ - debounced ________| |___________________________ - poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ - - longPressPeriod <---------------> + ___________________________ + debounced ________| |___________________________ + + poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ + + longPressPeriod <---------------> _ _ - _switched _________| |_________________________| |________________________ + _switched _________| |_________________________| |________________________ __________ - longPressDisable ___________________________| |_________________________ + longPressDisable ___________________________| |_________________________ _ - _longPress ___________________________| |__________________________________ + _longPress ___________________________| |__________________________________ + + +........................................SINGLE CLICK.............................. + + __________ ______ + debounced ________| |_______________________________| |_____ + + poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ + + longPressPeriod <---------------> + doubleClickPeriod <-------------------------------------> + _ _ _ _ + _switched _________| |_______| |_____________________________| |____| |___ + _____ + singleClickDisable______________________________________________| |__________ + _ + _singleClick _______________________________________________| |______________ ``` ### Additional information diff --git a/avdweb_Switch.cpp b/avdweb_Switch.cpp index b00d267..24ea310 100644 --- a/avdweb_Switch.cpp +++ b/avdweb_Switch.cpp @@ -10,77 +10,99 @@ AUTHOR: Albert van Dalen WEBSITE: http://www.avdweb.nl/arduino/hardware-interfacing/simple-switch-debouncer.html HISTORY: -1.0.0 20-04-2013 _debouncePeriod=50 -1.0.1 22-05-2013 Added longPress, doubleClick -1.0.2 01-12-2015 added process(input) -1.0.3 15-01-2016 added deglitching -1.0.5 25-01-2017 file renamed to avdweb_Switch -1.1.0 28-07-2018 added callbacks (code by Sean Lanigan, added by Martin Laclaustra) +1.0.0 20-04-2013 _debouncePeriod=50 +1.0.1 22-05-2013 Added longPress, doubleClick +1.0.2 01-12-2015 added process(input) +1.0.3 15-01-2016 added deglitching +1.0.5 25-01-2017 file renamed to avdweb_Switch +1.1.0 28-07-2018 added callbacks (code by Sean Lanigan, added by Martin Laclaustra) +1.2.0-rc 28-07-2017 added singleclick. Reorganize, keeping variables for each event in one function ..........................................DEGLITCHING.............................. - + ________________ _ - on | | | | _ - | | | | | | - | |_| |___| |__ - analog off_____|_____________________________|____________________________ - + on | | | | _ + | | | | | | + | |_| |___| |__ + analog off_____|_____________________________|____________________________ + ________________ _ _ - input _____| |_| |___| |_______________________________ - - poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ + input _____| |_| |___| |_______________________________ + + poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ equal 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 deglitchPeriod <--------><-- <-- <- <--------><--------><-------- ___________________________ - deglitched _________________| |__________________ + deglitched _________________| |__________________ deglitchTime ^ ^ ^ ^ ^ ^ ^ ..........................................DEBOUNCING............................. - debouncePeriod <--------------------------------> + debouncePeriod <--------------------------------> _________________________________ - debounced _________________| |____________ + debounced _________________| |____________ _ _ - _switched _________________| |_______________________________| |__________ - - switchedTime ^ ^ - + _switched _________________| |_______________________________| |__________ + + switchedTime ^ ^ + ********************************************************************************** ........................................DOUBLE CLICK.............................. - - __________ ______ - debounced ________| |_______| |_____________________________ - poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ + __________ ______ + debounced ________| |_______| |_____________________________ + + poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ _ _ - pushed _________| |________________| |__________________________________ - - pushedTime ^ ^ + pushed _________| |________________| |__________________________________ + + pushedTime ^ ^ + _ _ + released ____________________| |____________| |___________________________ + + releasedTime ^ ^ - doubleClickPeriod <-------------------------------------> + doubleClickPeriod <-------------------------------------> _ _doubleClick ___________________________| |__________________________________ - + ........................................LONG PRESS................................ - - ___________________________ - debounced ________| |___________________________ - poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ - - longPressPeriod <---------------> + ___________________________ + debounced ________| |___________________________ + + poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ + + longPressPeriod <---------------> _ _ - _switched _________| |_________________________| |________________________ + _switched _________| |_________________________| |________________________ __________ - longPressDisable ___________________________| |_________________________ + longPressDisable ___________________________| |_________________________ _ - _longPress ___________________________| |__________________________________ - + _longPress ___________________________| |__________________________________ + + +........................................SINGLE CLICK.............................. + + __________ ______ + debounced ________| |_______________________________| |_____ + + poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ + + longPressPeriod <---------------> + doubleClickPeriod <-------------------------------------> + _ _ _ _ + _switched _________| |_______| |_____________________________| |____| |___ + _____ + singleClickDisable______________________________________________| |__________ + _ + _singleClick _______________________________________________| |______________ + */ #include "Arduino.h" @@ -91,30 +113,40 @@ pin(_pin), polarity(polarity), deglitchPeriod(deglitchPeriod), debouncePeriod(de { pinMode(pin, PinMode); switchedTime = millis(); debounced = digitalRead(pin); + singleClickDisable = true; } bool Switch::poll() { input = digitalRead(pin); + ms = millis(); return process(); } bool Switch::process() { deglitch(); debounce(); + calcSingleClick(); calcDoubleClick(); calcLongPress(); + if(switched()) + { switchedTime = ms; //stores last times for future rounds + if(pushed()) + { pushedTime = ms; + } else { releasedTime = ms; + } + } triggerCallbacks(); - return _switched; + return _switched; } void inline Switch::deglitch() -{ ms = millis(); +{ if(input == lastInput) equal = 1; else { equal = 0; deglitchTime = ms; } - if(equal & ((ms - deglitchTime) > deglitchPeriod)) // max 50ms, disable deglitch: 0ms + if(equal && ((ms - deglitchTime) > deglitchPeriod)) // max 50ms, disable deglitch: 0ms { deglitched = input; deglitchTime = ms; } @@ -122,29 +154,38 @@ void inline Switch::deglitch() } void inline Switch::debounce() -{ ms = millis(); +{ _switched = 0; - if((deglitched != debounced) & ((ms - switchedTime) >= debouncePeriod)) - { switchedTime = ms; - debounced = deglitched; + if((deglitched != debounced) && ((ms - switchedTime) > debouncePeriod)) + { debounced = deglitched; _switched = 1; - longPressDisable = false; } } -void inline Switch::calcDoubleClick() -{ _doubleClick = false; +void inline Switch::calcSingleClick() +{ _singleClick = false; if(pushed()) - { _doubleClick = (ms - pushedTime) < doubleClickPeriod; // pushedTime of previous push - pushedTime = ms; + { if((ms - pushedTime) >= doubleClickPeriod) + { singleClickDisable = false; //resets when pushed not in second click of doubleclick + } else { singleClickDisable = true; //silence single click in second cl. doublecl. + } + } + if(!singleClickDisable) + { _singleClick = !switched() && !on() && ((releasedTime - pushedTime) <= longPressPeriod) && ((ms - pushedTime) >= doubleClickPeriod); // true just one time between polls + singleClickDisable = _singleClick; // will be reset at next push } } +void inline Switch::calcDoubleClick() +{ _doubleClick = pushed() && ((ms - pushedTime) < doubleClickPeriod); +} + void inline Switch::calcLongPress() { _longPress = false; + if(released()) longPressDisable = false; //resets when released if(!longPressDisable) - { _longPress = on() && ((ms - pushedTime) > longPressPeriod); // true just one time between polls - longPressDisable = _longPress; // will be reset at next switch + { _longPress = !switched() && on() && ((ms - pushedTime) > longPressPeriod); // true just one time between polls + longPressDisable = _longPress; // will be reset at next release } } @@ -172,6 +213,10 @@ bool Switch::doubleClick() { return _doubleClick; } +bool Switch::singleClick() +{ return _singleClick; +} + void Switch::triggerCallbacks() { if(_pushedCallback && pushed()) @@ -188,6 +233,10 @@ void Switch::triggerCallbacks() if(_doubleClickCallback && doubleClick()) { _doubleClickCallback(_doubleClickCallbackParam); } + + if(_singleClickCallback && singleClick()) + { _singleClickCallback(_singleClickCallbackParam); + } } void Switch::setPushedCallback(switchCallback_t cb, void* param) @@ -213,3 +262,9 @@ void Switch::setDoubleClickCallback(switchCallback_t cb, void* param) _doubleClickCallback = cb; _doubleClickCallbackParam = param; } + +void Switch::setSingleClickCallback(switchCallback_t cb, void* param) +{ /// Store the "double click" callback function + _singleClickCallback = cb; + _singleClickCallbackParam = param; +} diff --git a/avdweb_Switch.h b/avdweb_Switch.h index b7ac06f..0d4f2ba 100644 --- a/avdweb_Switch.h +++ b/avdweb_Switch.h @@ -26,37 +26,42 @@ class Switch bool released(); // will be refreshed by poll() bool longPress(); // will be refreshed by poll() bool doubleClick(); // will be refreshed by poll() + bool singleClick(); // will be refreshed by poll() // Set methods for event callbacks void setPushedCallback(switchCallback_t cb, void* param = nullptr); void setReleasedCallback(switchCallback_t cb, void* param = nullptr); void setLongPressCallback(switchCallback_t cb, void* param = nullptr); void setDoubleClickCallback(switchCallback_t cb, void* param = nullptr); + void setSingleClickCallback(switchCallback_t cb, void* param = nullptr); protected: bool process(); // not inline, used in child class void inline deglitch(); void inline debounce(); - void inline calcDoubleClick(); void inline calcLongPress(); + void inline calcDoubleClick(); + void inline calcSingleClick(); void triggerCallbacks(); - unsigned long deglitchTime, switchedTime, pushedTime, ms; + unsigned long deglitchTime, switchedTime, pushedTime, releasedTime, ms; const byte pin; const int deglitchPeriod, debouncePeriod, longPressPeriod, doubleClickPeriod; const bool polarity; - bool input, lastInput, equal, deglitched, debounced, _switched, _longPress, longPressDisable, _doubleClick; + bool input, lastInput, equal, deglitched, debounced, _switched, _longPress, longPressDisable, _doubleClick, _singleClick, singleClickDisable; // Event callbacks switchCallback_t _pushedCallback = nullptr; switchCallback_t _releasedCallback = nullptr; switchCallback_t _longPressCallback = nullptr; switchCallback_t _doubleClickCallback = nullptr; + switchCallback_t _singleClickCallback = nullptr; void* _pushedCallbackParam = nullptr; void* _releasedCallbackParam = nullptr; void* _longPressCallbackParam = nullptr; void* _doubleClickCallbackParam = nullptr; + void* _singleClickCallbackParam = nullptr; }; diff --git a/keywords.txt b/keywords.txt index 1d60bbe..74cd933 100644 --- a/keywords.txt +++ b/keywords.txt @@ -19,6 +19,12 @@ pushed KEYWORD2 released KEYWORD2 longPress KEYWORD2 doubleClick KEYWORD2 +singleClick KEYWORD2 +setPushedCallback KEYWORD2 +setReleasedCallback KEYWORD2 +setLongPressCallback KEYWORD2 +setDoubleClickCallback KEYWORD2 +setSingleClickCallback KEYWORD2 ####################################### # Instances (KEYWORD2) diff --git a/library.properties b/library.properties index 537855a..cbb86c5 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=Switch -version=1.1.0 +version=1.2.0-rc author=Albert van Dalen maintainer=Albert van Dalen sentence=Arduino library for deglitching and debouncing switches and buttons. -paragraph=Supports detecting longPress and doubleClick. Supports defining callback functions. +paragraph=Supports detecting longPress, doubleClick, and singleClick. Supports defining callback functions. category=Signal Input/Output url=https://github.com/avandalen/avdweb_Switch architectures=avr, samd, esp8266, esp32