13static const char *
const TAG =
"nextion";
16static constexpr uint8_t COMMAND_DELIMITER[3] = {0xFF, 0xFF, 0xFF};
17static constexpr size_t DELIMITER_SIZE =
sizeof(COMMAND_DELIMITER);
38#ifdef USE_NEXTION_COMMAND_SPACING
40 if (!this->
connection_state_.ignore_is_setup_ && !this->command_pacer_.can_send(now)) {
41 ESP_LOGN(TAG,
"Command spacing: delaying '%s'", command.c_str());
46 ESP_LOGN(TAG,
"cmd: %s", command.c_str());
49 const uint8_t to_send[3] = {0xFF, 0xFF, 0xFF};
52#ifdef USE_NEXTION_COMMAND_SPACING
69#ifdef USE_NEXTION_CONFIG_SKIP_CONNECTION_HANDSHAKE
70 ESP_LOGW(TAG,
"Connected (no handshake)");
79#ifdef USE_NEXTION_CONFIG_EXIT_REPARSE_ON_START
96 if (!response.empty() && response[0] == 0x1A) {
98 ESP_LOGV(TAG,
"0x1A error ignored (setup)");
101 if (response.empty() || response.find(
"comok") == std::string::npos) {
102#ifdef NEXTION_PROTOCOL_LOG
103 ESP_LOGN(TAG,
"Bad connect: %s", response.c_str());
104 for (
size_t i = 0; i < response.length(); i++) {
105 ESP_LOGN(TAG,
"resp: %s %d %d %c", response.c_str(), i, response[i], response[i]);
109 ESP_LOGW(TAG,
"Not connected");
115 ESP_LOGI(TAG,
"Connected");
118 ESP_LOGN(TAG,
"connect: %s", response.c_str());
122 std::vector<std::string> connect_info;
123 while ((start = response.find_first_not_of(
',',
end)) != std::string::npos) {
124 end = response.find(
',', start);
125 connect_info.push_back(response.substr(start,
end - start));
130 ESP_LOGN(TAG,
"Connect info: %zu", connect_info.size());
131#ifdef USE_NEXTION_CONFIG_DUMP_DEVICE_INFO
138 " Device Model: %s\n"
140 " Serial Number: %s\n"
142 connect_info[2].c_str(), connect_info[3].c_str(), connect_info[5].c_str(), connect_info[6].c_str());
145 ESP_LOGE(TAG,
"Bad connect value: '%s'", response.c_str());
162 delete entry->component;
166 this->nextion_queue_.clear();
167#ifdef USE_NEXTION_WAVEFORM
171 this->waveform_queue_.clear();
176 ESP_LOGCONFIG(TAG,
"Nextion:");
178#ifdef USE_NEXTION_CONFIG_SKIP_CONNECTION_HANDSHAKE
179 ESP_LOGCONFIG(TAG,
" Skip handshake: YES");
181#ifdef USE_NEXTION_CONFIG_DUMP_DEVICE_INFO
183 " Device Model: %s\n"
185 " Serial Number: %s\n"
187 " Max queue age: %u ms\n"
188 " Startup override: %u ms\n",
189 this->
device_model_.c_str(), this->firmware_version_.c_str(), this->serial_number_.c_str(),
190 this->flash_size_.c_str(), this->max_q_age_ms_, this->startup_override_ms_);
192#ifdef USE_NEXTION_CONFIG_EXIT_REPARSE_ON_START
193 ESP_LOGCONFIG(TAG,
" Exit reparse: YES\n");
196 " Wake On Touch: %s\n"
197 " Touch Timeout: %" PRIu16,
201#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
206 ESP_LOGCONFIG(TAG,
" Wake Up Page: %u", this->
wake_up_page_);
209#ifdef USE_NEXTION_CONF_START_UP_PAGE
215#ifdef USE_NEXTION_COMMAND_SPACING
219#ifdef USE_NEXTION_MAX_QUEUE_SIZE
222#ifdef USE_NEXTION_TFT_UPLOAD
225 " TFT upload HTTP timeout: %" PRIu16
"ms\n"
226 " TFT upload HTTP retries: %u",
227 this->
tft_url_.c_str(), this->tft_upload_http_timeout_, this->tft_upload_http_retries_);
250 binarysensortype->update_component();
253 sensortype->update_component();
256 switchtype->update_component();
259 textsensortype->update_component();
278 int ret = vsnprintf(buffer,
sizeof(buffer),
format, arg);
281 ESP_LOGW(TAG,
"Bad cmd format: '%s'",
format);
289#ifdef NEXTION_PROTOCOL_LOG
291 ESP_LOGN(TAG,
"print_queue_members_ (top 10) size %zu", this->nextion_queue_.size());
292 ESP_LOGN(TAG,
"*******************************************");
294 for (
auto *i : this->nextion_queue_) {
299 ESP_LOGN(TAG,
"Queue null");
301 ESP_LOGN(TAG,
"Queue type: %d:%s, name: %s", i->component->get_queue_type(),
302 i->component->get_queue_type_string(), i->component->get_variable_name().c_str());
305 ESP_LOGN(TAG,
"*******************************************");
313 if (this->
connection_state_.nextion_reports_is_setup_ && !this->connection_state_.sent_setup_commands_) {
322#ifdef USE_NEXTION_CONF_START_UP_PAGE
351 ESP_LOGV(TAG,
"Manual ready set");
356#ifdef USE_NEXTION_COMMAND_SPACING
358#ifdef USE_NEXTION_WAVEFORM
359 if (!this->waveform_queue_.empty()) {
366#ifdef USE_NEXTION_COMMAND_SPACING
368#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
369 size_t commands_sent = 0;
372 for (
auto *item : this->nextion_queue_) {
373 if (item ==
nullptr || item->pending_command.empty()) {
377#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
379 ESP_LOGV(TAG,
"Pending cmds: loop limit reached, deferring");
392 item->pending_command.clear();
393 ESP_LOGVV(TAG,
"Pending cmd sent: %s", item->component->get_variable_name().c_str());
399 if (this->nextion_queue_.empty()) {
401 ESP_LOGE(TAG,
"Queue empty");
406 NextionQueue *nb = this->nextion_queue_.front();
407 if (!nb || !nb->component) {
408 ESP_LOGE(TAG,
"Invalid queue");
409 this->nextion_queue_.pop_front();
412 NextionComponentBase *
component = nb->component;
414 ESP_LOGN(TAG,
"Removed: %s",
component->get_variable_name().c_str());
417 if (
component->get_variable_name() ==
"sleep_wake") {
423 this->nextion_queue_.pop_front();
432 size_t to_read = std::min(avail,
sizeof(buf));
438 this->
command_data_.append(
reinterpret_cast<const char *
>(buf), to_read);
447#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
448 size_t commands_processed = 0;
451 size_t to_process_length = 0;
452 std::string to_process;
454 ESP_LOGN(TAG,
"command_data_ %s len %d", this->
command_data_.c_str(), this->command_data_.length());
455#ifdef NEXTION_PROTOCOL_LOG
458 while ((to_process_length = this->
command_data_.find(
reinterpret_cast<const char *
>(COMMAND_DELIMITER), 0,
459 DELIMITER_SIZE)) != std::string::npos) {
460#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
462 ESP_LOGV(TAG,
"Command limit reached, deferring");
466 ESP_LOGN(TAG,
"queue size: %zu", this->nextion_queue_.size());
467 while (to_process_length + DELIMITER_SIZE < this->
command_data_.length() &&
468 static_cast<uint8_t
>(this->command_data_[to_process_length + DELIMITER_SIZE]) == 0xFF) {
470 ESP_LOGN(TAG,
"Add 0xFF");
475 to_process_length -= 1;
476 to_process = this->
command_data_.substr(1, to_process_length);
478 switch (nextion_event) {
480 ESP_LOGW(TAG,
"Invalid instruction");
486 ESP_LOGVV(TAG,
"Cmd OK");
487 ESP_LOGN(TAG,
"this->nextion_queue_.empty() %s", YESNO(this->nextion_queue_.empty()));
491 if (this->nextion_queue_.empty()) {
498 ESP_LOGW(TAG,
"Invalid component ID/name");
502 ESP_LOGW(TAG,
"Invalid page ID");
506 ESP_LOGW(TAG,
"Invalid picture ID");
510 ESP_LOGW(TAG,
"Invalid font ID");
514 ESP_LOGW(TAG,
"File operation failed");
517 ESP_LOGW(TAG,
"CRC validation failed");
520 ESP_LOGW(TAG,
"Invalid baud rate");
523#ifdef USE_NEXTION_WAVEFORM
524 if (this->waveform_queue_.empty()) {
525 ESP_LOGW(TAG,
"Waveform ID/ch used but no sensor queued");
527 auto &nb = this->waveform_queue_.front();
528 NextionComponentBase *
component = nb->component;
529 ESP_LOGW(TAG,
"Invalid waveform ID %d/ch %d",
component->get_component_id(),
531 ESP_LOGN(TAG,
"Remove waveform ID %d/ch %d",
component->get_component_id(),
component->get_wave_channel_id());
533 this->waveform_queue_.pop();
536 ESP_LOGW(TAG,
"Waveform ID/ch error but waveform not enabled");
540 ESP_LOGW(TAG,
"Invalid variable name");
544 ESP_LOGW(TAG,
"Invalid variable operation");
548 ESP_LOGW(TAG,
"Variable assign failed");
552 ESP_LOGW(TAG,
"EEPROM operation failed");
555 ESP_LOGW(TAG,
"Invalid parameter count");
559 ESP_LOGW(TAG,
"Invalid component I/O");
562 ESP_LOGW(TAG,
"Undefined escape chars");
566 ESP_LOGW(TAG,
"Variable name too long");
571 ESP_LOGE(TAG,
"Serial buffer overflow");
575 if (to_process_length != 3) {
576 ESP_LOGW(TAG,
"Incorrect touch len: %zu (need 3)", to_process_length);
580 uint8_t page_id = to_process[0];
581 uint8_t component_id = to_process[1];
582 uint8_t touch_event = to_process[2];
583 ESP_LOGV(TAG,
"Touch %s: page %u comp %u", touch_event ?
"PRESS" :
"RELEASE", page_id, component_id);
584 for (
auto *touch : this->
touch_) {
585 touch->process_touch(page_id, component_id, touch_event != 0);
592 if (to_process_length != 1) {
593 ESP_LOGW(TAG,
"Page event: expect 1, got %zu", to_process_length);
597 uint8_t page_id = to_process[0];
598 ESP_LOGV(TAG,
"New page: %u", page_id);
607 if (to_process_length != 5) {
608 ESP_LOGW(TAG,
"Touch coordinate: expect 5, got %zu", to_process_length);
609 ESP_LOGW(TAG,
"%s", to_process.c_str());
613 const uint16_t
x = (uint16_t(to_process[0]) << 8) | to_process[1];
614 const uint16_t
y = (uint16_t(to_process[2]) << 8) | to_process[3];
615 const uint8_t touch_event = to_process[4];
616 ESP_LOGV(TAG,
"Touch %s at %u,%u", touch_event ?
"PRESS" :
"RELEASE",
x,
y);
626 if (this->nextion_queue_.empty()) {
627 ESP_LOGW(TAG,
"String return but queue is empty");
631 NextionQueue *nb = this->nextion_queue_.front();
632 if (!nb || !nb->component) {
633 ESP_LOGE(TAG,
"Invalid queue entry");
634 this->nextion_queue_.pop_front();
637 NextionComponentBase *
component = nb->component;
640 ESP_LOGE(TAG,
"String return but '%s' not text sensor",
component->get_variable_name().c_str());
642 ESP_LOGN(TAG,
"String resp: '%s' id: %s type: %s", to_process.c_str(),
component->get_variable_name().c_str(),
647 this->nextion_queue_.pop_front();
658 if (this->nextion_queue_.empty()) {
659 ESP_LOGE(TAG,
"Numeric return but queue empty");
663 if (to_process_length < 4) {
664 ESP_LOGE(TAG,
"Numeric return but insufficient data (need 4, got %zu)", to_process_length);
668 int value =
static_cast<int>(
encode_uint32(to_process[3], to_process[2], to_process[1], to_process[0]));
670 NextionQueue *nb = this->nextion_queue_.front();
671 if (!nb || !nb->component) {
672 ESP_LOGE(TAG,
"Invalid queue");
673 this->nextion_queue_.pop_front();
676 NextionComponentBase *
component = nb->component;
681 ESP_LOGE(TAG,
"Numeric return but '%s' invalid type %d",
component->get_variable_name().c_str(),
684 ESP_LOGN(TAG,
"Numeric: %s type %d:%s val %d",
component->get_variable_name().c_str(),
686 component->set_state_from_int(value,
true,
false);
690 this->nextion_queue_.pop_front();
696 ESP_LOGVV(TAG,
"Auto sleep");
703 ESP_LOGVV(TAG,
"Auto wake");
711 ESP_LOGV(TAG,
"System start: %zu", to_process_length);
725 std::string variable_name;
728 auto index = to_process.find(
'\0');
729 if (index == std::string::npos || (to_process_length - index - 1) < 1) {
730 ESP_LOGE(TAG,
"Bad switch data (0x90)");
731 ESP_LOGN(TAG,
"proc: %s %zu %zu", to_process.c_str(), to_process_length, index);
735 variable_name = to_process.substr(0, index);
738 ESP_LOGN(TAG,
"Switch %s: %s", ONOFF(to_process[index] != 0), variable_name.c_str());
740#ifdef USE_NEXTION_TRIGGER_CUSTOM_SWITCH
744 for (
auto *switchtype : this->switchtype_) {
745 switchtype->process_bool(variable_name, to_process[index] != 0);
756 std::string variable_name;
758 auto index = to_process.find(
'\0');
759 if (index == std::string::npos || (to_process_length - index - 1) != 4) {
760 ESP_LOGE(TAG,
"Bad sensor data (0x91)");
761 ESP_LOGN(TAG,
"proc: %s %zu %zu", to_process.c_str(), to_process_length, index);
765 index = to_process.find(
'\0');
766 variable_name = to_process.substr(0, index);
768 int value =
static_cast<int>(
769 encode_uint32(to_process[index + 4], to_process[index + 3], to_process[index + 2], to_process[index + 1]));
771 ESP_LOGN(TAG,
"Sensor: %s=%d", variable_name.c_str(), value);
773#ifdef USE_NEXTION_TRIGGER_CUSTOM_SENSOR
777 for (
auto *sensor : this->sensortype_) {
778 sensor->process_sensor(variable_name, value);
791 std::string variable_name;
792 std::string text_value;
795 auto index = to_process.find(
'\0');
796 if (index == std::string::npos || (to_process_length - index - 1) < 1) {
797 ESP_LOGE(TAG,
"Bad text data (0x92)");
798 ESP_LOGN(TAG,
"proc: %s %zu %zu", to_process.c_str(), to_process_length, index);
802 variable_name = to_process.substr(0, index);
806 text_value = to_process.substr(index, to_process_length - index - 1);
808 ESP_LOGN(TAG,
"Text sensor: %s='%s'", variable_name.c_str(), text_value.c_str());
815#ifdef USE_NEXTION_TRIGGER_CUSTOM_TEXT_SENSOR
819 for (
auto *textsensortype : this->textsensortype_) {
820 textsensortype->process_text(variable_name, text_value);
831 std::string variable_name;
834 auto index = to_process.find(
'\0');
835 if (index == std::string::npos || (to_process_length - index - 1) < 1) {
836 ESP_LOGE(TAG,
"Bad binary data (0x93)");
837 ESP_LOGN(TAG,
"proc: %s %zu %zu", to_process.c_str(), to_process_length, index);
841 variable_name = to_process.substr(0, index);
844 ESP_LOGN(TAG,
"Binary sensor: %s=%s", variable_name.c_str(), ONOFF(to_process[index] != 0));
846#ifdef USE_NEXTION_TRIGGER_CUSTOM_BINARY_SENSOR
850 for (
auto *binarysensortype : this->binarysensortype_) {
851 binarysensortype->process_bool(&variable_name[0], to_process[index] != 0);
856 ESP_LOGVV(TAG,
"Data transmit done");
857#ifdef USE_NEXTION_WAVEFORM
863 ESP_LOGVV(TAG,
"Ready for transmit");
864#ifdef USE_NEXTION_WAVEFORM
865 if (this->waveform_queue_.empty()) {
866 ESP_LOGE(TAG,
"No waveforms queued");
869 auto &nb = this->waveform_queue_.front();
871 size_t buffer_to_send =
component->get_wave_buffer_size() < 255 ?
component->get_wave_buffer_size() : 255;
872 this->
write_array(component->get_wave_buffer().data(),
static_cast<int>(buffer_to_send));
873 ESP_LOGN(TAG,
"Send waveform: component id %d, waveform id %d, size %zu",
component->get_component_id(),
874 component->get_wave_channel_id(), buffer_to_send);
875 component->clear_wave_buffer(buffer_to_send);
877 this->waveform_queue_.pop();
879 ESP_LOGW(TAG,
"Waveform transmit ready but waveform not enabled");
884 ESP_LOGW(TAG,
"Unknown event: 0x%02X", nextion_event);
888 this->
command_data_.erase(0, to_process_length + DELIMITER_SIZE + 1);
893 if (this->
max_q_age_ms_ > 0 && !this->nextion_queue_.empty() &&
894 ms - this->nextion_queue_.front()->queue_time > this->max_q_age_ms_) {
895 for (
auto it = this->nextion_queue_.begin(); it != this->nextion_queue_.end();) {
896 if (ms - (*it)->queue_time > this->max_q_age_ms_) {
897 NextionComponentBase *
component = (*it)->component;
898 ESP_LOGV(TAG,
"Remove old queue '%s':'%s'",
component->get_queue_type_string(),
902 if (
component->get_variable_name() ==
"sleep_wake") {
909 it = this->nextion_queue_.erase(it);
916 ESP_LOGN(TAG,
"Loop end");
926 ESP_LOGN(TAG,
"State: %s=%lf (type %d)", name.c_str(),
state, queue_type);
928 switch (queue_type) {
930 for (
auto *sensor : this->sensortype_) {
931 if (name == sensor->get_variable_name()) {
932 sensor->set_state(
state,
true,
true);
939 for (
auto *sensor : this->binarysensortype_) {
940 if (name == sensor->get_variable_name()) {
941 sensor->set_state(
state != 0,
true,
true);
948 for (
auto *sensor : this->switchtype_) {
949 if (name == sensor->get_variable_name()) {
950 sensor->set_state(
state != 0,
true,
true);
957 ESP_LOGW(TAG,
"set_sensor_state: bad type %d", queue_type);
963 ESP_LOGV(TAG,
"State: %s='%s'", name.c_str(),
state.c_str());
965 for (
auto *sensor : this->textsensortype_) {
966 if (name == sensor->get_variable_name()) {
967 sensor->set_state(
state,
true,
true);
974 ESP_LOGV(TAG,
"Send states");
975 for (
auto *binarysensortype : this->binarysensortype_) {
976 if (force_update || binarysensortype->get_needs_to_send_update())
977 binarysensortype->send_state_to_nextion();
979 for (
auto *sensortype : this->sensortype_) {
980#ifdef USE_NEXTION_WAVEFORM
981 if ((force_update || sensortype->get_needs_to_send_update()) && sensortype->get_wave_channel_id() == UINT8_MAX) {
983 if (force_update || sensortype->get_needs_to_send_update()) {
985 sensortype->send_state_to_nextion();
988 for (
auto *switchtype : this->switchtype_) {
989 if (force_update || switchtype->get_needs_to_send_update())
990 switchtype->send_state_to_nextion();
992 for (
auto *textsensortype : this->textsensortype_) {
993 if (force_update || textsensortype->get_needs_to_send_update())
994 textsensortype->send_state_to_nextion();
999 for (
auto *binarysensortype : this->binarysensortype_) {
1000 if (binarysensortype->get_variable_name().find(prefix, 0) != std::string::npos)
1001 binarysensortype->update_component_settings(
true);
1003 for (
auto *sensortype : this->sensortype_) {
1004 if (sensortype->get_variable_name().find(prefix, 0) != std::string::npos)
1005 sensortype->update_component_settings(
true);
1007 for (
auto *switchtype : this->switchtype_) {
1008 if (switchtype->get_variable_name().find(prefix, 0) != std::string::npos)
1009 switchtype->update_component_settings(
true);
1011 for (
auto *textsensortype : this->textsensortype_) {
1012 if (textsensortype->get_variable_name().find(prefix, 0) != std::string::npos)
1013 textsensortype->update_component_settings(
true);
1019 uint8_t nr_of_ff_bytes = 0;
1020 bool exit_flag =
false;
1021 bool ff_flag =
false;
1025 while ((timeout == 0 && this->
available()) ||
millis() - start <= timeout) {
1040 if (nr_of_ff_bytes >= 3)
1043 response += (char) c;
1045 if (response.find(0x05) != std::string::npos) {
1052 if (exit_flag || ff_flag) {
1058 response = response.substr(0, response.length() - 3);
1060 return response.length();
1074#ifdef USE_NEXTION_MAX_QUEUE_SIZE
1075 if (this->
max_queue_size_ > 0 && this->nextion_queue_.size() >= this->max_queue_size_) {
1076 ESP_LOGW(TAG,
"Queue full (%zu), drop: %s", this->nextion_queue_.size(), variable_name.c_str());
1081 RAMAllocator<nextion::NextionQueue> allocator;
1082 nextion::NextionQueue *nextion_queue = allocator.allocate(1);
1083 if (nextion_queue ==
nullptr) {
1084 ESP_LOGW(TAG,
"Queue alloc failed");
1087 new (nextion_queue) nextion::NextionQueue();
1090 nextion_queue->component =
new nextion::NextionComponentBase;
1091 nextion_queue->component->set_variable_name(variable_name);
1095 this->nextion_queue_.push_back(nextion_queue);
1097 ESP_LOGN(TAG,
"Queue NORESULT: %s", nextion_queue->component->get_variable_name().c_str());
1120#ifdef USE_NEXTION_COMMAND_SPACING
1128#ifdef USE_NEXTION_COMMAND_SPACING
1130 const std::string &command) {
1131#ifdef USE_NEXTION_MAX_QUEUE_SIZE
1132 if (this->
max_queue_size_ > 0 && this->nextion_queue_.size() >= this->max_queue_size_) {
1133 ESP_LOGW(TAG,
"Queue full (%zu), drop: %s", this->nextion_queue_.size(), variable_name.c_str());
1138 RAMAllocator<nextion::NextionQueue> allocator;
1139 nextion::NextionQueue *nextion_queue = allocator.allocate(1);
1140 if (nextion_queue ==
nullptr) {
1141 ESP_LOGW(TAG,
"Queue alloc failed");
1144 new (nextion_queue) nextion::NextionQueue();
1146 nextion_queue->component =
new nextion::NextionComponentBase;
1147 nextion_queue->component->set_variable_name(variable_name);
1149 nextion_queue->pending_command = command;
1151 this->nextion_queue_.push_back(nextion_queue);
1152 ESP_LOGVV(TAG,
"Queue with pending command: %s", variable_name.c_str());
1164 int ret = vsnprintf(buffer,
sizeof(buffer),
format, arg);
1167 ESP_LOGW(TAG,
"Bad cmd format: '%s'",
format);
1189 int ret = vsnprintf(buffer,
sizeof(buffer),
format, arg);
1192 ESP_LOGW(TAG,
"Bad cmd format: '%s'",
format);
1215 const std::string &variable_name_to_send, int32_t state_value) {
1220 const std::string &variable_name_to_send, int32_t state_value,
1221 bool is_sleep_safe) {
1242 const std::string &variable_name_to_send,
1243 const std::string &state_value) {
1248 const std::string &variable_name_to_send,
1249 const std::string &state_value,
bool is_sleep_safe) {
1254 state_value.c_str());
1270#ifdef USE_NEXTION_MAX_QUEUE_SIZE
1271 if (this->
max_queue_size_ > 0 && this->nextion_queue_.size() >= this->max_queue_size_) {
1272 ESP_LOGW(TAG,
"Queue full (%zu), drop GET: %s", this->nextion_queue_.size(),
1273 component->get_variable_name().c_str());
1278 RAMAllocator<nextion::NextionQueue> allocator;
1279 nextion::NextionQueue *nextion_queue = allocator.allocate(1);
1280 if (nextion_queue ==
nullptr) {
1281 ESP_LOGW(TAG,
"Queue alloc failed");
1284 new (nextion_queue) nextion::NextionQueue();
1289 ESP_LOGN(TAG,
"Queue %s: %s",
component->get_queue_type_string(),
component->get_variable_name().c_str());
1291 std::string command =
"get " +
component->get_variable_name_to_send();
1293#ifdef USE_NEXTION_COMMAND_SPACING
1297 nextion_queue->pending_command = command;
1298 this->nextion_queue_.push_back(nextion_queue);
1300 nextion_queue->pending_command.clear();
1304 this->nextion_queue_.push_back(nextion_queue);
1306 delete nextion_queue;
1311#ifdef USE_NEXTION_WAVEFORM
1321 RAMAllocator<nextion::NextionQueue> allocator;
1322 nextion::NextionQueue *nextion_queue = allocator.allocate(1);
1323 if (nextion_queue ==
nullptr) {
1324 ESP_LOGW(TAG,
"Queue alloc failed");
1327 new (nextion_queue) nextion::NextionQueue();
1332 if (!this->waveform_queue_.push(nextion_queue)) {
1333 ESP_LOGW(TAG,
"Waveform queue full, drop");
1334 delete nextion_queue;
1337 if (this->waveform_queue_.size() == 1)
1342 if (this->waveform_queue_.empty())
1345 auto *nb = this->waveform_queue_.front();
1347 size_t buffer_to_send =
component->get_wave_buffer_size() < 255 ?
component->get_wave_buffer_size() : 255;
1350 buf_append_printf(command,
sizeof(command), 0,
"addt %u,%u,%zu",
component->get_component_id(),
1351 component->get_wave_channel_id(), buffer_to_send);
void feed_wdt()
Feed the task watchdog.
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
uint8_t get_spacing() const
Get current command spacing.
bool can_send(uint32_t now) const
Check if enough time has passed to send the next command.
void mark_sent(uint32_t now)
Record the transmit timestamp for the most recently sent command.
std::vector< NextionComponentBase * > touch_
std::vector< NextionComponentBase * > switchtype_
std::vector< NextionComponentBase * > binarysensortype_
StaticRingBuffer< NextionQueue *, 4 > waveform_queue_
Fixed-size ring buffer for waveform queue.
uint16_t max_q_age_ms_
Maximum age for queue items in ms.
bool send_command_(const std::string &command)
Manually send a raw command to the display and don't wait for an acknowledgement packet.
std::vector< NextionComponentBase * > textsensortype_
CallbackManager< void(uint8_t)> page_callback_
void check_pending_waveform_()
struct esphome::nextion::Nextion::@144 connection_state_
Status flags for Nextion display state management.
CallbackManager< void(StringRef, int32_t)> custom_sensor_callback_
void set_wake_up_page(uint8_t wake_up_page=255)
Sets which page Nextion loads when exiting sleep mode.
std::string device_model_
void all_components_send_state_(bool force_update=false)
std::string firmware_version_
void set_nextion_sensor_state(int queue_type, const std::string &name, float state)
Set the nextion sensor state object.
void add_addt_command_to_queue(NextionComponentBase *component) override
uint16_t max_commands_per_loop_
uint16_t startup_override_ms_
Timeout before forcing setup complete.
void process_nextion_commands_()
void add_to_get_queue(NextionComponentBase *component) override
bool send_command_printf(const char *format,...) __attribute__((format(printf
Manually send a raw formatted command to the display.
std::list< NextionQueue * > nextion_queue_
void set_auto_wake_on_touch(bool auto_wake_on_touch)
Sets if Nextion should auto-wake from sleep when touch press occurs.
bool remove_from_q_(bool report_empty=true)
std::vector< NextionComponentBase * > sensortype_
uint16_t touch_sleep_timeout_
bool add_no_result_to_queue_with_printf_(const std::string &variable_name, const char *format,...) __attribute__((format(printf
void set_touch_sleep_timeout(uint16_t touch_sleep_timeout=0)
Set the touch sleep timeout of the display using the thsp command.
CallbackManager< void()> setup_callback_
std::string command_data_
optional< float > brightness_
CallbackManager< void()> wake_callback_
bool is_updating() override
Check if the TFT update process is currently running.
uint16_t recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag)
void goto_page(const char *page)
Show the page with a given name.
bool void add_no_result_to_queue_with_set_internal_(const std::string &variable_name, const std::string &variable_name_to_send, int32_t state_value, bool is_sleep_safe=false)
bool void add_no_result_to_queue_with_command_(const std::string &variable_name, const std::string &command)
CallbackManager< void(StringRef, bool)> custom_binary_sensor_callback_
bool send_command(const char *command)
Manually send a raw command to the display.
std::string serial_number_
CallbackManager< void()> sleep_callback_
void reset_(bool reset_nextion=true)
void update_all_components()
void process_pending_in_queue_()
Process any commands in the queue that are pending due to command spacing.
void add_no_result_to_queue_(const std::string &variable_name)
CallbackManager< void(uint8_t, uint8_t, bool)> touch_callback_
void print_queue_members_()
void dump_config() override
NextionCommandPacer command_pacer_
void set_nextion_text_state(const std::string &name, const std::string &state)
bool add_no_result_to_queue_with_ignore_sleep_printf_(const std::string &variable_name, const char *format,...) __attribute__((format(printf
CallbackManager< void()> buffer_overflow_callback_
void set_writer(const nextion_writer_t &writer)
CallbackManager< void(StringRef, StringRef)> custom_text_sensor_callback_
void add_no_result_to_queue_with_pending_command_(const std::string &variable_name, const std::string &command)
Add a command to the Nextion queue with a pending command for retry.
void add_no_result_to_queue_with_set(NextionComponentBase *component, int32_t state_value) override
CallbackManager< void(StringRef, bool)> custom_switch_callback_
void update_components_by_prefix(const std::string &prefix)
uint32_t tft_upload_watchdog_timeout_
WDT timeout in ms (0 = no adjustment)
void set_backlight_brightness(float brightness)
Set the brightness of the backlight.
optional< std::array< uint8_t, N > > read_array()
void write_str(const char *str)
bool read_byte(uint8_t *data)
void write_array(const uint8_t *data, size_t len)
const Component * component
display::DisplayWriter< Nextion > nextion_writer_t
const char int const __FlashStringHelper * format
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
size_t size_t const char va_start(args, fmt)
void HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.