AwesomeStudioPedal
A programmable, multi-profile foot controller for DAWs, score readers, and studio automation
Loading...
Searching...
No Matches
esp32/src/button.cpp
Go to the documentation of this file.
1
#include "button.h"
2
#include <Arduino.h>
3
#ifndef HOST_TEST_BUILD
4
#include <driver/gpio.h>
5
#endif
6
7
Button::Button
(uint8_t PIN) : PIN(PIN) {}
8
9
void
Button::setup
()
10
{
11
gpio_pad_select_gpio(
static_cast<
gpio_num_t
>
(PIN));
12
pinMode(PIN, INPUT_PULLUP);
13
}
14
15
bool
Button::isDebounced(
unsigned
long
now)
const
16
{
17
return
(now -
lastDebounceTime
) >
debounceDelay
;
18
}
19
20
void
Button::isr
()
21
{
22
unsigned
long
now = millis();
23
if
(digitalRead(PIN) == HIGH)
24
{
25
if
(
awaitingRelease
&& isDebounced(now))
26
{
27
awaitingRelease
=
false
;
28
lastDebounceTime
= now;
29
}
30
return
;
31
}
32
if
(!
awaitingRelease
&& isDebounced(now))
33
{
34
pressCount
++;
35
awaitingRelease
=
true
;
36
lastDebounceTime
= now;
37
}
38
}
39
40
bool
Button::event
()
41
{
42
if
(
pressCount
> 0)
43
{
44
pressCount
--;
45
return
true
;
46
}
47
return
false
;
48
}
49
50
void
Button::reset
()
51
{
52
pressCount
= 0;
53
awaitingRelease
=
false
;
54
lastDebounceTime
= 0;
55
}
Button::setup
void setup() override
Configures the GPIO pin as input with pull-up.
Definition
esp32/src/button.cpp:9
Button::awaitingRelease
volatile bool awaitingRelease
True after press, until pin goes HIGH.
Definition
esp32/include/button.h:25
Button::pressCount
volatile uint8_t pressCount
Incremented by ISR, decremented by event()
Definition
esp32/include/button.h:24
Button::Button
Button(uint8_t PIN)
Constructs a Button for the given GPIO pin.
Definition
esp32/src/button.cpp:7
Button::lastDebounceTime
unsigned long lastDebounceTime
Timestamp of last accepted press.
Definition
esp32/include/button.h:26
Button::isr
void isr()
ISR entry point — call from an IRAM_ATTR interrupt handler.
Definition
esp32/src/button.cpp:20
Button::debounceDelay
unsigned long debounceDelay
Debounce window in milliseconds.
Definition
esp32/include/button.h:27
Button::reset
void reset() override
Clears the pressed flag.
Definition
esp32/src/button.cpp:50
Button::event
bool event() override
Checks for a press event and clears the flag.
Definition
esp32/src/button.cpp:40
lib
hardware
esp32
src
button.cpp
Generated by
1.9.8