mirror of
https://github.com/esphome/esphome.git
synced 2025-07-29 14:46:40 +00:00
[nextion] Cached timing optimization (#9150)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
parent
eb97781f68
commit
7dbad42470
@ -71,13 +71,13 @@ bool Nextion::check_connect_() {
|
|||||||
}
|
}
|
||||||
this->send_command_("connect");
|
this->send_command_("connect");
|
||||||
|
|
||||||
this->comok_sent_ = millis();
|
this->comok_sent_ = App.get_loop_component_start_time();
|
||||||
this->ignore_is_setup_ = false;
|
this->ignore_is_setup_ = false;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (millis() - this->comok_sent_ <= 500) // Wait 500 ms
|
if (App.get_loop_component_start_time() - this->comok_sent_ <= 500) // Wait 500 ms
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::string response;
|
std::string response;
|
||||||
@ -318,9 +318,9 @@ void Nextion::loop() {
|
|||||||
|
|
||||||
if (!this->nextion_reports_is_setup_) {
|
if (!this->nextion_reports_is_setup_) {
|
||||||
if (this->started_ms_ == 0)
|
if (this->started_ms_ == 0)
|
||||||
this->started_ms_ = millis();
|
this->started_ms_ = App.get_loop_component_start_time();
|
||||||
|
|
||||||
if (this->started_ms_ + this->startup_override_ms_ < millis()) {
|
if (this->started_ms_ + this->startup_override_ms_ < App.get_loop_component_start_time()) {
|
||||||
ESP_LOGD(TAG, "Manual ready set");
|
ESP_LOGD(TAG, "Manual ready set");
|
||||||
this->nextion_reports_is_setup_ = true;
|
this->nextion_reports_is_setup_ = true;
|
||||||
}
|
}
|
||||||
@ -432,7 +432,7 @@ void Nextion::process_nextion_commands_() {
|
|||||||
case 0x01: // instruction sent by user was successful
|
case 0x01: // instruction sent by user was successful
|
||||||
|
|
||||||
ESP_LOGVV(TAG, "Cmd OK");
|
ESP_LOGVV(TAG, "Cmd OK");
|
||||||
ESP_LOGN(TAG, "this->nextion_queue_.empty() %s", this->nextion_queue_.empty() ? "True" : "False");
|
ESP_LOGN(TAG, "this->nextion_queue_.empty() %s", YESNO(this->nextion_queue_.empty()));
|
||||||
|
|
||||||
this->remove_from_q_();
|
this->remove_from_q_();
|
||||||
if (!this->is_setup_) {
|
if (!this->is_setup_) {
|
||||||
@ -444,7 +444,7 @@ void Nextion::process_nextion_commands_() {
|
|||||||
}
|
}
|
||||||
#ifdef USE_NEXTION_COMMAND_SPACING
|
#ifdef USE_NEXTION_COMMAND_SPACING
|
||||||
this->command_pacer_.mark_sent(); // Here is where we should mark the command as sent
|
this->command_pacer_.mark_sent(); // Here is where we should mark the command as sent
|
||||||
ESP_LOGN(TAG, "Command spacing: marked command sent at %u ms", millis());
|
ESP_LOGN(TAG, "Command spacing: marked command sent");
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case 0x02: // invalid Component ID or name was used
|
case 0x02: // invalid Component ID or name was used
|
||||||
@ -828,7 +828,7 @@ void Nextion::process_nextion_commands_() {
|
|||||||
this->command_data_.erase(0, to_process_length + COMMAND_DELIMITER.length() + 1);
|
this->command_data_.erase(0, to_process_length + COMMAND_DELIMITER.length() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ms = millis();
|
uint32_t ms = App.get_loop_component_start_time();
|
||||||
|
|
||||||
if (!this->nextion_queue_.empty() && this->nextion_queue_.front()->queue_time + this->max_q_age_ms_ < ms) {
|
if (!this->nextion_queue_.empty() && this->nextion_queue_.front()->queue_time + this->max_q_age_ms_ < ms) {
|
||||||
for (size_t i = 0; i < this->nextion_queue_.size(); i++) {
|
for (size_t i = 0; i < this->nextion_queue_.size(); i++) {
|
||||||
@ -967,9 +967,9 @@ uint16_t Nextion::recv_ret_string_(std::string &response, uint32_t timeout, bool
|
|||||||
bool exit_flag = false;
|
bool exit_flag = false;
|
||||||
bool ff_flag = false;
|
bool ff_flag = false;
|
||||||
|
|
||||||
start = millis();
|
start = App.get_loop_component_start_time();
|
||||||
|
|
||||||
while ((timeout == 0 && this->available()) || millis() - start <= timeout) {
|
while ((timeout == 0 && this->available()) || App.get_loop_component_start_time() - start <= timeout) {
|
||||||
if (!this->available()) {
|
if (!this->available()) {
|
||||||
App.feed_wdt();
|
App.feed_wdt();
|
||||||
delay(1);
|
delay(1);
|
||||||
@ -1038,7 +1038,7 @@ void Nextion::add_no_result_to_queue_(const std::string &variable_name) {
|
|||||||
nextion_queue->component = new nextion::NextionComponentBase;
|
nextion_queue->component = new nextion::NextionComponentBase;
|
||||||
nextion_queue->component->set_variable_name(variable_name);
|
nextion_queue->component->set_variable_name(variable_name);
|
||||||
|
|
||||||
nextion_queue->queue_time = millis();
|
nextion_queue->queue_time = App.get_loop_component_start_time();
|
||||||
|
|
||||||
this->nextion_queue_.push_back(nextion_queue);
|
this->nextion_queue_.push_back(nextion_queue);
|
||||||
|
|
||||||
@ -1085,7 +1085,7 @@ void Nextion::add_no_result_to_queue_with_pending_command_(const std::string &va
|
|||||||
|
|
||||||
nextion_queue->component = new nextion::NextionComponentBase;
|
nextion_queue->component = new nextion::NextionComponentBase;
|
||||||
nextion_queue->component->set_variable_name(variable_name);
|
nextion_queue->component->set_variable_name(variable_name);
|
||||||
nextion_queue->queue_time = millis();
|
nextion_queue->queue_time = App.get_loop_component_start_time();
|
||||||
nextion_queue->pending_command = command; // Store command for retry
|
nextion_queue->pending_command = command; // Store command for retry
|
||||||
|
|
||||||
this->nextion_queue_.push_back(nextion_queue);
|
this->nextion_queue_.push_back(nextion_queue);
|
||||||
@ -1224,7 +1224,7 @@ void Nextion::add_to_get_queue(NextionComponentBase *component) {
|
|||||||
new (nextion_queue) nextion::NextionQueue();
|
new (nextion_queue) nextion::NextionQueue();
|
||||||
|
|
||||||
nextion_queue->component = component;
|
nextion_queue->component = component;
|
||||||
nextion_queue->queue_time = millis();
|
nextion_queue->queue_time = App.get_loop_component_start_time();
|
||||||
|
|
||||||
ESP_LOGN(TAG, "Queue %s: %s", component->get_queue_type_string().c_str(), component->get_variable_name().c_str());
|
ESP_LOGN(TAG, "Queue %s: %s", component->get_queue_type_string().c_str(), component->get_variable_name().c_str());
|
||||||
|
|
||||||
@ -1256,7 +1256,7 @@ void Nextion::add_addt_command_to_queue(NextionComponentBase *component) {
|
|||||||
new (nextion_queue) nextion::NextionQueue();
|
new (nextion_queue) nextion::NextionQueue();
|
||||||
|
|
||||||
nextion_queue->component = component;
|
nextion_queue->component = component;
|
||||||
nextion_queue->queue_time = millis();
|
nextion_queue->queue_time = App.get_loop_component_start_time();
|
||||||
|
|
||||||
this->waveform_queue_.push_back(nextion_queue);
|
this->waveform_queue_.push_back(nextion_queue);
|
||||||
if (this->waveform_queue_.size() == 1)
|
if (this->waveform_queue_.size() == 1)
|
||||||
|
@ -67,8 +67,8 @@ int Nextion::upload_by_chunks_(HTTPClient &http_client, uint32_t &range_start) {
|
|||||||
ESP_LOGV(TAG, "Fetch %" PRIu16 " bytes", buffer_size);
|
ESP_LOGV(TAG, "Fetch %" PRIu16 " bytes", buffer_size);
|
||||||
uint16_t read_len = 0;
|
uint16_t read_len = 0;
|
||||||
int partial_read_len = 0;
|
int partial_read_len = 0;
|
||||||
const uint32_t start_time = millis();
|
const uint32_t start_time = App.get_loop_component_start_time();
|
||||||
while (read_len < buffer_size && millis() - start_time < 5000) {
|
while (read_len < buffer_size && App.get_loop_component_start_time() - start_time < 5000) {
|
||||||
if (http_client.getStreamPtr()->available() > 0) {
|
if (http_client.getStreamPtr()->available() > 0) {
|
||||||
partial_read_len =
|
partial_read_len =
|
||||||
http_client.getStreamPtr()->readBytes(reinterpret_cast<char *>(buffer) + read_len, buffer_size - read_len);
|
http_client.getStreamPtr()->readBytes(reinterpret_cast<char *>(buffer) + read_len, buffer_size - read_len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user