SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
minimal_button.h
Go to the documentation of this file.
1#ifndef SENSESP_SYSTEM_MINIMAL_BUTTON_H_
2#define SENSESP_SYSTEM_MINIMAL_BUTTON_H_
3
4#include "sensesp.h"
5
6#include "AceButton.h"
7#include "elapsedMillis.h"
9#include "sensesp_base_app.h"
10
11namespace sensesp {
12
13using namespace ace_button;
14
24 public:
25 MinimalButtonHandler(int pin, String config_path = "")
26 : BaseButtonHandler(pin, config_path) {}
27
28 virtual void handleEvent(AceButton* button, uint8_t event_type,
29 uint8_t button_state) override {
30 ESP_LOGD(__FILENAME__, "Button event: %d", event_type);
31 switch (event_type) {
32 case AceButton::kEventPressed:
34 ESP_LOGD(__FILENAME__, "Press");
35 break;
36 case AceButton::kEventLongReleased:
37 ESP_LOGD(__FILENAME__, "Long release, duration: %d",
38 static_cast<int>(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 ESP_LOGD(__FILENAME__, "Short release, duration: %d",
61 static_cast<int>(time_since_press_event));
62 ESP_LOGD(__FILENAME__, "Restarting");
63 ESP.restart();
64 }
74 virtual void handle_very_long_press() {
75 ESP_LOGD(__FILENAME__, "Performing a factory reset");
76 SensESPBaseApp::get()->reset();
77 }
78};
79
80} // namespace sensesp
81
82#endif // SENSESP_SRC_SENSESP_SYSTEM_BASE_BUTTON_H_
Base class for button handlers.
Definition base_button.h:21
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 const std::shared_ptr< SensESPBaseApp > & get()
Get the singleton instance of the SensESPBaseApp.