From d1d19ffb062fae6688c523e5ae919032788c5680 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Fri, 9 Feb 2024 19:32:07 +0100 Subject: [PATCH] upload_tft_baud_rate on UI --- ReleaseNotes.md | 5 + .../nspanel_esphome_addon_upload_tft.yaml | 101 +++++++++--------- advanced/esphome/nspanel_esphome_core.yaml | 12 +-- 3 files changed, 59 insertions(+), 59 deletions(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 0fabd70..2df2310 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -460,6 +460,7 @@ ensuring users are well-informed for successful system setup and operation. | Enhanced Memory Allocation When Uploading TFT (`esp-idf` only) | Enhancement | `ESPHome` | | Expanded Visualization on Chips | Enhancement | `Blueprint` | | Direct TFT Transfer from GitHub for Arduino Users | Enhancement | `ESPHome` | +| Baud Rate Adjustment for TFT Uploads | Enhancement | `ESPHome` | | Update docs (install.md) with memory requirements (#1720) | Documentation | `Documentation` | @@ -506,6 +507,10 @@ This streamlines the update workflow, removing the need for intermediate steps l This update addresses frequent user-reported compilation errors in ESPHome, attributed to insufficient memory on compiler servers. The updated section outlines recommended memory configurations for different installation scenarios, ensuring smoother compilation processes. A special acknowledgement to @andythomas for his valuable contributions to this update. +- **Baud Rate Adjustment for TFT Uploads**: This update introduces a baud rate selector in the device's "Configuration" area, +allowing users to lower the transfer speed from the default 921600 bps. +This enhancement is particularly useful for troubleshooting transfer issues, +providing a straightforward method to improve transfer reliability by adjusting the speed to accommodate different system capabilities. For support, feedback, or detailed information about this update, visit our [GitHub repository](https://github.com/Blackymas/NSPanel_HA_Blueprint) diff --git a/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml b/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml index 6dd44cd..05482d2 100644 --- a/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml +++ b/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml @@ -14,10 +14,6 @@ substitutions: nextion_update_base_url: "https://raw.githubusercontent.com/Blackymas/NSPanel_HA_Blueprint/" ############################################## - ##### DON'T CHANGE THIS ##### - upload_tft_baud_rate: "921600" # To do: Move to UI - ############################# - ##### External components ##### external_components: - source: github://pr#6192 # Change this when that PR gets released (2024.2?) @@ -77,11 +73,6 @@ globals: restore_value: false initial_value: '115200' - - id: baud_rate_target - type: uint - restore_value: false - initial_value: ${upload_tft_baud_rate} - - id: tft_is_valid type: bool restore_value: false @@ -105,6 +96,8 @@ globals: script: - id: nextion_upload mode: single + parameters: + baud_rate: uint32_t then: - lambda: |- static const char *const TAG = "addon_upload_tft.script.nextion_upload"; @@ -118,7 +111,7 @@ script: - 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(!disp1->is_setup()); + id(tft_upload_result) = disp1->upload_tft(baud_rate, !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 @@ -146,7 +139,7 @@ script: ESP_LOGI(TAG, "Substitutions:"); ESP_LOGI(TAG, " nextion_update_url: ${nextion_update_url}"); ESP_LOGI(TAG, " nextion_update_base_url: ${nextion_update_base_url}"); - ESP_LOGI(TAG, " upload_tft_baud_rate: ${upload_tft_baud_rate}"); + ESP_LOGI(TAG, " TFT upload baud rate: %s bps", tft_upload_baud_rate->state.c_str()); - id: report_upload_progress mode: restart @@ -231,35 +224,12 @@ script: nextion_status->execute(); - uint32_t supported_baud_rates[] = {2400, 4800, 9600, 19200, 31250, 38400, 57600, 115200, 230400, 250000, 256000, 512000, 921600}; - - auto is_baud_rate_supported = [supported_baud_rates](uint32_t baud_rate_requested) -> bool { - size_t size = sizeof(supported_baud_rates) / sizeof(supported_baud_rates[0]); - for (size_t i = 0; i < size; ++i) { - if (supported_baud_rates[i] == baud_rate_requested) { - return true; - } - } - return false; // Return false if not found - }; - // The upload process starts here ESP_LOGD(TAG, "Starting the upload script"); - - // Detect baud rates to be used - id(baud_rate_original) = tf_uart->get_baud_rate(); - if (!is_baud_rate_supported(id(baud_rate_original))) id(baud_rate_original) = 115200; - - std::string upload_tft_baud_rate_string = "${upload_tft_baud_rate}"; - id(baud_rate_target) = stoi(upload_tft_baud_rate_string); - if (!is_baud_rate_supported(id(baud_rate_target))) id(baud_rate_target) = id(baud_rate_original); - - ESP_LOGD(TAG, " Target upload baud rate: %d bps", id(baud_rate_target)); - ESP_LOGD(TAG, " Current baud rate: %" PRIu32 " bps", tf_uart->get_baud_rate()); ESP_LOGD(TAG, " Valid TFT: %s", YESNO(id(tft_is_valid))); - - // Upload URL - ESP_LOGD(TAG, " Upload URL: %s", url.c_str()); + ESP_LOGD(TAG, " Current baud rate: %" PRIu32 " bps", tf_uart->get_baud_rate()); + ESP_LOGD(TAG, " Target upload baud rate: %s bps", tft_upload_baud_rate->state.c_str()); + ESP_LOGD(TAG, " Upload URL: %s", url.c_str()); disp1->set_tft_url(url.c_str()); - lambda: if (id(tft_is_valid)) disp1->goto_page("home"); @@ -290,31 +260,25 @@ script: timeout: 1s ### Attempt twice at the target baud rate - - 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 + - script.execute: + id: upload_tft_sequence_attempt + baud_rate: !lambda return stoi(tft_upload_baud_rate->state); + - 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)) or (!disp1->is_setup())); + - lambda: return (stoi(tft_upload_baud_rate->state) != tf_uart->get_baud_rate()); then: - script.execute: id: upload_tft_sequence_attempt - baud_rate: !lambda return id(baud_rate_original); + baud_rate: 0 - script.wait: upload_tft_sequence_attempt ### Attempt twice at the Nextion's default baud rate (115200bps) - if: condition: - - lambda: |- - return (id(baud_rate_original) != 115200 and id(baud_rate_target) != 115200); + - lambda: return (stoi(tft_upload_baud_rate->state) != 115200 and tf_uart->get_baud_rate() != 115200); then: - script.execute: id: upload_tft_sequence_attempt @@ -373,7 +337,7 @@ script: - id: upload_tft_sequence_attempt mode: single parameters: - baud_rate: uint + baud_rate: uint32_t then: - script.execute: nextion_status - script.wait: nextion_status @@ -391,12 +355,16 @@ script: count: 2 then: # First attempt - - script.execute: upload_tft_attempt + - script.execute: + id: upload_tft_attempt + baud_rate: !lambda return baud_rate; - script.wait: upload_tft_attempt - delay: 5s - id: upload_tft_attempt mode: single + parameters: + baud_rate: uint32_t then: - logger.log: "Attempting to upload TFT" - lambda: id(tft_upload_attempt)++; @@ -410,7 +378,9 @@ script: condition: - lambda: return (!id(tft_is_valid)); timeout: 1s - - script.execute: nextion_upload + - script.execute: + id: nextion_upload + baud_rate: !lambda return baud_rate; - script.wait: nextion_upload - lambda: |- char update_msg[128]; @@ -465,6 +435,31 @@ select: on_value: - script.execute: set_tft_file + - id: tft_upload_baud_rate + name: Update TFT display - Baud rate + platform: template + options: + - "2400" + - "4800" + - "9600" + - "19200" + - "31250" + - "38400" + - "57600" + - "115200" + - "230400" + - "250000" + - "256000" + - "512000" + - "921600" + initial_option: "921600" + optimistic: true + restore_value: true + internal: false + entity_category: config + disabled_by_default: true + icon: mdi:swap-horizontal + sensor: - id: !extend display_mode on_value: diff --git a/advanced/esphome/nspanel_esphome_core.yaml b/advanced/esphome/nspanel_esphome_core.yaml index 65648f9..8d1739c 100644 --- a/advanced/esphome/nspanel_esphome_core.yaml +++ b/advanced/esphome/nspanel_esphome_core.yaml @@ -2560,7 +2560,7 @@ script: - id: set_baud_rate mode: restart parameters: - baud_rate: int + baud_rate: uint32_t definitive: bool then: - if: @@ -2569,7 +2569,7 @@ script: then: - lambda: |- static const char *const TAG = "script.set_baud_rate"; - ESP_LOGD(TAG, "Baud rate changing from %" PRIu32 " to %i bps", tf_uart->get_baud_rate(), baud_rate); + ESP_LOGD(TAG, "Baud rate changing from %" PRIu32 " to %" PRIu32 " bps", tf_uart->get_baud_rate(), baud_rate); ESP_LOGD(TAG, "Flush UART"); - wait_until: condition: @@ -2577,8 +2577,8 @@ script: timeout: 5s - lambda: |- static const char *const TAG = "script.set_baud_rate"; - ESP_LOGD(TAG, "Sending instruction '%s=%i' to Nextion", definitive ? "bauds" : "baud", baud_rate); - disp1->send_command_printf("%s=%i", definitive ? "bauds" : "baud", baud_rate); + ESP_LOGD(TAG, "Sending instruction '%s=%" PRIu32 "' to Nextion", definitive ? "bauds" : "baud", baud_rate); + disp1->send_command_printf("%s=%" PRIu32, definitive ? "bauds" : "baud", baud_rate); ESP_LOGD(TAG, "Flush UART"); - wait_until: condition: @@ -2586,10 +2586,10 @@ script: timeout: 5s - lambda: |- static const char *const TAG = "script.set_baud_rate"; - ESP_LOGD(TAG, "Set ESPHome new baud rate to %i bps", baud_rate); + ESP_LOGD(TAG, "Set ESPHome new baud rate to %" PRIu32 " bps", baud_rate); tf_uart->set_baud_rate(baud_rate); tf_uart->load_settings(); - ESP_LOGD(TAG, "Baud rate is changet to %i bps", baud_rate); + ESP_LOGD(TAG, "Current baud rate: %" PRIu32 " bps", tf_uart->get_baud_rate()); - id: set_brightness mode: restart