ESPHome 2025.9.3
Loading...
Searching...
No Matches
button.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome {
8namespace button {
9
10class Button;
11void log_button(const char *tag, const char *prefix, const char *type, Button *obj);
12
13#define LOG_BUTTON(prefix, type, obj) log_button(TAG, prefix, LOG_STR_LITERAL(type), obj)
14
15#define SUB_BUTTON(name) \
16 protected: \
17 button::Button *name##_button_{nullptr}; \
18\
19 public: \
20 void set_##name##_button(button::Button *button) { this->name##_button_ = button; }
21
27 public:
32 void press();
33
38 void add_on_press_callback(std::function<void()> &&callback);
39
40 protected:
43 virtual void press_action() = 0;
44
46};
47
48} // namespace button
49} // namespace esphome
Base class for all buttons.
Definition button.h:26
void add_on_press_callback(std::function< void()> &&callback)
Set callback for state changes.
Definition button.cpp:27
CallbackManager< void()> press_callback_
Definition button.h:45
void press()
Press this button.
Definition button.cpp:22
virtual void press_action()=0
You should implement this virtual method if you want to create your own button.
uint8_t type
void log_button(const char *tag, const char *prefix, const char *type, Button *obj)
Definition button.cpp:10
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7