Made the HCIEmulator Log Level settable inside the .yaml file
This commit is contained in:
@@ -14,6 +14,21 @@ HoermannDoor = hoermann_door_ns.class_('HoermannMainComponent', cg.Component)
|
||||
|
||||
CONF_UART_ENTRY = "uart_connection"
|
||||
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):
|
||||
return config
|
||||
@@ -23,6 +38,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.GenerateID(): cv.declare_id(HoermannDoor),
|
||||
cv.Required(CONF_UART_ENTRY): cv.use_id(uart.UARTComponent),
|
||||
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
|
||||
)
|
||||
@@ -39,4 +55,7 @@ async def to_code(config):
|
||||
cg.add(var.set_seriel_connection(code))
|
||||
|
||||
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))
|
@@ -123,7 +123,6 @@ HCIEmulator::HCIEmulator(esphome::InternalGPIOPin* pin, esphome::uart::UARTCompo
|
||||
m_port = uart;
|
||||
m_pin = pin;
|
||||
m_statusCallback = NULL;
|
||||
setLogLevel(DEFAULTLOGLEVEL);
|
||||
};
|
||||
|
||||
#define TX_ON 25
|
||||
|
@@ -9,8 +9,6 @@
|
||||
#define LL_INFO 3
|
||||
#define LL_DEBUG 4
|
||||
|
||||
#define DEFAULTLOGLEVEL LL_INFO
|
||||
|
||||
#define DEVICEID 0x02
|
||||
#define BROADCASTID 0x00
|
||||
#define SIMULATEKEYPRESSDELAYMS 100
|
||||
|
@@ -20,6 +20,7 @@ class HoermannMainComponent: public Component{
|
||||
protected:
|
||||
HCIEmulator* emulator;
|
||||
TaskHandle_t modBusTask;
|
||||
int log_level = 3; // Defaults to INFO
|
||||
|
||||
uart::UARTComponent* _uart;
|
||||
InternalGPIOPin* _tx_on;
|
||||
@@ -36,6 +37,11 @@ class HoermannMainComponent: public Component{
|
||||
void set_tx_on_pin(InternalGPIOPin* pin){
|
||||
this->_tx_on = pin;
|
||||
}
|
||||
|
||||
void set_log_level(int level){
|
||||
this->log_level = level;
|
||||
}
|
||||
|
||||
HCIEmulator* getEmulator(){
|
||||
return emulator;
|
||||
}
|
||||
@@ -44,6 +50,7 @@ class HoermannMainComponent: public Component{
|
||||
|
||||
this->_tx_on->setup();
|
||||
this->emulator = new HCIEmulator(this->_tx_on, this->_uart);
|
||||
this->emulator->setLogLevel(this->log_level);
|
||||
|
||||
this->_tx_on->digital_write(false);
|
||||
this->set_continue_ = true;
|
||||
|
Reference in New Issue
Block a user