arduino-audio-tools
Loading...
Searching...
No Matches
src
AudioTools
CoreAudio
AudioBasic
Debouncer.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "AudioLogger.h"
4
5
namespace
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
}
LOGI
#define LOGI(...)
Definition
AudioLoggerIDF.h:28
audio_tools::Debouncer
Helper class to debounce user input from a push button.
Definition
Debouncer.h:11
audio_tools::Debouncer::setDebounceTimeout
void setDebounceTimeout(uint16_t timeoutMs)
Definition
Debouncer.h:19
audio_tools::Debouncer::p_ref
void * p_ref
Definition
Debouncer.h:42
audio_tools::Debouncer::debounce_ms
unsigned long debounce_ms
Definition
Debouncer.h:40
audio_tools::Debouncer::ms
uint16_t ms
Definition
Debouncer.h:41
audio_tools::Debouncer::Debouncer
Debouncer(uint16_t timeoutMs=5000, void *ref=nullptr)
Definition
Debouncer.h:14
audio_tools::Debouncer::debounce
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
audio_tools
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition
AudioCodecsBase.h:10
audio_tools::millis
uint32_t millis()
Returns the milliseconds since the start.
Definition
Time.h:12
audio_tools::writeData
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition
AudioTypes.h:512
Generated by
1.9.8