diff --git a/esphome/nspanel_esphome_core_boot.yaml b/esphome/nspanel_esphome_core_boot.yaml index cf2d7952d..596329174 100644 --- a/esphome/nspanel_esphome_core_boot.yaml +++ b/esphome/nspanel_esphome_core_boot.yaml @@ -52,9 +52,16 @@ esphome: then: - script.execute: boot_initialize - - priority: 600.1 + - priority: 400.1 then: - script.wait: scan_baud_rate + - if: + condition: + - lambda: return not disp1->is_setup(); + then: + - wait_until: + condition: + - lambda: return disp1->is_setup(); - script.execute: id: boot_sequence show_boot_page: true diff --git a/esphome/nspanel_esphome_core_hw_display.yaml b/esphome/nspanel_esphome_core_hw_display.yaml index eb371c3ca..f25863a4d 100644 --- a/esphome/nspanel_esphome_core_hw_display.yaml +++ b/esphome/nspanel_esphome_core_hw_display.yaml @@ -117,14 +117,14 @@ esphome: build_flags: - -D NSPANEL_HA_BLUEPRINT_CORE_HW_DISPLAY on_boot: - - priority: 700.5 + - priority: 700.${BOOT_STEP_HW_DISPLAY} then: - wait_until: condition: - lambda: return (display_command_spacing->state >= 0 and display_command_spacing->state <= UINT8_MAX); - lambda: disp1->set_command_spacing(static_cast(display_command_spacing->state)); - #- priority: 600.5 + #- priority: 600.${BOOT_STEP_HW_DISPLAY} # then: #- if: # condition: @@ -158,7 +158,7 @@ esphome: # - switch.turn_on: screen_power on_shutdown: - - priority: 600.5 + - priority: 600.${BOOT_STEP_HW_DISPLAY} then: - switch.turn_off: screen_power - priority: 0.5 @@ -167,7 +167,7 @@ esphome: id: nextion_init state: false -external_components: # To-do: Remove this when PR#7948 is merged and released (v2025.1.0?) +external_components: # To-do: Remove this when both PR#7948 and PR#7961 are merged and released (v2025.1.0?) - source: type: git url: https://github.com/edwardtfn/esphome diff --git a/esphome/nspanel_esphome_core_hw_display_uart.yaml b/esphome/nspanel_esphome_core_hw_display_uart.yaml index 7acb0ae26..21c165135 100644 --- a/esphome/nspanel_esphome_core_hw_display_uart.yaml +++ b/esphome/nspanel_esphome_core_hw_display_uart.yaml @@ -11,6 +11,7 @@ substitutions: MAX_SCAN_RETRIES: '255' # Maximum number of complete scan cycles, limited to 255 (UINT8_MAX) SCAN_INTERVAL: '500' # Interval between connection checks in ms VERIFY_DELAY: '1000' # Delay before verifying connection in ms + WAIT_TIME: '10000' # Time to wait for the Nextion display to respond display: - id: !extend disp1 @@ -23,29 +24,45 @@ display: esphome: on_boot: - priority: 600.5 # Before other display initialization - then: - - wait_until: - condition: - - lambda: return disp1->is_setup(); - timeout: 5s - then: - - lambda: |- - ESP_LOGI("script", "Display connected at boot with baud rate %" PRIu32, tf_uart->get_baud_rate()); - if (tf_uart->get_baud_rate() != ${BAUD_RATE}) { - ESP_LOGw("script", "Attempting to switch to target baud rate ${BAUD_RATE} bps"); - set_baud_rate->execute(${BAUD_RATE}, true); - verify_target_baud->execute(); - } - else: - - script.execute: scan_baud_rate + - priority: 600.${BOOT_STEP_HW_DISPLAY} # Before other display initialization + then: + - wait_until: + condition: + - lambda: return not isnan(tf_uart->get_baud_rate()); + timeout: 15s + - wait_until: + condition: &nextion_is_connected + - lambda: return disp1->is_connected(); + timeout: 5s + - if: + condition: *nextion_is_connected + then: + - lambda: |- + ESP_LOGI("script", "Display connected at boot with baud rate %" PRIu32, tf_uart->get_baud_rate()); + if (tf_uart->get_baud_rate() != ${BAUD_RATE}) { + ESP_LOGW("script", "Attempting to switch to target baud rate ${BAUD_RATE} bps"); + set_baud_rate->execute(${BAUD_RATE}, true); + scan_baud_rate->execute(); + } + else: + - script.execute: scan_baud_rate globals: + - id: DEBUG_step + type: uint8_t + restore_value: no + initial_value: '0' + - id: baud_error_count type: uint8_t restore_value: yes initial_value: '0' + - id: baud_scan_started + type: bool + restore_value: no + initial_value: 'false' + - id: baud_scan_index type: uint8_t restore_value: no @@ -56,6 +73,17 @@ globals: restore_value: no initial_value: '0' + - id: baud_rates + type: const std::vector + restore_value: no + initial_value: > # Target rate first, then most common rates, standard rated and then uncommon rates + { + ${BAUD_RATE}, 921600, 115200, + 57600, 38400, 19200, 9600, + 512000, 256000, 250000, + 31250, 4800, 2400 + } + script: - id: !extend dump_config then: @@ -74,13 +102,74 @@ script: mode: restart then: - globals.set: - id: baud_scan_index - value: '0' - - lambda: |- - id(baud_scan_retries)++; - ESP_LOGI("script", "Starting baud rate detection cycle %u (target: ${BAUD_RATE} bps)...", - id(baud_scan_retries)); - - script.execute: try_next_baud_rate + id: baud_scan_started + value: 'true' + - while: + condition: + or: + - lambda: return not disp1->is_connected(); + - lambda: return (tf_uart->get_baud_rate() != ${BAUD_RATE}); + then: + - repeat: + count: 5 + then: + - if: + condition: &nextion_is_NOT_connected + - lambda: return not disp1->is_connected(); + then: + - logger.log: Waiting for Nextion + - wait_until: + condition: *nextion_is_connected + timeout: 1s # ${WAIT_TIME}ms + - if: + condition: + - lambda: return disp1->is_connected(); + then: + - lambda: |- + ESP_LOGI("script", "Nextion detected at %" PRIu32 "bps", tf_uart->get_baud_rate()); + if (tf_uart->get_baud_rate() != ${BAUD_RATE}) { + ESP_LOGI("script", "Trying to set it to ${BAUD_RATE}bps"); + set_baud_rate->execute(${BAUD_RATE}, true); + } + else: + - lambda: |- + ESP_LOGW("script", "Nextion was not detected at %" PRIu32 "bps", tf_uart->get_baud_rate()); + id(baud_scan_index)++; + // Check if we need to start over + if (id(baud_scan_index) >= id(baud_rates).size()) { + id(baud_scan_index) = 0; + if (id(baud_scan_retries) < UINT8_MAX) { + id(baud_scan_retries)++; + } + if (id(baud_error_count) < UINT8_MAX) { + id(baud_error_count)++; + } + ESP_LOGW("script", "Starting new scan cycle %u", id(baud_scan_retries)); + } + const uint32_t current_baud = id(baud_rates)[id(baud_scan_index)]; + ESP_LOGW("script", "Searching for Nextion at %" PRIu32, current_baud); + set_baud_rate->execute(current_baud, (current_baud == ${BAUD_RATE})); + - script.wait: set_baud_rate + - if: + condition: + - lambda: return disp1->is_connected(); + - lambda: return (tf_uart->get_baud_rate() == ${BAUD_RATE}); + then: + - lambda: |- + ESP_LOGI("script", "Nextion detected at %" PRIu32 "bps", tf_uart->get_baud_rate()); + if (not disp1->is_setup()) + disp1->setup(); + - wait_until: + condition: &nextion_is_setup + - lambda: return disp1->is_setup(); + timeout: 5s + - if: + condition: &nextion_is_NOT_setup + - lambda: return not disp1->is_setup(); + then: + - switch.turn_off: screen_power + - delay: 2s + - switch.turn_on: screen_power - id: set_baud_rate mode: restart @@ -90,7 +179,8 @@ script: then: - if: condition: - - lambda: return (tf_uart->get_baud_rate() != baud_rate); + - lambda: return (baud_rate > 0); + - lambda: return (baud_rate != tf_uart->get_baud_rate()); then: - lambda: |- ESP_LOGW("script", "Baud rate changing from %" PRIu32 " to %" PRIu32 " bps", @@ -121,96 +211,9 @@ script: dump_config_uart->stop(); scan_baud_rate->stop(); set_baud_rate->stop(); - try_next_baud_rate->stop(); - verify_target_baud->stop(); - - - id: try_next_baud_rate - mode: restart - then: - - lambda: |- - const std::vector baud_rates = { - ${BAUD_RATE}, 921600, 115200, // Target rate and most common rates first, - 9600, 19200, 57600, 38400, // then some not that uncommon rates, - 512000, 256000, 250000, // and then the uncommon rates - 230400, 31250, 4800, 2400 // with lower rates last - }; - - if (disp1->is_setup()) { - ESP_LOGW("script", "Display connected at %" PRIu32 " bps", tf_uart->get_baud_rate()); - if (tf_uart->get_baud_rate() != ${BAUD_RATE}) { - ESP_LOGW("script", "Attempting to switch to target baud rate ${BAUD_RATE} bps"); - set_baud_rate->execute(${BAUD_RATE}, true); - verify_target_baud->execute(); - } - return; - } - - if (id(baud_scan_index) >= baud_rates.size()) { - ESP_LOGE("script", "Failed to detect display at any baud rate"); - if (id(baud_error_count) < UINT8_MAX) - id(baud_error_count)++; - - const uint8_t max_retries = std::min(static_cast(${MAX_SCAN_RETRIES}), - static_cast(UINT8_MAX)); - if (id(baud_scan_retries) < max_retries) { - ESP_LOGW("script", "Starting new scan cycle (%u/%u)", id(baud_scan_retries) + 1, max_retries); - scan_baud_rate->execute(); - } else { - ESP_LOGE("script", "Maximum retry attempts reached. Display might be disconnected."); - ESP_LOGE("script", "Total errors since boot: %u", id(baud_error_count)); - } - return; - } - - uint32_t current_baud = baud_rates[id(baud_scan_index)]; - ESP_LOGW("script", "Trying baud rate: %" PRIu32, current_baud); - set_baud_rate->execute(current_baud, false); - - # Check connection status multiple times - - repeat: - count: 10 - then: - - if: - condition: - - lambda: return disp1->is_setup(); - then: - - lambda: |- - ESP_LOGW("script", "Display connected at %" PRIu32 " bps", tf_uart->get_baud_rate()); - if (tf_uart->get_baud_rate() != ${BAUD_RATE}) { - ESP_LOGW("script", "Attempting to switch to target baud rate ${BAUD_RATE} bps"); - set_baud_rate->execute(${BAUD_RATE}, true); - verify_target_baud->execute(); - } - else: - - delay: ${SCAN_INTERVAL}ms - - # If we get here, this rate didn't work, try next one - - globals.set: - id: baud_scan_index - value: !lambda return id(baud_scan_index) + 1; - - script.execute: try_next_baud_rate - - - id: verify_target_baud - mode: restart - then: - - delay: ${VERIFY_DELAY}ms - - - if: - condition: - - lambda: return disp1->is_setup(); - then: - - lambda: |- - ESP_LOGI("script", "Successfully configured display at ${BAUD_RATE} bps"); - id(baud_scan_retries) = 0; // Reset retry counter on success - else: - - lambda: |- - ESP_LOGE("script", "Failed to verify connection at target baud rate"); - id(baud_error_count)++; - ESP_LOGW("script", "Will retry scanning process"); - - script.execute: scan_baud_rate select: - - id: baud_rate + - id: baud_rateX name: Baud rate platform: template options: diff --git a/esphome/nspanel_esphome_core_page_boot.yaml b/esphome/nspanel_esphome_core_page_boot.yaml index 4e2773891..46ef77ee8 100644 --- a/esphome/nspanel_esphome_core_page_boot.yaml +++ b/esphome/nspanel_esphome_core_page_boot.yaml @@ -14,6 +14,7 @@ display: - id: !extend disp1 on_setup: then: + - script.wait: scan_baud_rate - lambda: |- page_changed->execute(${PAGE_ID_BOOT}); diff --git a/hmi/dev/nspanel_CJK_eu_code/boot.txt b/hmi/dev/nspanel_CJK_eu_code/boot.txt index 28ece8d8f..82b2bc920 100644 --- a/hmi/dev/nspanel_CJK_eu_code/boot.txt +++ b/hmi/dev/nspanel_CJK_eu_code/boot.txt @@ -74,22 +74,16 @@ Variable (int32) log_max_lines Scope: local Value: 14 -Variable (int32) counter - Attributes - ID : 26 - Scope: local - Value: 0 - Variable (string) json Attributes - ID : 28 + ID : 27 Scope : local Text : Max. Text Size: 100 Variable (string) num_to_str Attributes - ID : 29 + ID : 28 Scope : local Text : Max. Text Size: 10 @@ -330,23 +324,13 @@ Dual-state Button bt_reboot Timer tm_esphome Attributes - ID : 27 + ID : 26 Scope : local Period (ms): 10000 Enabled : yes Events Timer Event - counter.val++ - if(counter.val>360) - { - rest - } - sys0=counter.val%60 - if(sys0==0) - { - bauds=921600 - } click sys_baudrate,1 click initializing,0 doevents diff --git a/hmi/dev/nspanel_CJK_us_code/boot.txt b/hmi/dev/nspanel_CJK_us_code/boot.txt index f5c9a3833..a677af89b 100644 --- a/hmi/dev/nspanel_CJK_us_code/boot.txt +++ b/hmi/dev/nspanel_CJK_us_code/boot.txt @@ -74,22 +74,16 @@ Variable (int32) log_max_lines Scope: local Value: 7 -Variable (int32) counter - Attributes - ID : 26 - Scope: local - Value: 0 - Variable (string) json Attributes - ID : 28 + ID : 27 Scope : local Text : Max. Text Size: 100 Variable (string) num_to_str Attributes - ID : 29 + ID : 28 Scope : local Text : Max. Text Size: 10 @@ -330,23 +324,13 @@ Dual-state Button bt_reboot Timer tm_esphome Attributes - ID : 27 + ID : 26 Scope : local Period (ms): 10000 Enabled : yes Events Timer Event - counter.val++ - if(counter.val>360) - { - rest - } - sys0=counter.val%60 - if(sys0==0) - { - bauds=921600 - } click sys_baudrate,1 click initializing,0 doevents diff --git a/hmi/dev/nspanel_CJK_us_land_code/boot.txt b/hmi/dev/nspanel_CJK_us_land_code/boot.txt index 28ece8d8f..82b2bc920 100644 --- a/hmi/dev/nspanel_CJK_us_land_code/boot.txt +++ b/hmi/dev/nspanel_CJK_us_land_code/boot.txt @@ -74,22 +74,16 @@ Variable (int32) log_max_lines Scope: local Value: 14 -Variable (int32) counter - Attributes - ID : 26 - Scope: local - Value: 0 - Variable (string) json Attributes - ID : 28 + ID : 27 Scope : local Text : Max. Text Size: 100 Variable (string) num_to_str Attributes - ID : 29 + ID : 28 Scope : local Text : Max. Text Size: 10 @@ -330,23 +324,13 @@ Dual-state Button bt_reboot Timer tm_esphome Attributes - ID : 27 + ID : 26 Scope : local Period (ms): 10000 Enabled : yes Events Timer Event - counter.val++ - if(counter.val>360) - { - rest - } - sys0=counter.val%60 - if(sys0==0) - { - bauds=921600 - } click sys_baudrate,1 click initializing,0 doevents diff --git a/hmi/dev/nspanel_blank_code/Program.s.txt b/hmi/dev/nspanel_blank_code/Program.s.txt index 42a7a1f2b..8aeb4d3f6 100644 --- a/hmi/dev/nspanel_blank_code/Program.s.txt +++ b/hmi/dev/nspanel_blank_code/Program.s.txt @@ -6,6 +6,5 @@ Program.s int charset=1 dim=100//Configure backlight recmod=0//Serial data parsing mode:0-Passive mode;1-Active mode - bauds=921600 printh 00 00 00 ff ff ff 88 ff ff ff//Output power on information to serial port page 0 //Power on start page 0 diff --git a/hmi/dev/nspanel_blank_code/blank.txt b/hmi/dev/nspanel_blank_code/blank.txt index 2dcfaa6df..4a64a6e37 100644 --- a/hmi/dev/nspanel_blank_code/blank.txt +++ b/hmi/dev/nspanel_blank_code/blank.txt @@ -24,43 +24,37 @@ Page blank dim=100 tm0.en=1 -Variable (int32) counter - Attributes - ID : 9 - Scope: local - Value: 0 - Variable (string) aux1 Attributes - ID : 10 + ID : 9 Scope : local Text : Max. Text Size: 10 Variable (string) json Attributes - ID : 11 + ID : 10 Scope : local Text : Max. Text Size: 100 Variable (string) num_to_str Attributes - ID : 12 + ID : 11 Scope : local Text : Max. Text Size: 10 Variable (string) version Attributes - ID : 13 + ID : 12 Scope : global Text : 2024.10.2 Max. Text Size: 15 Variable (string) tmp_baudrate Attributes - ID : 14 + ID : 13 Scope : local Text : Max. Text Size: 8 @@ -232,15 +226,5 @@ Timer tm_esphome Events Timer Event - counter.val++ - if(counter.val>360) - { - rest - } - sys0=counter.val%60 - if(sys0==0) - { - bauds=921600 - } click qr0,0 diff --git a/hmi/dev/nspanel_eu_code/boot.txt b/hmi/dev/nspanel_eu_code/boot.txt index 28ece8d8f..82b2bc920 100644 --- a/hmi/dev/nspanel_eu_code/boot.txt +++ b/hmi/dev/nspanel_eu_code/boot.txt @@ -74,22 +74,16 @@ Variable (int32) log_max_lines Scope: local Value: 14 -Variable (int32) counter - Attributes - ID : 26 - Scope: local - Value: 0 - Variable (string) json Attributes - ID : 28 + ID : 27 Scope : local Text : Max. Text Size: 100 Variable (string) num_to_str Attributes - ID : 29 + ID : 28 Scope : local Text : Max. Text Size: 10 @@ -330,23 +324,13 @@ Dual-state Button bt_reboot Timer tm_esphome Attributes - ID : 27 + ID : 26 Scope : local Period (ms): 10000 Enabled : yes Events Timer Event - counter.val++ - if(counter.val>360) - { - rest - } - sys0=counter.val%60 - if(sys0==0) - { - bauds=921600 - } click sys_baudrate,1 click initializing,0 doevents diff --git a/hmi/dev/nspanel_us_code/boot.txt b/hmi/dev/nspanel_us_code/boot.txt index f5c9a3833..a677af89b 100644 --- a/hmi/dev/nspanel_us_code/boot.txt +++ b/hmi/dev/nspanel_us_code/boot.txt @@ -74,22 +74,16 @@ Variable (int32) log_max_lines Scope: local Value: 7 -Variable (int32) counter - Attributes - ID : 26 - Scope: local - Value: 0 - Variable (string) json Attributes - ID : 28 + ID : 27 Scope : local Text : Max. Text Size: 100 Variable (string) num_to_str Attributes - ID : 29 + ID : 28 Scope : local Text : Max. Text Size: 10 @@ -330,23 +324,13 @@ Dual-state Button bt_reboot Timer tm_esphome Attributes - ID : 27 + ID : 26 Scope : local Period (ms): 10000 Enabled : yes Events Timer Event - counter.val++ - if(counter.val>360) - { - rest - } - sys0=counter.val%60 - if(sys0==0) - { - bauds=921600 - } click sys_baudrate,1 click initializing,0 doevents diff --git a/hmi/dev/nspanel_us_land_code/boot.txt b/hmi/dev/nspanel_us_land_code/boot.txt index 28ece8d8f..82b2bc920 100644 --- a/hmi/dev/nspanel_us_land_code/boot.txt +++ b/hmi/dev/nspanel_us_land_code/boot.txt @@ -74,22 +74,16 @@ Variable (int32) log_max_lines Scope: local Value: 14 -Variable (int32) counter - Attributes - ID : 26 - Scope: local - Value: 0 - Variable (string) json Attributes - ID : 28 + ID : 27 Scope : local Text : Max. Text Size: 100 Variable (string) num_to_str Attributes - ID : 29 + ID : 28 Scope : local Text : Max. Text Size: 10 @@ -330,23 +324,13 @@ Dual-state Button bt_reboot Timer tm_esphome Attributes - ID : 27 + ID : 26 Scope : local Period (ms): 10000 Enabled : yes Events Timer Event - counter.val++ - if(counter.val>360) - { - rest - } - sys0=counter.val%60 - if(sys0==0) - { - bauds=921600 - } click sys_baudrate,1 click initializing,0 doevents diff --git a/hmi/nspanel_CJK_eu.HMI b/hmi/nspanel_CJK_eu.HMI index 83efbd82e..f3ab67225 100644 Binary files a/hmi/nspanel_CJK_eu.HMI and b/hmi/nspanel_CJK_eu.HMI differ diff --git a/hmi/nspanel_CJK_eu.tft b/hmi/nspanel_CJK_eu.tft index aa2379188..1048028c8 100644 Binary files a/hmi/nspanel_CJK_eu.tft and b/hmi/nspanel_CJK_eu.tft differ diff --git a/hmi/nspanel_CJK_us.HMI b/hmi/nspanel_CJK_us.HMI index 8cbcd08b2..0d13f0f39 100644 Binary files a/hmi/nspanel_CJK_us.HMI and b/hmi/nspanel_CJK_us.HMI differ diff --git a/hmi/nspanel_CJK_us.tft b/hmi/nspanel_CJK_us.tft index 8b0bef10e..1126f7751 100644 Binary files a/hmi/nspanel_CJK_us.tft and b/hmi/nspanel_CJK_us.tft differ diff --git a/hmi/nspanel_CJK_us_land.HMI b/hmi/nspanel_CJK_us_land.HMI index 2ebc71fc4..9f29fc826 100644 Binary files a/hmi/nspanel_CJK_us_land.HMI and b/hmi/nspanel_CJK_us_land.HMI differ diff --git a/hmi/nspanel_CJK_us_land.tft b/hmi/nspanel_CJK_us_land.tft index 3350243e6..d9050d4f1 100644 Binary files a/hmi/nspanel_CJK_us_land.tft and b/hmi/nspanel_CJK_us_land.tft differ diff --git a/hmi/nspanel_blank.HMI b/hmi/nspanel_blank.HMI index f393d4af3..17bcb1733 100644 Binary files a/hmi/nspanel_blank.HMI and b/hmi/nspanel_blank.HMI differ diff --git a/hmi/nspanel_blank.tft b/hmi/nspanel_blank.tft index 9063d4643..96dacd8d5 100644 Binary files a/hmi/nspanel_blank.tft and b/hmi/nspanel_blank.tft differ diff --git a/hmi/nspanel_eu.HMI b/hmi/nspanel_eu.HMI index 43c37cdd3..9a782b229 100644 Binary files a/hmi/nspanel_eu.HMI and b/hmi/nspanel_eu.HMI differ diff --git a/hmi/nspanel_eu.tft b/hmi/nspanel_eu.tft index 403345a8b..ed7dffff8 100644 Binary files a/hmi/nspanel_eu.tft and b/hmi/nspanel_eu.tft differ diff --git a/hmi/nspanel_us.HMI b/hmi/nspanel_us.HMI index 195223cd0..dfb7808de 100644 Binary files a/hmi/nspanel_us.HMI and b/hmi/nspanel_us.HMI differ diff --git a/hmi/nspanel_us.tft b/hmi/nspanel_us.tft index f5d1526b8..e55d4b698 100644 Binary files a/hmi/nspanel_us.tft and b/hmi/nspanel_us.tft differ diff --git a/hmi/nspanel_us_land.HMI b/hmi/nspanel_us_land.HMI index 338e543a6..7f569ddad 100644 Binary files a/hmi/nspanel_us_land.HMI and b/hmi/nspanel_us_land.HMI differ diff --git a/hmi/nspanel_us_land.tft b/hmi/nspanel_us_land.tft index d88456ad0..68c03a0b8 100644 Binary files a/hmi/nspanel_us_land.tft and b/hmi/nspanel_us_land.tft differ