arduino-audio-tools
Loading...
Searching...
No Matches
Debouncer.h
Go to the documentation of this file.
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) {
16 p_ref = ref;
17 }
18
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
42 void* p_ref = nullptr;
43
44 };
45
46}
#define LOGI(...)
Definition AudioLoggerIDF.h:28
Helper class to debounce user input from a push button.
Definition Debouncer.h:11
void setDebounceTimeout(uint16_t timeoutMs)
Definition Debouncer.h:19
void * p_ref
Definition Debouncer.h:42
unsigned long debounce_ms
Definition Debouncer.h:40
uint16_t ms
Definition Debouncer.h:41
Debouncer(uint16_t timeoutMs=5000, void *ref=nullptr)
Definition Debouncer.h:14
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
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition AudioTypes.h:512