arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
Debouncer.h
1#pragma once
2
3#include "AudioLogger.h"
4
5namespace audio_tools {
6
11 class Debouncer {
12
13 public:
14 Debouncer(uint16_t timeoutMs = 5000, void* ref = nullptr) {
15 setDebounceTimeout(timeoutMs);
16 p_ref = ref;
17 }
18
19 void setDebounceTimeout(uint16_t timeoutMs) {
20 ms = timeoutMs;
21 }
22
24 bool debounce(void(*cb)(void* ref) = nullptr) {
25 bool result = false;
26 if (millis() > debounce_ms) {
27 LOGI("accpted");
28 if (cb != nullptr) cb(p_ref);
29 // new time limit
30 debounce_ms = millis() + ms;
31 result = true;
32 }
33 else {
34 LOGI("rejected");
35 }
36 return result;
37 }
38
39 protected:
40 unsigned long debounce_ms = 0; // Debounce sensitive touch
41 uint16_t ms;
42 void* p_ref = nullptr;
43
44 };
45
46}
Helper class to debounce user input from a push button.
Definition Debouncer.h:11
bool debounce(void(*cb)(void *ref)=nullptr)
Prevents that the same method is executed multiple times within the indicated time limit.
Definition Debouncer.h:24
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
uint32_t millis()
Returns the milliseconds since the start.
Definition Time.h:12