ESPHome  2024.12.2
button.cpp
Go to the documentation of this file.
1 #include "button.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace button {
6 
7 static const char *const TAG = "button";
8 
9 void Button::press() {
10  ESP_LOGD(TAG, "'%s' Pressed.", this->get_name().c_str());
11  this->press_action();
12  this->press_callback_.call();
13 }
14 void Button::add_on_press_callback(std::function<void()> &&callback) { this->press_callback_.add(std::move(callback)); }
15 
16 } // namespace button
17 } // namespace esphome
void press()
Press this button.
Definition: button.cpp:9
void add_on_press_callback(std::function< void()> &&callback)
Set callback for state changes.
Definition: button.cpp:14
virtual void press_action()=0
You should implement this virtual method if you want to create your own button.
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
CallbackManager< void()> press_callback_
Definition: button.h:48
const StringRef & get_name() const
Definition: entity_base.cpp:10