2024-04-26 19:02:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
2024-04-29 11:49:12 +00:00
|
|
|
#include "door_singleton.h"
|
|
|
|
|
|
|
|
#ifdef USE_COVER
|
|
|
|
|
2024-04-26 19:02:48 +00:00
|
|
|
#include "esphome.h"
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "hciemulator.h"
|
|
|
|
//#include "cover.h"
|
|
|
|
|
|
|
|
#define RS485 Serial2
|
|
|
|
#define TX_ON 25
|
|
|
|
//#define configMAX_PRIORITIES 25
|
|
|
|
|
|
|
|
#define TAG "hoermann_door"
|
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
namespace hoermann_door {
|
|
|
|
|
|
|
|
void modBusPolling(void *parameter);
|
|
|
|
class HoermanDoor : public Component, public cover::Cover
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
cover::CoverTraits get_traits() override {
|
|
|
|
auto traits = cover::CoverTraits();
|
|
|
|
traits.set_is_assumed_state(false);
|
2024-04-29 11:49:12 +00:00
|
|
|
traits.set_supports_position(false);
|
2024-04-26 19:02:48 +00:00
|
|
|
traits.set_supports_tilt(false);
|
|
|
|
traits.set_supports_stop(true);
|
|
|
|
traits.set_supports_toggle(true);
|
|
|
|
return traits;
|
|
|
|
}
|
|
|
|
|
|
|
|
//u_int8_t stopAt == 0;
|
|
|
|
bool manual = false;
|
|
|
|
void control(const cover::CoverCall &call) override {
|
|
|
|
ESP_LOGW(TAG, "In func control door");
|
|
|
|
// This will be called every time the user requests a state change.
|
|
|
|
if (call.get_position().has_value()) {
|
|
|
|
|
|
|
|
float pos = *call.get_position();
|
|
|
|
|
|
|
|
//emulator(&RS485);
|
|
|
|
// Write pos (range 0-1) to cover
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
|
|
if(pos == 1.0){
|
2024-04-29 11:49:12 +00:00
|
|
|
HoermannSingleton::getInstance()->getEmulator()->openDoor();
|
2024-04-26 19:02:48 +00:00
|
|
|
manual = false;
|
|
|
|
}
|
|
|
|
else if(pos == 0.0){
|
2024-04-29 11:49:12 +00:00
|
|
|
HoermannSingleton::getInstance()->getEmulator()->closeDoor();
|
2024-04-26 19:02:48 +00:00
|
|
|
manual = false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
ESP_LOGD("Door controller", "Not yet supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (call.get_stop()) {
|
2024-04-29 11:49:12 +00:00
|
|
|
HoermannSingleton::getInstance()->getEmulator()->stopDoor();
|
2024-04-26 19:02:48 +00:00
|
|
|
}
|
|
|
|
//if(call.get_close()) {
|
|
|
|
//emulator.closeDoor();
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
void modBusPolling(void *parameter)
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (lastCall > 0)
|
|
|
|
{
|
|
|
|
maxPeriod = _max(micros() - lastCall, maxPeriod);
|
|
|
|
}
|
|
|
|
lastCall = micros();
|
|
|
|
emulator.poll();
|
|
|
|
vTaskDelay(1);
|
|
|
|
}
|
|
|
|
vTaskDelete(NULL);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
void setup() override
|
|
|
|
{
|
2024-04-29 11:49:12 +00:00
|
|
|
HoermannSingleton::getInstance()->initializeEmulator();
|
2024-04-26 19:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void open(){
|
|
|
|
//emulator.openDoor();
|
|
|
|
}
|
|
|
|
void close(){
|
|
|
|
//emulator.closeDoor();
|
|
|
|
}
|
|
|
|
void stop(){
|
|
|
|
//emulator.stopDoor();
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
unsigned long lastStatus = 0;
|
|
|
|
u_int8_t pos = 255;
|
|
|
|
void loop() override
|
|
|
|
{
|
2024-04-29 11:49:12 +00:00
|
|
|
u_int8_t position = HoermannSingleton::getInstance()->getEmulator()->getState().doorCurrentPosition;
|
2024-04-26 19:02:48 +00:00
|
|
|
if(pos != position){
|
|
|
|
this->position = (float) position / 200.0;
|
|
|
|
this->publish_state();
|
|
|
|
pos = position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace hoermann
|
2024-04-29 11:49:12 +00:00
|
|
|
} // namespace esphome
|
|
|
|
|
|
|
|
#endif
|