ESPHome  2024.10.2
lvgl_number.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 LVGLNumber : public number::Number {
14  public:
15  void set_control_lambda(std::function<void(float)> control_lambda) {
16  this->control_lambda_ = std::move(control_lambda);
17  if (this->initial_state_.has_value()) {
18  this->control_lambda_(this->initial_state_.value());
19  this->initial_state_.reset();
20  }
21  }
22 
23  protected:
24  void control(float value) override {
25  if (this->control_lambda_ != nullptr) {
26  this->control_lambda_(value);
27  } else {
28  this->initial_state_ = value;
29  }
30  }
31  std::function<void(float)> control_lambda_{};
33 };
34 
35 } // namespace lvgl
36 } // namespace esphome
value_type const & value() const
Definition: optional.h:89
void control(float value) override
Definition: lvgl_number.h:24
bool has_value() const
Definition: optional.h:87
optional< float > initial_state_
Definition: lvgl_number.h:32
Base-class for all numbers.
Definition: number.h:39
void set_control_lambda(std::function< void(float)> control_lambda)
Definition: lvgl_number.h:15
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
std::function< void(float)> control_lambda_
Definition: lvgl_number.h:31