Selectable baud rate
This commit is contained in:
@@ -25,9 +25,12 @@ 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: |-
|
||||||
|
static const char *const TAG = "on_boot";
|
||||||
|
ESP_LOGD(TAG, "After boot check-up starting");
|
||||||
|
set_baud_rate->execute(stoi(baud_rate->state), true);
|
||||||
- wait_until:
|
- wait_until:
|
||||||
condition:
|
condition:
|
||||||
- api.connected:
|
- api.connected:
|
||||||
@@ -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