mirror of
https://github.com/esphome/esphome.git
synced 2024-11-14 02:58:11 +01:00
Extends UART change at runtime to ESP8266 (#6019)
This commit is contained in:
parent
e3d146ee44
commit
2bb5343d27
3 changed files with 35 additions and 4 deletions
|
@ -122,7 +122,7 @@ class UARTComponent {
|
||||||
// @return Baud rate in bits per second.
|
// @return Baud rate in bits per second.
|
||||||
uint32_t get_baud_rate() const { return baud_rate_; }
|
uint32_t get_baud_rate() const { return baud_rate_; }
|
||||||
|
|
||||||
#ifdef USE_ESP32
|
#if defined(USE_ESP8266) || defined(USE_ESP32)
|
||||||
/**
|
/**
|
||||||
* Load the UART settings.
|
* Load the UART settings.
|
||||||
* @param dump_config If true (default), output the new settings to logs; otherwise, change settings quietly.
|
* @param dump_config If true (default), output the new settings to logs; otherwise, change settings quietly.
|
||||||
|
@ -147,7 +147,7 @@ class UARTComponent {
|
||||||
* This will load the current UART interface with the latest settings (baud_rate, parity, etc).
|
* This will load the current UART interface with the latest settings (baud_rate, parity, etc).
|
||||||
*/
|
*/
|
||||||
virtual void load_settings(){};
|
virtual void load_settings(){};
|
||||||
#endif // USE_ESP32
|
#endif // USE_ESP8266 || USE_ESP32
|
||||||
|
|
||||||
#ifdef USE_UART_DEBUGGER
|
#ifdef USE_UART_DEBUGGER
|
||||||
void add_debug_callback(std::function<void(UARTDirection, uint8_t)> &&callback) {
|
void add_debug_callback(std::function<void(UARTDirection, uint8_t)> &&callback) {
|
||||||
|
|
|
@ -98,10 +98,26 @@ void ESP8266UartComponent::setup() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESP8266UartComponent::load_settings(bool dump_config) {
|
||||||
|
ESP_LOGCONFIG(TAG, "Loading UART bus settings...");
|
||||||
|
if (this->hw_serial_ != nullptr) {
|
||||||
|
SerialConfig config = static_cast<SerialConfig>(get_config());
|
||||||
|
this->hw_serial_->begin(this->baud_rate_, config);
|
||||||
|
this->hw_serial_->setRxBufferSize(this->rx_buffer_size_);
|
||||||
|
} else {
|
||||||
|
this->sw_serial_->setup(this->tx_pin_, this->rx_pin_, this->baud_rate_, this->stop_bits_, this->data_bits_,
|
||||||
|
this->parity_, this->rx_buffer_size_);
|
||||||
|
}
|
||||||
|
if (dump_config) {
|
||||||
|
ESP_LOGCONFIG(TAG, "UART bus was reloaded.");
|
||||||
|
this->dump_config();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ESP8266UartComponent::dump_config() {
|
void ESP8266UartComponent::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "UART Bus:");
|
ESP_LOGCONFIG(TAG, "UART Bus:");
|
||||||
LOG_PIN(" TX Pin: ", tx_pin_);
|
LOG_PIN(" TX Pin: ", this->tx_pin_);
|
||||||
LOG_PIN(" RX Pin: ", rx_pin_);
|
LOG_PIN(" RX Pin: ", this->rx_pin_);
|
||||||
if (this->rx_pin_ != nullptr) {
|
if (this->rx_pin_ != nullptr) {
|
||||||
ESP_LOGCONFIG(TAG, " RX Buffer Size: %u", this->rx_buffer_size_); // NOLINT
|
ESP_LOGCONFIG(TAG, " RX Buffer Size: %u", this->rx_buffer_size_); // NOLINT
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,21 @@ class ESP8266UartComponent : public UARTComponent, public Component {
|
||||||
|
|
||||||
uint32_t get_config();
|
uint32_t get_config();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the UART with the current settings.
|
||||||
|
* @param dump_config (Optional, default `true`): True for displaying new settings or
|
||||||
|
* false to change it quitely
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* ```cpp
|
||||||
|
* id(uart1).load_settings();
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* This will load the current UART interface with the latest settings (baud_rate, parity, etc).
|
||||||
|
*/
|
||||||
|
void load_settings(bool dump_config) override;
|
||||||
|
void load_settings() override { this->load_settings(true); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void check_logger_conflict() override;
|
void check_logger_conflict() override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue