From 1050d083b4fdd1fdabe853e546d47f37f37afc3a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 11 Feb 2026 08:34:17 -0600 Subject: [PATCH] cleanup ifdefs and typos --- esphome/components/logger/logger.cpp | 2 +- esphome/components/logger/logger.h | 2 ++ .../components/logger/task_log_buffer_zephyr.cpp | 14 ++++++++------ esphome/components/logger/task_log_buffer_zephyr.h | 6 +++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/esphome/components/logger/logger.cpp b/esphome/components/logger/logger.cpp index 5dedf33625..e1b49bcb61 100644 --- a/esphome/components/logger/logger.cpp +++ b/esphome/components/logger/logger.cpp @@ -125,7 +125,7 @@ void HOT Logger::log_vprintf_(uint8_t level, const char *tag, int line, const ch // Other single-task platforms don't have thread names, so pass nullptr this->log_message_to_buffer_and_send_(global_recursion_guard_, level, tag, line, format, args, nullptr); } -#endif // USE_ESPHOME_TASK_LOG_BUFFER +#endif // USE_ESP32 || USE_HOST || USE_LIBRETINY || USE_ZEPHYR #ifdef USE_STORE_LOG_STR_IN_FLASH // Implementation for ESP8266 with flash string support. diff --git a/esphome/components/logger/logger.h b/esphome/components/logger/logger.h index 018f7655cf..835542dd8f 100644 --- a/esphome/components/logger/logger.h +++ b/esphome/components/logger/logger.h @@ -228,7 +228,9 @@ class Logger : public Component { void log_vprintf_non_main_thread_(uint8_t level, const char *tag, int line, const char *format, va_list args, const char *thread_name); #endif +#if defined(USE_ZEPHYR) && defined(USE_LOGGER_USB_CDC) void cdc_loop_(); +#endif void process_messages_(); void write_msg_(const char *msg, uint16_t len); diff --git a/esphome/components/logger/task_log_buffer_zephyr.cpp b/esphome/components/logger/task_log_buffer_zephyr.cpp index 3fc0eabf81..71c75231b7 100644 --- a/esphome/components/logger/task_log_buffer_zephyr.cpp +++ b/esphome/components/logger/task_log_buffer_zephyr.cpp @@ -47,7 +47,7 @@ bool TaskLogBuffer::send_message_thread_safe(uint8_t level, const char *tag, uin size_t text_length = (static_cast(ret) > MAX_TEXT_SIZE) ? MAX_TEXT_SIZE : ret; size_t total_size = total_size_in_32bit_words(text_length); auto *msg = reinterpret_cast(mpsc_pbuf_alloc(&this->log_buffer_, total_size, K_NO_WAIT)); - if (nullptr == msg) { + if (msg == nullptr) { return false; } msg->level = level; @@ -63,7 +63,7 @@ bool TaskLogBuffer::send_message_thread_safe(uint8_t level, const char *tag, uin // Handle unexpected formatting error if (ret <= 0) { - // this shall not happened vsnprintf was called already once + // this should not happen, vsnprintf was called already once // fill with '\n' to not call mpsc_pbuf_free from producer // it will be trimmed anyway for (size_t i = 0; i < text_length; ++i) { @@ -86,11 +86,11 @@ bool TaskLogBuffer::borrow_message_main_loop(LogMessage *&message, uint16_t &tex this->current_token_ = mpsc_pbuf_claim(&this->log_buffer_); - if (nullptr == this->current_token_) { + if (this->current_token_ == nullptr) { return false; } - // we claimed buffer alraedy const_cast is safe here + // we claimed buffer already, const_cast is safe here message = const_cast(reinterpret_cast(this->current_token_)); text_length = message->text_length; @@ -109,6 +109,8 @@ void TaskLogBuffer::release_message_main_loop() { mpsc_pbuf_free(&this->log_buffer_, this->current_token_); this->current_token_ = nullptr; } -#endif +#endif // USE_ESPHOME_TASK_LOG_BUFFER + } // namespace esphome::logger -#endif + +#endif // USE_ZEPHYR diff --git a/esphome/components/logger/task_log_buffer_zephyr.h b/esphome/components/logger/task_log_buffer_zephyr.h index 0e82aaf5b7..cc2ed1f687 100644 --- a/esphome/components/logger/task_log_buffer_zephyr.h +++ b/esphome/components/logger/task_log_buffer_zephyr.h @@ -19,7 +19,7 @@ class TaskLogBuffer { public: // Structure for a log message header (text data follows immediately after) struct LogMessage { - MPSC_PBUF_HDR; // this is only 2 bits put not more that 30 bits directly after + MPSC_PBUF_HDR; // this is only 2 bits but no more than 30 bits directly after uint16_t line; // Source code line number uint8_t level; // Log level (0-7) #if defined(CONFIG_THREAD_NAME) @@ -59,8 +59,8 @@ class TaskLogBuffer { const mpsc_pbuf_generic *current_token_{}; }; -#endif +#endif // USE_ESPHOME_TASK_LOG_BUFFER } // namespace esphome::logger -#endif +#endif // USE_ZEPHYR