SensESP 2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
minimal_button.h
Go to the documentation of this file.
1#ifndef SENSESP_SRC_SENSESP_SYSTEM_MINIMAL_BUTTON_H_
2#define SENSESP_SRC_SENSESP_SYSTEM_MINIMAL_BUTTON_H_
3
4#include "AceButton.h"
5#include "elapsedMillis.h"
6#include "sensesp.h"
10#include "sensesp_base_app.h"
11
12namespace sensesp {
13
14using namespace ace_button;
15
25 public:
28
30 uint8_t button_state) override {
31 debugD("Button event: %d", event_type);
32 switch (event_type) {
33 case AceButton::kEventPressed:
35 debugD("Press");
36 break;
37 case AceButton::kEventLongReleased:
38 debugD("Long release, duration: %d", time_since_press_event);
39 if (time_since_press_event > 5000) {
41 } else if (time_since_press_event > 1000) {
42 this->handle_long_press();
43 }
44 break;
45 case AceButton::kEventReleased:
46 this->handle_button_press();
47 break;
48 default:
49 break;
50 }
51 }
52
53 protected:
59 virtual void handle_button_press() {
60 debugD("Short release, duration: %d", time_since_press_event);
61 debugD("Restarting");
62 ESP.restart();
63 }
68 virtual void handle_long_press() {
70 }
75 virtual void handle_very_long_press() {
76 debugD("Performing a factory reset");
77 SensESPBaseApp::get()->reset();
78 }
79};
80
81
82} // namespace sensesp
83
84#endif // SENSESP_SRC_SENSESP_SYSTEM_BASE_BUTTON_H_
Base class for button handlers.
Definition base_button.h:21
Construct a new transform based on a single function.
Minimal Button Handler.
virtual void handle_long_press()
Handle a long button press (over 1 second).
virtual void handleEvent(AceButton *button, uint8_t event_type, uint8_t button_state) override
MinimalButtonHandler(int pin, String config_path="")
virtual void handle_very_long_press()
Handle a very long button press (over 5 seconds).
virtual void handle_button_press()
Handle a brief button press (less than one second).
static SensESPBaseApp * get()
Get the singleton instance of the SensESPBaseApp.
#define debugD(fmt,...)
Definition local_debug.h:47