1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-04 04:12:23 +01:00

dump config when logging cdc port is open

This commit is contained in:
Tomasz Duda
2024-02-03 09:26:25 +01:00
parent d88ece9822
commit 8ef2a0ccd3
2 changed files with 22 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
#include "esphome/core/hal.h"
#include "esphome/core/log.h"
#include "esphome/core/application.h"
namespace esphome {
namespace logger {
@@ -162,6 +163,24 @@ Logger::Logger(uint32_t baud_rate, size_t tx_buffer_size) : baud_rate_(baud_rate
#endif
}
#ifdef USE_USB_CDC
void Logger::loop() {
#ifdef USE_ARDUINO
if (this->uart_ != UART_SELECTION_USB_CDC) {
return;
}
static bool opened = false;
if (opened == Serial){
return;
}
if(false == opened){
App.schedule_dump_config();
}
opened = !opened;
#endif
}
#endif
void Logger::set_baud_rate(uint32_t baud_rate) { this->baud_rate_ = baud_rate; }
void Logger::set_log_level(const std::string &tag, int log_level) {
this->log_levels_.push_back(LogLevelOverride{tag, log_level});

View File

@@ -58,7 +58,9 @@ enum UARTSelection {
class Logger : public Component {
public:
explicit Logger(uint32_t baud_rate, size_t tx_buffer_size);
#ifdef USE_USB_CDC
void loop() override;
#endif
/// Manually set the baud rate for serial, set to 0 to disable.
void set_baud_rate(uint32_t baud_rate);
uint32_t get_baud_rate() const { return baud_rate_; }