ESPHome  2024.9.0
lvgl_switch.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <utility>
4 
9 
10 namespace esphome {
11 namespace lvgl {
12 
13 class LVGLSwitch : public switch_::Switch {
14  public:
15  void set_control_lambda(std::function<void(bool)> state_lambda) {
16  this->state_lambda_ = std::move(state_lambda);
17  if (this->initial_state_.has_value()) {
18  this->state_lambda_(this->initial_state_.value());
19  this->initial_state_.reset();
20  }
21  }
22 
23  protected:
24  void write_state(bool value) override {
25  if (this->state_lambda_ != nullptr) {
26  this->state_lambda_(value);
27  } else {
28  this->initial_state_ = value;
29  }
30  }
31  std::function<void(bool)> state_lambda_{};
33 };
34 
35 } // namespace lvgl
36 } // namespace esphome
Base class for all switches.
Definition: switch.h:39
value_type const & value() const
Definition: optional.h:89
std::function< void(bool)> state_lambda_
Definition: lvgl_switch.h:31
void set_control_lambda(std::function< void(bool)> state_lambda)
Definition: lvgl_switch.h:15
bool has_value() const
Definition: optional.h:87
optional< bool > initial_state_
Definition: lvgl_switch.h:32
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void write_state(bool value) override
Definition: lvgl_switch.h:24