Selectable baud rate
This commit is contained in:
@@ -25,62 +25,65 @@ esphome:
|
|||||||
build_flags:
|
build_flags:
|
||||||
- -Wno-missing-field-initializers
|
- -Wno-missing-field-initializers
|
||||||
on_boot:
|
on_boot:
|
||||||
priority: 200.0
|
- priority: 600.0 # This is where most sensors are set up.
|
||||||
then:
|
then:
|
||||||
- logger.log: After boot check-up
|
- lambda: |-
|
||||||
- wait_until:
|
static const char *const TAG = "on_boot";
|
||||||
condition:
|
ESP_LOGD(TAG, "After boot check-up starting");
|
||||||
- api.connected:
|
set_baud_rate->execute(stoi(baud_rate->state), true);
|
||||||
timeout: 60s
|
- wait_until:
|
||||||
- wait_until:
|
condition:
|
||||||
condition:
|
- api.connected:
|
||||||
- lambda: !lambda return disp1->is_detected();
|
timeout: 60s
|
||||||
timeout: 10s
|
- wait_until:
|
||||||
- lambda: |-
|
condition:
|
||||||
if (!disp1->is_setup()) {
|
- lambda: !lambda return disp1->is_detected();
|
||||||
exit_reparse->execute();
|
timeout: 10s
|
||||||
}
|
- lambda: |-
|
||||||
- wait_until:
|
if (!disp1->is_setup()) {
|
||||||
condition:
|
exit_reparse->execute();
|
||||||
- lambda: !lambda return disp1->is_setup();
|
|
||||||
timeout: 10s
|
|
||||||
- lambda: |-
|
|
||||||
static const char *const TAG = "on_boot";
|
|
||||||
|
|
||||||
auto delay_seconds_ = [](int seconds) {
|
|
||||||
ESP_LOGD(TAG, "Wait %i seconds", seconds);
|
|
||||||
for (int i = 0; i < (seconds*4); i++) {
|
|
||||||
#ifdef ARDUINO
|
|
||||||
delay(250);
|
|
||||||
#elif defined(USE_ESP_IDF)
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(250));
|
|
||||||
#endif
|
|
||||||
App.feed_wdt();
|
|
||||||
}
|
}
|
||||||
};
|
- wait_until:
|
||||||
|
condition:
|
||||||
|
- lambda: !lambda return disp1->is_setup();
|
||||||
|
timeout: 10s
|
||||||
|
- lambda: |-
|
||||||
|
static const char *const TAG = "on_boot";
|
||||||
|
|
||||||
|
auto delay_seconds_ = [](int seconds) {
|
||||||
|
ESP_LOGD(TAG, "Wait %i seconds", seconds);
|
||||||
|
for (int i = 0; i < (seconds*4); i++) {
|
||||||
|
#ifdef ARDUINO
|
||||||
|
delay(250);
|
||||||
|
#elif defined(USE_ESP_IDF)
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(250));
|
||||||
|
#endif
|
||||||
|
App.feed_wdt();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
nextion_status->execute();
|
|
||||||
if (not disp1->is_setup()) {
|
|
||||||
ESP_LOGE(TAG, "No response from Nextion display");
|
|
||||||
ESP_LOGD(TAG, "Turn off Nextion");
|
|
||||||
screen_power->turn_off();
|
|
||||||
delay_seconds_(2);
|
|
||||||
ESP_LOGD(TAG, "Turn on Nextion");
|
|
||||||
screen_power->turn_on();
|
|
||||||
delay_seconds_(5);
|
|
||||||
nextion_status->execute();
|
nextion_status->execute();
|
||||||
}
|
if (not disp1->is_setup()) {
|
||||||
- wait_until:
|
ESP_LOGE(TAG, "No response from Nextion display");
|
||||||
condition:
|
ESP_LOGD(TAG, "Turn off Nextion");
|
||||||
- lambda: !lambda return disp1->is_setup();
|
screen_power->turn_off();
|
||||||
timeout: 20s
|
delay_seconds_(2);
|
||||||
- lambda: |-
|
ESP_LOGD(TAG, "Turn on Nextion");
|
||||||
static const char *const TAG = "on_boot";
|
screen_power->turn_on();
|
||||||
nextion_status->execute();
|
delay_seconds_(5);
|
||||||
if (not disp1->is_setup()) {
|
nextion_status->execute();
|
||||||
ESP_LOGE(TAG, "No response from Nextion display");
|
}
|
||||||
}
|
- wait_until:
|
||||||
ESP_LOGD(TAG, "Finished");
|
condition:
|
||||||
|
- lambda: !lambda return disp1->is_setup();
|
||||||
|
timeout: 20s
|
||||||
|
- lambda: |-
|
||||||
|
static const char *const TAG = "on_boot";
|
||||||
|
nextion_status->execute();
|
||||||
|
if (not disp1->is_setup()) {
|
||||||
|
ESP_LOGE(TAG, "No response from Nextion display");
|
||||||
|
}
|
||||||
|
ESP_LOGD(TAG, "Finished");
|
||||||
on_shutdown:
|
on_shutdown:
|
||||||
then:
|
then:
|
||||||
- switch.turn_off: screen_power
|
- switch.turn_off: screen_power
|
||||||
@@ -1192,6 +1195,33 @@ number:
|
|||||||
|
|
||||||
##### START - SELECT CONFIGURATION #####
|
##### START - SELECT CONFIGURATION #####
|
||||||
select:
|
select:
|
||||||
|
- id: baud_rate
|
||||||
|
name: ${device_name} Baud rate
|
||||||
|
platform: template
|
||||||
|
options:
|
||||||
|
- "2400"
|
||||||
|
- "4800"
|
||||||
|
- "9600"
|
||||||
|
- "19200"
|
||||||
|
- "31250"
|
||||||
|
- "38400"
|
||||||
|
- "57600"
|
||||||
|
- "115200"
|
||||||
|
- "230400"
|
||||||
|
- "250000"
|
||||||
|
- "256000"
|
||||||
|
- "512000"
|
||||||
|
- "921600"
|
||||||
|
initial_option: "115200"
|
||||||
|
optimistic: true
|
||||||
|
restore_value: true
|
||||||
|
internal: false
|
||||||
|
entity_category: config
|
||||||
|
disabled_by_default: true
|
||||||
|
icon: mdi:swap-horizontal
|
||||||
|
set_action:
|
||||||
|
- lambda: set_baud_rate->execute(stoi(x), true);
|
||||||
|
|
||||||
- name: ${device_name} Wake-up page
|
- name: ${device_name} Wake-up page
|
||||||
id: wakeup_page_name
|
id: wakeup_page_name
|
||||||
platform: template
|
platform: template
|
||||||
@@ -2334,6 +2364,42 @@ script:
|
|||||||
api_server->send_homeassistant_service_call(resp);
|
api_server->send_homeassistant_service_call(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- id: set_baud_rate
|
||||||
|
mode: restart
|
||||||
|
parameters:
|
||||||
|
baud_rate: int
|
||||||
|
definitive: bool
|
||||||
|
then:
|
||||||
|
- if:
|
||||||
|
condition:
|
||||||
|
- lambda: !lambda return (tf_uart->get_baud_rate() != baud_rate);
|
||||||
|
then:
|
||||||
|
- lambda: |-
|
||||||
|
static const char *const TAG = "script.set_baud_rate";
|
||||||
|
ESP_LOGW(TAG, "Baud rate changing from %i to %i bps", tf_uart->get_baud_rate(), baud_rate);
|
||||||
|
ESP_LOGW(TAG, "Flush UART");
|
||||||
|
- wait_until:
|
||||||
|
condition:
|
||||||
|
- lambda: !lambda return (tf_uart->available() < 1);
|
||||||
|
timeout: 3s
|
||||||
|
- lambda: |-
|
||||||
|
tf_uart->flush();
|
||||||
|
static const char *const TAG = "script.set_baud_rate";
|
||||||
|
ESP_LOGW(TAG, "Sending instruction '%s=%i' to Nextion", definitive ? "bauds" : "baud", baud_rate);
|
||||||
|
disp1->send_command_printf("%s=%i", definitive ? "bauds" : "baud", baud_rate);
|
||||||
|
ESP_LOGW(TAG, "Flush UART");
|
||||||
|
- wait_until:
|
||||||
|
condition:
|
||||||
|
- lambda: !lambda return (tf_uart->available() < 1);
|
||||||
|
timeout: 3s
|
||||||
|
- lambda: |-
|
||||||
|
tf_uart->flush();
|
||||||
|
static const char *const TAG = "script.set_baud_rate";
|
||||||
|
ESP_LOGW(TAG, "Set ESPHome new baud rate to %i bps", baud_rate);
|
||||||
|
tf_uart->set_baud_rate(baud_rate);
|
||||||
|
tf_uart->load_settings();
|
||||||
|
ESP_LOGW(TAG, "Baud rate is changet to %i bps", baud_rate);
|
||||||
|
|
||||||
- id: set_brightness
|
- id: set_brightness
|
||||||
mode: restart
|
mode: restart
|
||||||
parameters:
|
parameters:
|
||||||
@@ -2638,6 +2704,7 @@ script:
|
|||||||
refresh_wifi_icon->stop();
|
refresh_wifi_icon->stop();
|
||||||
relay_settings->stop();
|
relay_settings->stop();
|
||||||
service_call_alarm_control_panel->stop();
|
service_call_alarm_control_panel->stop();
|
||||||
|
set_baud_rate->stop();
|
||||||
set_brightness->stop();
|
set_brightness->stop();
|
||||||
set_climate->stop();
|
set_climate->stop();
|
||||||
set_component_color->stop();
|
set_component_color->stop();
|
||||||
|
|||||||
Reference in New Issue
Block a user