ESPHome  2024.12.2
nextion_component.cpp
Go to the documentation of this file.
1 #include "nextion_component.h"
2 
3 namespace esphome {
4 namespace nextion {
5 
7  if (this->variable_name_ == this->variable_name_to_send_) {
8  return; // This is a variable. no need to set color
9  }
10  this->bco_ = bco;
11  this->bco_needs_update_ = true;
12  this->bco_is_set_ = true;
14 }
15 
17  if (this->variable_name_ == this->variable_name_to_send_) {
18  return; // This is a variable. no need to set color
19  }
20 
21  this->bco2_ = bco2;
22  this->bco2_needs_update_ = true;
23  this->bco2_is_set_ = true;
25 }
26 
28  if (this->variable_name_ == this->variable_name_to_send_) {
29  return; // This is a variable. no need to set color
30  }
31  this->pco_ = pco;
32  this->pco_needs_update_ = true;
33  this->pco_is_set_ = true;
35 }
36 
38  if (this->variable_name_ == this->variable_name_to_send_) {
39  return; // This is a variable. no need to set color
40  }
41  this->pco2_ = pco2;
42  this->pco2_needs_update_ = true;
43  this->pco2_is_set_ = true;
45 }
46 
47 void NextionComponent::set_font_id(uint8_t font_id) {
48  if (this->variable_name_ == this->variable_name_to_send_) {
49  return; // This is a variable. no need to set color
50  }
51  this->font_id_ = font_id;
52  this->font_id_needs_update_ = true;
53  this->font_id_is_set_ = true;
55 }
56 
57 void NextionComponent::set_visible(bool visible) {
58  if (this->variable_name_ == this->variable_name_to_send_) {
59  return; // This is a variable. no need to set color
60  }
61  this->visible_ = visible;
62  this->visible_needs_update_ = true;
63  this->visible_is_set_ = true;
65 }
66 
68  if (this->nextion_->is_sleeping() || !this->nextion_->is_setup() || !this->visible_is_set_ ||
69  (!this->visible_needs_update_ && !this->visible_)) {
70  this->needs_to_send_update_ = true;
71  return;
72  }
73 
74  if (this->visible_needs_update_ || (force_update && this->visible_is_set_)) {
75  std::string name_to_send = this->variable_name_;
76 
77  size_t pos = name_to_send.find_last_of('.');
78  if (pos != std::string::npos) {
79  name_to_send = name_to_send.substr(pos + 1);
80  }
81 
82  this->visible_needs_update_ = false;
83 
84  if (this->visible_) {
85  this->nextion_->show_component(name_to_send.c_str());
86  this->send_state_to_nextion();
87  } else {
88  this->nextion_->hide_component(name_to_send.c_str());
89  return;
90  }
91  }
92 
93  if (this->bco_needs_update_ || (force_update && this->bco2_is_set_)) {
94  this->nextion_->set_component_background_color(this->variable_name_.c_str(), this->bco_);
95  this->bco_needs_update_ = false;
96  }
97  if (this->bco2_needs_update_ || (force_update && this->bco2_is_set_)) {
99  this->bco2_needs_update_ = false;
100  }
101  if (this->pco_needs_update_ || (force_update && this->pco_is_set_)) {
102  this->nextion_->set_component_foreground_color(this->variable_name_.c_str(), this->pco_);
103  this->pco_needs_update_ = false;
104  }
105  if (this->pco2_needs_update_ || (force_update && this->pco2_is_set_)) {
107  this->pco2_needs_update_ = false;
108  }
109 
110  if (this->font_id_needs_update_ || (force_update && this->font_id_is_set_)) {
111  this->nextion_->set_component_font(this->variable_name_.c_str(), this->font_id_);
112  this->font_id_needs_update_ = false;
113  }
114 }
115 } // namespace nextion
116 } // namespace esphome
virtual void set_component_font(const char *component, uint8_t font_id)=0
virtual void set_component_pressed_foreground_color(const char *component, Color color)=0
virtual void set_component_pressed_background_color(const char *component, Color color)=0
virtual void hide_component(const char *component)=0
virtual void show_component(const char *component)=0
virtual void set_component_background_color(const char *component, Color color)=0
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
virtual void set_component_foreground_color(const char *component, Color color)=0