Skip to content

Commit

Permalink
added stopPolling()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Kulig committed Aug 25, 2024
1 parent a8900f7 commit 1e892de
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=DebounceMe
version=2.0.8
version=2.0.9
author=Tomasz Kulig <[email protected]>
maintainer=Tomasz Kulig <[email protected]>
sentence= Debounce button library.
Expand Down
8 changes: 7 additions & 1 deletion src/ButtonsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ void ButtonsHandler::pollOnce(int pollInterval) {
auto _this = static_cast<ButtonsHandler *>(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()`
Expand Down
5 changes: 4 additions & 1 deletion src/ButtonsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class ButtonsHandler {
void setSimultaneousBehavior(std::set<Button*> _buttons, std::function<void()> behavior);
void setSimultaneousBehaviorLong(std::set<Button*> _buttons, std::function<void()> behavior, unsigned int longPressTime = 1000);

void pollOnce(int pollInterval = 1);
void poll();
void pollOnce(int pollInterval = 1);
void stopPolling();

private:
std::vector<Button*> buttons;
Expand All @@ -33,6 +34,8 @@ class ButtonsHandler {
std::map<Button*, unsigned long> buttonLastStartPressed;
std::map<Button*, bool> buttonWasLongPressed;

TimerHandle_t timer;

void pollState(Button *button) const;
void resetState(Button *button) const;

Expand Down

0 comments on commit 1e892de

Please sign in to comment.