Compare commits
2 Commits
c60f4e97ce
...
4750a22ddf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4750a22ddf | ||
|
|
7e70e7c3c1 |
@@ -15,18 +15,15 @@ substitutions:
|
||||
##############################################
|
||||
|
||||
##### DON'T CHANGE THIS #####
|
||||
upload_tft_baud_rate: "921600"
|
||||
upload_tft_baud_rate: "921600" # To do: Move to UI
|
||||
#############################
|
||||
|
||||
##### External components #####
|
||||
external_components:
|
||||
- source:
|
||||
type: git
|
||||
url: https://github.com/edwardtfn/esphome
|
||||
ref: nextion-23
|
||||
- source: github://pr#6192 # Change this when that PR gets released (2024.2?)
|
||||
components:
|
||||
- nextion
|
||||
refresh: 300s
|
||||
refresh: 3s # Change this before the release: 300s
|
||||
|
||||
api:
|
||||
on_client_connected:
|
||||
@@ -114,14 +111,14 @@ script:
|
||||
ESP_LOGD(TAG, "Waiting for empty UART and Nextion queues");
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (disp1->queue_size() < 1);
|
||||
- lambda: !lambda return (tf_uart->available() < 1);
|
||||
- lambda: return (disp1->queue_size() < 1);
|
||||
- lambda: return (tf_uart->available() < 1);
|
||||
timeout: 10s
|
||||
- delay: 2s
|
||||
- lambda: |-
|
||||
static const char *const TAG = "addon_upload_tft.script.nextion_upload";
|
||||
ESP_LOGD(TAG, "Starting TFT upload...");
|
||||
id(tft_upload_result) = disp1->upload_tft();
|
||||
id(tft_upload_result) = disp1->upload_tft(!disp1->is_setup());
|
||||
ESP_LOGD(TAG, "TFT upload: %s", esphome::nextion::Nextion::tft_upload_result_to_string(id(tft_upload_result)));
|
||||
|
||||
- id: open_upload_dialog
|
||||
@@ -272,7 +269,7 @@ script:
|
||||
- lambda: page_id->update();
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (page_id->state == 26);
|
||||
- lambda: return (page_id->state == 26);
|
||||
timeout: 2s
|
||||
- script.execute:
|
||||
id: report_upload_progress
|
||||
@@ -289,20 +286,24 @@ script:
|
||||
- script.wait: stop_all
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (!id(tft_is_valid));
|
||||
- lambda: return (!id(tft_is_valid));
|
||||
timeout: 1s
|
||||
|
||||
### Attempt twice at the target baud rate
|
||||
- script.execute:
|
||||
id: upload_tft_sequence_attempt
|
||||
baud_rate: !lambda return id(baud_rate_target);
|
||||
- script.wait: upload_tft_sequence_attempt
|
||||
- if:
|
||||
condition:
|
||||
- lambda: return disp1->is_setup();
|
||||
then:
|
||||
- script.execute:
|
||||
id: upload_tft_sequence_attempt
|
||||
baud_rate: !lambda return id(baud_rate_target);
|
||||
- script.wait: upload_tft_sequence_attempt
|
||||
|
||||
### Attempt twice at the original baud rate
|
||||
- if:
|
||||
condition:
|
||||
- lambda: |-
|
||||
return (id(baud_rate_original) != id(baud_rate_target));
|
||||
return ((id(baud_rate_original) != id(baud_rate_target)) or (!disp1->is_setup()));
|
||||
then:
|
||||
- script.execute:
|
||||
id: upload_tft_sequence_attempt
|
||||
@@ -327,7 +328,7 @@ script:
|
||||
- script.wait: report_upload_progress
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (!id(tft_is_valid));
|
||||
- lambda: return (!id(tft_is_valid));
|
||||
timeout: 3s
|
||||
- switch.turn_off: screen_power
|
||||
- delay: 2s
|
||||
@@ -345,7 +346,7 @@ script:
|
||||
- script.wait: report_upload_progress
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (!id(tft_is_valid));
|
||||
- lambda: return (!id(tft_is_valid));
|
||||
timeout: 5s
|
||||
- script.execute:
|
||||
id: report_upload_progress
|
||||
@@ -353,12 +354,12 @@ script:
|
||||
- script.wait: report_upload_progress
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (!id(tft_is_valid));
|
||||
- lambda: return (!id(tft_is_valid));
|
||||
timeout: 5s
|
||||
- switch.turn_off: screen_power
|
||||
- delay: 2s
|
||||
# Restart ESPHome
|
||||
- lambda: !lambda App.safe_reboot();
|
||||
- lambda: App.safe_reboot();
|
||||
|
||||
### This code should never run
|
||||
- delay: 2s
|
||||
@@ -398,7 +399,7 @@ script:
|
||||
mode: single
|
||||
then:
|
||||
- logger.log: "Attempting to upload TFT"
|
||||
- lambda: !lambda id(tft_upload_attempt)++;
|
||||
- lambda: id(tft_upload_attempt)++;
|
||||
- lambda: |-
|
||||
char update_msg[128];
|
||||
sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps", id(tft_upload_attempt), tf_uart->get_baud_rate());
|
||||
@@ -407,7 +408,7 @@ script:
|
||||
- script.wait: report_upload_progress
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (!id(tft_is_valid));
|
||||
- lambda: return (!id(tft_is_valid));
|
||||
timeout: 1s
|
||||
- script.execute: nextion_upload
|
||||
- script.wait: nextion_upload
|
||||
@@ -419,14 +420,16 @@ script:
|
||||
- script.wait: report_upload_progress
|
||||
- if:
|
||||
condition:
|
||||
not:
|
||||
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::UNKNOWN;
|
||||
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::UPLOAD_IN_PROGRESS;
|
||||
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::NEXTION_ERROR_PREPARATION_FAILED;
|
||||
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::NEXTION_ERROR_INVALID_RESPONSE;
|
||||
- lambda: |-
|
||||
return
|
||||
id(tft_upload_result) != esphome::nextion::Nextion::TFTUploadResult::UNKNOWN and
|
||||
id(tft_upload_result) != esphome::nextion::Nextion::TFTUploadResult::UPLOAD_IN_PROGRESS and
|
||||
id(tft_upload_result) != esphome::nextion::Nextion::TFTUploadResult::NEXTION_ERROR_PREPARATION_FAILED and
|
||||
id(tft_upload_result) != esphome::nextion::Nextion::TFTUploadResult::NEXTION_ERROR_INVALID_RESPONSE;
|
||||
then:
|
||||
- delay: 5s
|
||||
- lambda: |-
|
||||
ESP_LOGI("addon_upload_tft.script.upload_tft_attempt", "Restarting ESPHome");
|
||||
App.safe_reboot();
|
||||
|
||||
- id: !extend watchdog
|
||||
|
||||
Reference in New Issue
Block a user