SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
base_button.h
Go to the documentation of this file.
1#ifndef SENSESP_SRC_SENSESP_SYSTEM_BASE_BUTTON_H_
2#define SENSESP_SRC_SENSESP_SYSTEM_BASE_BUTTON_H_
3
4#include <memory>
5#include "sensesp.h"
6
7#include "AceButton.h"
8#include "elapsedMillis.h"
9#include "sensesp_base_app.h"
10
11namespace sensesp {
12
13using namespace ace_button;
14
21class BaseButtonHandler : public IEventHandler {
22 public:
23 BaseButtonHandler(int pin, String config_path = "") {
24 button_ = std::unique_ptr<AceButton>(new AceButton(pin));
25 pinMode(pin, INPUT_PULLUP);
26
27 ButtonConfig* button_config = button_->getButtonConfig();
28 button_config->setIEventHandler(this);
29 button_config->setFeature(ButtonConfig::kFeatureLongPress);
30 button_config->setFeature(ButtonConfig::kFeatureSuppressAfterLongPress);
31
32 ESP_LOGD(__FILENAME__, "Button handler started");
33
34 event_loop()->onRepeat(
35 4, [this]() { this->button_->check(); });
36 }
37
38 protected:
39 std::unique_ptr<AceButton> button_;
40};
41
42} // namespace sensesp
43
44#endif // SENSESP_SRC_SENSESP_SYSTEM_BASE_BUTTON_H_
Base class for button handlers.
Definition base_button.h:21
std::unique_ptr< AceButton > button_
Definition base_button.h:39
BaseButtonHandler(int pin, String config_path="")
Definition base_button.h:23
std::shared_ptr< reactesp::EventLoop > event_loop()
Definition sensesp.cpp:9