Made the HCIEmulator Log Level settable inside the .yaml file

This commit is contained in:
2025-10-07 02:01:56 +02:00
parent 9d3930af59
commit 3b88f1e988
5 changed files with 29 additions and 5 deletions

View File

@@ -14,6 +14,21 @@ HoermannDoor = hoermann_door_ns.class_('HoermannMainComponent', cg.Component)
CONF_UART_ENTRY = "uart_connection" CONF_UART_ENTRY = "uart_connection"
CONF_TX_PIN = "tx_pin" CONF_TX_PIN = "tx_pin"
CONF_LOG_LEVEL = "log_level"
#define LL_OFF 0
#define LL_ERROR 1
#define LL_WARN 2
#define LL_INFO 3
#define LL_DEBUG 4
CONF_LOG_LEVELS = {
"NONE": 0,
"ERROR": 1,
"WARN": 2,
"INFO": 3,
"DEBUG": 4,
}
def validate_config(config): def validate_config(config):
return config return config
@@ -23,6 +38,7 @@ CONFIG_SCHEMA = cv.All(
cv.GenerateID(): cv.declare_id(HoermannDoor), cv.GenerateID(): cv.declare_id(HoermannDoor),
cv.Required(CONF_UART_ENTRY): cv.use_id(uart.UARTComponent), cv.Required(CONF_UART_ENTRY): cv.use_id(uart.UARTComponent),
cv.Required(CONF_TX_PIN): pins.internal_gpio_output_pin_schema, cv.Required(CONF_TX_PIN): pins.internal_gpio_output_pin_schema,
cv.Optional(CONF_LOG_LEVEL, default="INFO"): cv.enum(CONF_LOG_LEVELS, upper=True),
}), }),
validate_config validate_config
) )
@@ -39,4 +55,7 @@ async def to_code(config):
cg.add(var.set_seriel_connection(code)) cg.add(var.set_seriel_connection(code))
code2 = await cg.gpio_pin_expression(config[CONF_TX_PIN]) code2 = await cg.gpio_pin_expression(config[CONF_TX_PIN])
cg.add(var.set_tx_on_pin(code2)) # Needs be configured before sensor cg.add(var.set_tx_on_pin(code2)) # Needs be configured before sensor
log_level = config[CONF_LOG_LEVEL]
cg.add(var.set_log_level(log_level))

View File

@@ -123,7 +123,6 @@ HCIEmulator::HCIEmulator(esphome::InternalGPIOPin* pin, esphome::uart::UARTCompo
m_port = uart; m_port = uart;
m_pin = pin; m_pin = pin;
m_statusCallback = NULL; m_statusCallback = NULL;
setLogLevel(DEFAULTLOGLEVEL);
}; };
#define TX_ON 25 #define TX_ON 25

View File

@@ -9,8 +9,6 @@
#define LL_INFO 3 #define LL_INFO 3
#define LL_DEBUG 4 #define LL_DEBUG 4
#define DEFAULTLOGLEVEL LL_INFO
#define DEVICEID 0x02 #define DEVICEID 0x02
#define BROADCASTID 0x00 #define BROADCASTID 0x00
#define SIMULATEKEYPRESSDELAYMS 100 #define SIMULATEKEYPRESSDELAYMS 100

View File

@@ -20,6 +20,7 @@ class HoermannMainComponent: public Component{
protected: protected:
HCIEmulator* emulator; HCIEmulator* emulator;
TaskHandle_t modBusTask; TaskHandle_t modBusTask;
int log_level = 3; // Defaults to INFO
uart::UARTComponent* _uart; uart::UARTComponent* _uart;
InternalGPIOPin* _tx_on; InternalGPIOPin* _tx_on;
@@ -36,6 +37,11 @@ class HoermannMainComponent: public Component{
void set_tx_on_pin(InternalGPIOPin* pin){ void set_tx_on_pin(InternalGPIOPin* pin){
this->_tx_on = pin; this->_tx_on = pin;
} }
void set_log_level(int level){
this->log_level = level;
}
HCIEmulator* getEmulator(){ HCIEmulator* getEmulator(){
return emulator; return emulator;
} }
@@ -44,6 +50,7 @@ class HoermannMainComponent: public Component{
this->_tx_on->setup(); this->_tx_on->setup();
this->emulator = new HCIEmulator(this->_tx_on, this->_uart); this->emulator = new HCIEmulator(this->_tx_on, this->_uart);
this->emulator->setLogLevel(this->log_level);
this->_tx_on->digital_write(false); this->_tx_on->digital_write(false);
this->set_continue_ = true; this->set_continue_ = true;

View File

@@ -50,9 +50,10 @@ uart:
hoermann_door: hoermann_door:
id: door_controll_internal id: door_controll_internal
uart_connection: hm_connection uart_connection: hm_connection
log_level: INFO
tx_pin: tx_pin:
number: 25 number: 25
inverted: false inverted: false # Just for clarity, false is standard
light: light: