Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
button.h
Go to the documentation of this file.
1
5#ifndef COMPONENT_BUTTON_H
6#define COMPONENT_BUTTON_H
7
8#include <cstdint>
10
11namespace lampda {
12namespace component {
14namespace button {
15
16static constexpr uint32_t thread_throttle_time_ms = 5;
17static constexpr uint32_t RELEASE_BETWEEN_CLICKS = 50;
18static constexpr uint32_t RELEASE_TIMING_CLICKS_MS = 250;
19static constexpr uint32_t RELEASE_TIMING_HOLDS_MS = 125;
20static constexpr uint32_t HOLD_BUTTON_MIN_MS = 500;
21
26void init(const bool isSystemStartedFromButton);
27
32{
34 bool isPressed = false;
36 bool isLongPressed = false;
38 uint32_t lastPressTime = 0;
40 uint32_t firstHoldTime = 0;
42 uint8_t nbClicksCounted = 0;
44 bool wasTriggered = false;
45
47 void reset()
48 {
49 isPressed = false;
50 isLongPressed = false;
51 lastPressTime = 0;
52 firstHoldTime = 0;
54 }
55};
56
60extern ButtonStateTy get_button_state();
61
65extern hal::gpio::DigitalPin::GPIO get_button_pin();
66
70extern void set_button_pin(const hal::gpio::DigitalPin::GPIO buttonPin);
71
75extern int get_button_pin_RAW();
76
78extern void shutdown();
79
80} // namespace button
81} // namespace component
82} // namespace lampda
83
84#endif
Interface for the platform specific GeneralPurposeInputOutputs.
static constexpr uint32_t RELEASE_TIMING_HOLDS_MS
time to release the button after hold stops
Definition: button.h:19
int get_button_pin_RAW()
get the button pin index in system. USE WITH CAUTION
Definition: button.cpp:32
void set_button_pin(const hal::gpio::DigitalPin::GPIO buttonPin)
Only on system start, set the pin where the button is wired.
Definition: button.cpp:143
void init(const bool isSystemStartedFromButton)
Start the button handler.
Definition: button.cpp:260
static constexpr uint32_t RELEASE_TIMING_CLICKS_MS
time to release the button after clicks stops
Definition: button.h:18
static constexpr uint32_t thread_throttle_time_ms
thread run frequency timing
Definition: button.h:16
ButtonStateTy get_button_state()
Get a copy of the raw internal button state.
Definition: button.cpp:52
static constexpr uint32_t HOLD_BUTTON_MIN_MS
press and hold delay (ms)
Definition: button.h:20
void shutdown()
Deactivate button behavior.
Definition: button.cpp:310
hal::gpio::DigitalPin::GPIO get_button_pin()
Return the pin used for the button.
Definition: button.cpp:31
static constexpr uint32_t RELEASE_BETWEEN_CLICKS
minimum release timing (debounce)
Definition: button.h:17
Program scope.
Definition: control_fixed_modes.hpp:14
Store the button status and characteristics.
Definition: button.h:32
bool isLongPressed
Is button in long press?
Definition: button.h:36
uint8_t nbClicksCounted
Nb of counted clicks.
Definition: button.h:42
bool wasTriggered
Was a button action detected.
Definition: button.h:44
uint32_t firstHoldTime
Timestamp (millis) of first press (hold)
Definition: button.h:40
void reset()
Reset this object.
Definition: button.h:47
bool isPressed
Is the button pressed?
Definition: button.h:34
uint32_t lastPressTime
Timestamp (millis) of last press.
Definition: button.h:38