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
17#define RELEASE_BETWEEN_CLICKS 50
18#define RELEASE_TIMING_MS 250
19#define HOLD_BUTTON_MIN_MS 500
20
21void init(const bool isSystemStartedFromButton);
22
32void handle_events(const std::function<void(uint8_t)>& clickSerieCallback,
33 const std::function<void(uint8_t, uint32_t)>& clickHoldSerieCallback);
34
40
45{
47 bool isPressed = false;
49 bool isLongPressed = false;
51 uint32_t lastPressTime = 0;
53 uint32_t firstHoldTime = 0;
55 uint8_t nbClicksCounted = 0;
57 bool wasTriggered = false;
58
60 void reset()
61 {
62 isPressed = false;
63 isLongPressed = false;
64 lastPressTime = 0;
65 firstHoldTime = 0;
67 }
68};
69
73extern ButtonStateTy get_button_state();
74
78extern platform::gpio::DigitalPin::GPIO get_button_pin();
79
83extern void set_button_pin(const platform::gpio::DigitalPin::GPIO buttonPin);
84
88extern int get_button_pin_RAW();
89
90} // namespace button
91} // namespace physical
92} // namespace lampda
93
94#endif
Interface for the platform specific GeneralPurposeInputOutputs.
void init(const bool wasPoweredByUserInterrupt)
Call once on system start.
Definition: inputs.cpp:501
bool is_system_start_click()
Indicates that this click is the one triggered by the system start It is set to false after the click...
Definition: button.cpp:163
platform::gpio::DigitalPin::GPIO get_button_pin()
Return the pin used for the button.
Definition: button.cpp:23
void handle_events(const std::function< void(uint8_t)> &clickSerieCallback, const std::function< void(uint8_t, uint32_t)> &clickHoldSerieCallback)
handle the button clicked events
Definition: button.cpp:104
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:25
int get_button_pin_RAW()
get the button pin index in system. USE WITH CAUTION
Definition: button.cpp:24
ButtonStateTy get_button_state()
Get a copy of the raw internal button state.
Definition: button.cpp:29
Program scope.
Definition: control_fixed_modes.hpp:12
Store the button status and characteristics.
Definition: button.h:45
bool wasTriggered
Was a button action detected.
Definition: button.h:57
uint8_t nbClicksCounted
Nb of counted clicks.
Definition: button.h:55
bool isLongPressed
Is button in long press?
Definition: button.h:49
bool isPressed
Is the button pressed?
Definition: button.h:47
void reset()
Reset this object.
Definition: button.h:60
uint32_t firstHoldTime
Timestamp (millis) of first press (hold)
Definition: button.h:53
uint32_t lastPressTime
Timestamp (millis) of last press.
Definition: button.h:51