diff --git a/library.json b/library.json index 0f73001..13c5663 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "DebounceMe", - "version": "2.0.8", + "version": "2.0.9", "description": "This library solves bounce problem, imperfection of physical buttons. It supports short clicks and long clicks and combination of clicks!", "keywords": "button, buttons, switch, switches, click, clicks, debounce, debouncer, input, IO", "repository": { diff --git a/library.properties b/library.properties index 0156aba..a336d75 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=DebounceMe -version=2.0.8 +version=2.0.9 author=Tomasz Kulig maintainer=Tomasz Kulig sentence= Debounce button library. diff --git a/src/ButtonsHandler.cpp b/src/ButtonsHandler.cpp index 75f1a4b..bac7ad4 100644 --- a/src/ButtonsHandler.cpp +++ b/src/ButtonsHandler.cpp @@ -83,9 +83,15 @@ void ButtonsHandler::pollOnce(int pollInterval) { auto _this = static_cast(pvTimerGetTimerID(xTimer)); _this->poll(); }; - auto timer = xTimerCreate(NULL, pdMS_TO_TICKS(pollInterval), true, this, task); + timer = xTimerCreate(NULL, pdMS_TO_TICKS(pollInterval), true, this, task); xTimerStart(timer, 0); } + +void ButtonsHandler::stopPolling() { + if (timer == nullptr) return; + xTimerStop(timer, 0); + xTimerDelete(timer, 0); +} #endif // this function can be used to poll inside `loop()` diff --git a/src/ButtonsHandler.h b/src/ButtonsHandler.h index d556c13..f9b00e4 100644 --- a/src/ButtonsHandler.h +++ b/src/ButtonsHandler.h @@ -16,8 +16,9 @@ class ButtonsHandler { void setSimultaneousBehavior(std::set _buttons, std::function behavior); void setSimultaneousBehaviorLong(std::set _buttons, std::function behavior, unsigned int longPressTime = 1000); - void pollOnce(int pollInterval = 1); void poll(); + void pollOnce(int pollInterval = 1); + void stopPolling(); private: std::vector buttons; @@ -33,6 +34,8 @@ class ButtonsHandler { std::map buttonLastStartPressed; std::map buttonWasLongPressed; + TimerHandle_t timer; + void pollState(Button *button) const; void resetState(Button *button) const;