HoermannDoor: Now uses GPIOInternalPin and UARTComponent to communicate.
This commit is contained in:
92
external_components/hoermann_door/hoermann.h
Normal file
92
external_components/hoermann_door/hoermann.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#pragma once
|
||||
|
||||
class HoermannMainComponent;
|
||||
#include "hciemulator.h"
|
||||
#include "esphome/components/uart/uart.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace hoermann_door {
|
||||
|
||||
static const char *const TAG = "Hoermann";
|
||||
|
||||
void dispatcherFn(void *arg);
|
||||
|
||||
class HoermannMainComponent: public Component{
|
||||
protected:
|
||||
HCIEmulator* emulator;
|
||||
TaskHandle_t modBusTask;
|
||||
|
||||
uart::UARTComponent* _uart;
|
||||
InternalGPIOPin* _tx_on;
|
||||
|
||||
volatile bool set_continue_ = true;
|
||||
volatile unsigned long lastCall = 0;
|
||||
volatile unsigned long maxPeriod = 0;
|
||||
|
||||
public:
|
||||
|
||||
void set_seriel_connection(uart::UARTComponent* uart){
|
||||
this->_uart = uart;
|
||||
}
|
||||
void set_tx_on_pin(InternalGPIOPin* pin){
|
||||
this->_tx_on = pin;
|
||||
}
|
||||
HCIEmulator* getEmulator(){
|
||||
return emulator;
|
||||
}
|
||||
|
||||
void setup() override {
|
||||
|
||||
this->_tx_on->setup();
|
||||
this->emulator = new HCIEmulator(this->_tx_on, this->_uart);
|
||||
|
||||
this->_tx_on->digital_write(LOW);
|
||||
this->set_continue_ = false;
|
||||
xTaskCreatePinnedToCore(
|
||||
dispatcherFn, // Function to implement the task
|
||||
"ModBusTask", // Name of the task
|
||||
10000, // Stack size in words
|
||||
NULL, // Task input parameter
|
||||
// 1, // Priority of the task
|
||||
configMAX_PRIORITIES - 1,
|
||||
&modBusTask, // Task handle.
|
||||
1 // Core where the task should run
|
||||
);
|
||||
}
|
||||
|
||||
void stop_polling(){
|
||||
this->_tx_on->digital_write(HIGH);
|
||||
this->set_continue_ = false;
|
||||
}
|
||||
|
||||
void modBusPolling(void *parameter)
|
||||
{
|
||||
while (set_continue_)
|
||||
{
|
||||
if (lastCall > 0)
|
||||
{
|
||||
maxPeriod = _max(micros() - lastCall, maxPeriod);
|
||||
}
|
||||
lastCall = micros();
|
||||
emulator->poll();
|
||||
vTaskDelay(1);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void dump_config() override {
|
||||
ESP_LOGCONFIG(TAG, "hoermann_door_component:");
|
||||
ESP_LOGCONFIG(TAG, " UART: %d", this->_uart->get_baud_rate());
|
||||
//LOG_PIN(TAG, this->_tx_on);
|
||||
}
|
||||
};
|
||||
|
||||
void dispatcherFn(void *arg)
|
||||
{
|
||||
HoermannMainComponent *x = (HoermannMainComponent *)arg;
|
||||
x->modBusPolling(arg);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user