mirror of
https://github.com/esphome/esphome.git
synced 2025-09-05 21:02:20 +01:00
move msg write per platform file
This commit is contained in:
@@ -105,28 +105,9 @@ void HOT Logger::log_message_(int level, const char *tag, int offset) {
|
|||||||
this->set_null_terminator_();
|
this->set_null_terminator_();
|
||||||
|
|
||||||
const char *msg = this->tx_buffer_ + offset;
|
const char *msg = this->tx_buffer_ + offset;
|
||||||
|
|
||||||
if (this->baud_rate_ > 0) {
|
if (this->baud_rate_ > 0) {
|
||||||
#ifdef USE_ARDUINO
|
this->write_msg_(msg);
|
||||||
this->hw_serial_->println(msg);
|
|
||||||
#endif // USE_ARDUINO
|
|
||||||
#ifdef USE_ESP_IDF
|
|
||||||
if (
|
|
||||||
#if defined(USE_ESP32_VARIANT_ESP32S2)
|
|
||||||
this->uart_ == UART_SELECTION_USB_CDC
|
|
||||||
#elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32H2)
|
|
||||||
this->uart_ == UART_SELECTION_USB_SERIAL_JTAG
|
|
||||||
#elif defined(USE_ESP32_VARIANT_ESP32S3)
|
|
||||||
this->uart_ == UART_SELECTION_USB_CDC || this->uart_ == UART_SELECTION_USB_SERIAL_JTAG
|
|
||||||
#else
|
|
||||||
/* DISABLES CODE */ (false) // NOLINT
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
puts(msg);
|
|
||||||
} else {
|
|
||||||
uart_write_bytes(this->uart_num_, msg, strlen(msg));
|
|
||||||
uart_write_bytes(this->uart_num_, "\n", 1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_ESP32
|
#ifdef USE_ESP32
|
||||||
@@ -138,13 +119,20 @@ void HOT Logger::log_message_(int level, const char *tag, int offset) {
|
|||||||
if (xPortGetFreeHeapSize() < 2048)
|
if (xPortGetFreeHeapSize() < 2048)
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_HOST
|
|
||||||
puts(msg);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
this->log_callback_.call(level, tag, msg);
|
this->log_callback_.call(level, tag, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(USE_HOST) || defined(USE_ARDUINO)
|
||||||
|
void HOT Logger::write_msg_(const char *msg) {
|
||||||
|
#ifdef USE_HOST
|
||||||
|
puts(msg);
|
||||||
|
#elif USE_ARDUINO
|
||||||
|
this->hw_serial_->println(msg);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Logger::Logger(uint32_t baud_rate, size_t tx_buffer_size) : baud_rate_(baud_rate), tx_buffer_size_(tx_buffer_size) {
|
Logger::Logger(uint32_t baud_rate, size_t tx_buffer_size) : baud_rate_(baud_rate), tx_buffer_size_(tx_buffer_size) {
|
||||||
// add 1 to buffer size for null terminator
|
// add 1 to buffer size for null terminator
|
||||||
this->tx_buffer_ = new char[this->tx_buffer_size_ + 1]; // NOLINT
|
this->tx_buffer_ = new char[this->tx_buffer_size_ + 1]; // NOLINT
|
||||||
|
@@ -97,6 +97,7 @@ class Logger : public Component {
|
|||||||
void write_header_(int level, const char *tag, int line);
|
void write_header_(int level, const char *tag, int line);
|
||||||
void write_footer_();
|
void write_footer_();
|
||||||
void log_message_(int level, const char *tag, int offset = 0);
|
void log_message_(int level, const char *tag, int offset = 0);
|
||||||
|
void write_msg_(const char *msg);
|
||||||
|
|
||||||
inline bool is_buffer_full_() const { return this->tx_buffer_at_ >= this->tx_buffer_size_; }
|
inline bool is_buffer_full_() const { return this->tx_buffer_at_ >= this->tx_buffer_size_; }
|
||||||
inline int buffer_remaining_capacity_() const { return this->tx_buffer_size_ - this->tx_buffer_at_; }
|
inline int buffer_remaining_capacity_() const { return this->tx_buffer_size_ - this->tx_buffer_at_; }
|
||||||
|
@@ -158,6 +158,27 @@ void Logger::pre_setup() {
|
|||||||
ESP_LOGI(TAG, "Log initialized");
|
ESP_LOGI(TAG, "Log initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_ESP_IDF
|
||||||
|
void HOT Logger::write_msg_(const char *msg) {
|
||||||
|
if (
|
||||||
|
#if defined(USE_ESP32_VARIANT_ESP32S2)
|
||||||
|
this->uart_ == UART_SELECTION_USB_CDC
|
||||||
|
#elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32H2)
|
||||||
|
this->uart_ == UART_SELECTION_USB_SERIAL_JTAG
|
||||||
|
#elif defined(USE_ESP32_VARIANT_ESP32S3)
|
||||||
|
this->uart_ == UART_SELECTION_USB_CDC || this->uart_ == UART_SELECTION_USB_SERIAL_JTAG
|
||||||
|
#else
|
||||||
|
/* DISABLES CODE */ (false) // NOLINT
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
|
puts(msg);
|
||||||
|
} else {
|
||||||
|
uart_write_bytes(this->uart_num_, msg, strlen(msg));
|
||||||
|
uart_write_bytes(this->uart_num_, "\n", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const char *const UART_SELECTIONS[] = {
|
const char *const UART_SELECTIONS[] = {
|
||||||
"UART0", "UART1",
|
"UART0", "UART1",
|
||||||
#ifdef USE_ESP32_VARIANT_ESP32
|
#ifdef USE_ESP32_VARIANT_ESP32
|
||||||
|
Reference in New Issue
Block a user