mirror of
https://github.com/esphome/esphome.git
synced 2024-12-19 16:07:47 +01:00
Fix logger uart conflict check (#858)
* Fix logger uart conflict check * Fix class for check func * Fix syntax Hope lint is OK with moving the end of the conditional outside the #IFDEF * Move end of conditional inside ifdef and remove extra whitespace * Simplify clang-format did not like the ifdefs and was reformatting in a way that killed clang-tidy. Simple solution is to use logger's hw_serial as source of truth Also simplifies the code - uart doesn't need to know what the logger uart settings mean
This commit is contained in:
parent
694395ac91
commit
aca306d120
@ -32,6 +32,7 @@ class Logger : public Component {
|
|||||||
/// Manually set the baud rate for serial, set to 0 to disable.
|
/// Manually set the baud rate for serial, set to 0 to disable.
|
||||||
void set_baud_rate(uint32_t baud_rate);
|
void set_baud_rate(uint32_t baud_rate);
|
||||||
uint32_t get_baud_rate() const { return baud_rate_; }
|
uint32_t get_baud_rate() const { return baud_rate_; }
|
||||||
|
HardwareSerial *get_hw_serial() const { return hw_serial_; }
|
||||||
|
|
||||||
/// Get the UART used by the logger.
|
/// Get the UART used by the logger.
|
||||||
UARTSelection get_uart() const;
|
UARTSelection get_uart() const;
|
||||||
|
@ -46,12 +46,7 @@ void UARTComponent::dump_config() {
|
|||||||
}
|
}
|
||||||
ESP_LOGCONFIG(TAG, " Baud Rate: %u baud", this->baud_rate_);
|
ESP_LOGCONFIG(TAG, " Baud Rate: %u baud", this->baud_rate_);
|
||||||
ESP_LOGCONFIG(TAG, " Stop bits: %u", this->stop_bits_);
|
ESP_LOGCONFIG(TAG, " Stop bits: %u", this->stop_bits_);
|
||||||
#ifdef USE_LOGGER
|
this->check_logger_conflict_();
|
||||||
if (this->hw_serial_ == &Serial && logger::global_logger->get_baud_rate() != 0) {
|
|
||||||
ESP_LOGW(TAG, " You're using the same serial port for logging and the UART component. Please "
|
|
||||||
"disable logging over the serial port by setting logger->baud_rate to 0.");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UARTComponent::write_byte(uint8_t data) {
|
void UARTComponent::write_byte(uint8_t data) {
|
||||||
@ -156,13 +151,7 @@ void UARTComponent::dump_config() {
|
|||||||
} else {
|
} else {
|
||||||
ESP_LOGCONFIG(TAG, " Using software serial");
|
ESP_LOGCONFIG(TAG, " Using software serial");
|
||||||
}
|
}
|
||||||
|
this->check_logger_conflict_();
|
||||||
#ifdef USE_LOGGER
|
|
||||||
if (this->hw_serial_ == &Serial && logger::global_logger->get_baud_rate() != 0) {
|
|
||||||
ESP_LOGW(TAG, " You're using the same serial port for logging and the UART component. Please "
|
|
||||||
"disable logging over the serial port by setting logger->baud_rate to 0.");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UARTComponent::write_byte(uint8_t data) {
|
void UARTComponent::write_byte(uint8_t data) {
|
||||||
@ -378,6 +367,19 @@ int UARTComponent::peek() {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UARTComponent::check_logger_conflict_() {
|
||||||
|
#ifdef USE_LOGGER
|
||||||
|
if (this->hw_serial_ == nullptr || logger::global_logger->get_baud_rate() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->hw_serial_ == logger::global_logger->get_hw_serial()) {
|
||||||
|
ESP_LOGW(TAG, " You're using the same serial port for logging and the UART component. Please "
|
||||||
|
"disable logging over the serial port by setting logger->baud_rate to 0.");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void UARTDevice::check_uart_settings(uint32_t baud_rate, uint8_t stop_bits) {
|
void UARTDevice::check_uart_settings(uint32_t baud_rate, uint8_t stop_bits) {
|
||||||
if (this->parent_->baud_rate_ != baud_rate) {
|
if (this->parent_->baud_rate_ != baud_rate) {
|
||||||
ESP_LOGE(TAG, " Invalid baud_rate: Integration requested baud_rate %u but you have %u!", baud_rate,
|
ESP_LOGE(TAG, " Invalid baud_rate: Integration requested baud_rate %u but you have %u!", baud_rate,
|
||||||
|
@ -76,6 +76,7 @@ class UARTComponent : public Component, public Stream {
|
|||||||
void set_stop_bits(uint8_t stop_bits) { this->stop_bits_ = stop_bits; }
|
void set_stop_bits(uint8_t stop_bits) { this->stop_bits_ = stop_bits; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void check_logger_conflict_();
|
||||||
bool check_read_timeout_(size_t len = 1);
|
bool check_read_timeout_(size_t len = 1);
|
||||||
friend class UARTDevice;
|
friend class UARTDevice;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user