Added hoermann_door.stop_polling and .start_polling as automations should that need arise somehow!

This commit is contained in:
2025-10-07 13:15:04 +02:00
parent 3b88f1e988
commit 273cd9e434
3 changed files with 73 additions and 21 deletions

View File

@@ -52,18 +52,36 @@ class HoermannMainComponent: public Component{
this->emulator = new HCIEmulator(this->_tx_on, this->_uart);
this->emulator->setLogLevel(this->log_level);
this->start_polling();
}
void stop_polling(){
this->set_continue_ = false;
if(modBusTask != NULL){
// Wait for the task to be deleted
while(eTaskGetState(modBusTask) != eDeleted){
vTaskDelay(1);
}
modBusTask = NULL;
}
this->_tx_on->digital_write(false);
this->set_continue_ = true;
xTaskCreatePinnedToCore(
dispatcherFn, // Function to implement the task
"ModBusTask", // Name of the task
10000, // Stack size in words
this, // Task input parameter
// 1, // Priority of the task
configMAX_PRIORITIES - 1,
&modBusTask, // Task handle.
1 // Core where the task should run
);
}
void start_polling() {
if(modBusTask == NULL){
this->_tx_on->digital_write(false);
this->set_continue_ = true;
xTaskCreatePinnedToCore(
dispatcherFn, // Function to implement the task
"ModBusTask", // Name of the task
10000, // Stack size in words
this, // Task input parameter
// 1, // Priority of the task
configMAX_PRIORITIES - 1,
&modBusTask, // Task handle.
1 // Core where the task should run
);
}
}
void modBusPolling(void *parameter)
@@ -83,8 +101,10 @@ class HoermannMainComponent: public Component{
void dump_config() override {
ESP_LOGCONFIG(COMP_TAG, "hoermann_door_component:");
ESP_LOGCONFIG(COMP_TAG, " UART: %d", this->_uart->get_baud_rate());
//LOG_PIN(TAG, this->_tx_on);
ESP_LOGCONFIG(COMP_TAG, " UART: ");
ESP_LOGCONFIG(COMP_TAG, " UART is configured");
LOG_PIN(" TX_ON_PIN", this->_tx_on);
ESP_LOGCONFIG(COMP_TAG, " Log Level: %d", this->log_level);
}
};
@@ -94,6 +114,25 @@ void dispatcherFn(void *arg)
x->modBusPolling(arg);
}
template<typename... Ts> class StopPollingAction: public Action<Ts...> {
public:
StopPollingAction(HoermannMainComponent *motor) : motor_(motor) {}
void play(Ts... x) override { this->motor_->stop_polling(); }
protected:
HoermannMainComponent *motor_;
};
template<typename... Ts> class StartPollingAction: public Action<Ts...> {
public:
StartPollingAction(HoermannMainComponent *motor) : motor_(motor) {}
void play(Ts... x) override { this->motor_->start_polling(); }
protected:
HoermannMainComponent *motor_;
};
}
}