Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
button.h
Go to the documentation of this file.
1
5#ifndef BUTTON_H
6#define BUTTON_H
7
8#include <cstdint>
9#include <functional>
11
12namespace lampda {
13namespace physical {
15namespace button {
16
17static constexpr uint32_t thread_throttle_time_ms = 5;
18static constexpr uint32_t RELEASE_BETWEEN_CLICKS = 50;
19static constexpr uint32_t RELEASE_TIMING_CLICKS_MS = 250;
20static constexpr uint32_t RELEASE_TIMING_HOLDS_MS = 125;
21static constexpr uint32_t HOLD_BUTTON_MIN_MS = 500;
22
27void init(const bool isSystemStartedFromButton);
28
33{
35 bool isPressed = false;
37 bool isLongPressed = false;
39 uint32_t lastPressTime = 0;
41 uint32_t firstHoldTime = 0;
43 uint8_t nbClicksCounted = 0;
45 bool wasTriggered = false;
46
48 void reset()
49 {
50 isPressed = false;
51 isLongPressed = false;
52 lastPressTime = 0;
53 firstHoldTime = 0;
55 }
56};
57
61extern ButtonStateTy get_button_state();
62
66extern platform::gpio::DigitalPin::GPIO get_button_pin();
67
71extern void set_button_pin(const platform::gpio::DigitalPin::GPIO buttonPin);
72
76extern int get_button_pin_RAW();
77
78} // namespace button
79} // namespace physical
80} // namespace lampda
81
82#endif
Interface for the platform specific GeneralPurposeInputOutputs.
platform::gpio::DigitalPin::GPIO get_button_pin()
Return the pin used for the button.
Definition: button.cpp:25
static constexpr uint32_t RELEASE_TIMING_HOLDS_MS
time to release the button after hold stops
Definition: button.h:20
void set_button_pin(const platform::gpio::DigitalPin::GPIO buttonPin)
Only on system start, set the pin where the button is wired.
Definition: button.cpp:27
static constexpr uint32_t thread_throttle_time_ms
thread run frequency timing
Definition: button.h:17
static constexpr uint32_t RELEASE_BETWEEN_CLICKS
minimum release timing (debounce)
Definition: button.h:18
void init(const bool isSystemStartedFromButton)
Start the button handler.
Definition: button.cpp:148
int get_button_pin_RAW()
get the button pin index in system. USE WITH CAUTION
Definition: button.cpp:26
ButtonStateTy get_button_state()
Get a copy of the raw internal button state.
Definition: button.cpp:31
static constexpr uint32_t RELEASE_TIMING_CLICKS_MS
time to release the button after clicks stops
Definition: button.h:19
static constexpr uint32_t HOLD_BUTTON_MIN_MS
press and hold delay (ms)
Definition: button.h:21
Program scope.
Definition: control_fixed_modes.hpp:12
Store the button status and characteristics.
Definition: button.h:33
bool wasTriggered
Was a button action detected.
Definition: button.h:45
uint8_t nbClicksCounted
Nb of counted clicks.
Definition: button.h:43
bool isLongPressed
Is button in long press?
Definition: button.h:37
bool isPressed
Is the button pressed?
Definition: button.h:35
void reset()
Reset this object.
Definition: button.h:48
uint32_t firstHoldTime
Timestamp (millis) of first press (hold)
Definition: button.h:41
uint32_t lastPressTime
Timestamp (millis) of last press.
Definition: button.h:39