Stop timers before upload tft

This commit is contained in:
Edward Firmo
2023-12-17 23:41:18 +01:00
parent 5f1c289f5b
commit a3b55e341f

View File

@@ -20,23 +20,6 @@ substitutions:
upload_tft_baud_rate: "0"
#############################
#external_components:
# - source: github://pr#3256 # adds esp-idf support to http_request
# components:
# - http_request
# - source: github://pr#5910
# components:
# - nextion
# - uart
# refresh: 1s
##### HTTP REQUEST #####
# Enables http client #
# for upload_tft. #
########################
#http_request:
# id: httpclient
api:
services:
##### SERVICE TO UPDATE THE TFT FILE from URL #####
@@ -228,6 +211,25 @@ script:
}
};
auto send_nextion_command = [](const std::string &command) -> bool
{
static const char *const TAG = "script.upload_tft.send_nextion_command";
ESP_LOGD(TAG, "Sending: %s", command.c_str());
id(tf_uart).write_str(command.c_str());
const uint8_t to_send[3] = {0xFF, 0xFF, 0xFF};
id(tf_uart).write_array(to_send, sizeof(to_send));
return true;
};
auto disable_boot_timers_ = [send_nextion_command]() {
ESP_LOGD(TAG, "Disabling timers on boot page");
send_nextion_command("timer.en=0");
send_nextion_command("tm_esphome.en=0");
send_nextion_command("tm_pageid.en=0");
send_nextion_command("wakeup_timer.en=0");
send_nextion_command("dim=1");
};
std::string framework = "Unknown";
#ifdef ARDUINO
framework = "Arduino";
@@ -235,6 +237,7 @@ script:
framework = "ESP-IDF";
#endif
disable_boot_timers_();
if (disp1->is_setup()) {
disp1->set_backlight_brightness(1);
disp1->set_component_text_printf("confirm.title", "Upload TFT\\r%s", framework.c_str());
@@ -276,16 +279,6 @@ script:
uart->setup();
};
auto send_nextion_command = [](const std::string &command) -> bool
{
static const char *const TAG = "script.upload_tft.send_nextion_command";
ESP_LOGD(TAG, "Sending: %s", command.c_str());
id(tf_uart).write_str(command.c_str());
const uint8_t to_send[3] = {0xFF, 0xFF, 0xFF};
id(tf_uart).write_array(to_send, sizeof(to_send));
return true;
};
auto recv_ret_string_ = [](std::string &response, uint32_t timeout, bool recv_flag) -> uint16_t
{
static const char *const TAG = "script.upload_tft.recv_ret_string_";
@@ -905,6 +898,7 @@ script:
ESP_LOGW(TAG, "Try #1 failed");
if (disp1->is_setup()) display_wrapped_text->execute("confirm.body", "Try #1 failed", 18);
delay_seconds_(5);
disable_boot_timers_();
sprintf(update_msg, "Try #2 at %d bps", target_upload_baud_rate_);
ESP_LOGD(TAG, update_msg);
if (disp1->is_setup()) display_wrapped_text->execute("confirm.body", update_msg, 18);
@@ -912,6 +906,7 @@ script:
ESP_LOGW(TAG, "Try #2 failed");
if (disp1->is_setup()) display_wrapped_text->execute("confirm.body", "Try #2 failed", 18);
delay_seconds_(5);
disable_boot_timers_();
sprintf(update_msg, "Try #3 at %d bps", original_baud_rate_);
ESP_LOGD(TAG, update_msg);
if (disp1->is_setup()) display_wrapped_text->execute("confirm.body", update_msg, 18);
@@ -926,7 +921,15 @@ script:
delay_seconds_(2);
ESP_LOGD(TAG, "Turn on Nextion");
id(screen_power).turn_on();
delay_seconds_(10);
delay_seconds_(2);
disable_boot_timers_();
send_nextion_command("vis 255,0");
exit_reparse->execute();
delay_seconds_(3);
disable_boot_timers_();
send_nextion_command("vis 255,0");
delay_seconds_(4);
disable_boot_timers_();
sprintf(update_msg, "Try #4 at %d bps", original_baud_rate_);
ESP_LOGD(TAG, update_msg);
if (disp1->is_setup()) {
@@ -942,10 +945,12 @@ script:
}
if (upload_tft_(url, original_baud_rate_)) id(restart_nspanel).press();
ESP_LOGW(TAG, "Try #4 failed");
disable_boot_timers_();
if (disp1->is_setup()) {
display_wrapped_text->execute("confirm.body", "Try #4 failed.", 18);
delay_seconds_(3);
}
disable_boot_timers_();
sprintf(update_msg, "Try #5 at %d bps", 115200);
ESP_LOGD(TAG, update_msg);
if (disp1->is_setup()) {