espHome-NBS-files/external_components/hoermann_door/cover_component.h

127 lines
2.5 KiB
C
Raw Normal View History

#pragma once
#include "door_singleton.h"
#ifdef USE_COVER
#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);
traits.set_supports_position(false);
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){
HoermannSingleton::getInstance()->getEmulator()->openDoor();
manual = false;
}
else if(pos == 0.0){
HoermannSingleton::getInstance()->getEmulator()->closeDoor();
manual = false;
}
else{
ESP_LOGD("Door controller", "Not yet supported");
}
}
if (call.get_stop()) {
HoermannSingleton::getInstance()->getEmulator()->stopDoor();
}
//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
{
HoermannSingleton::getInstance()->initializeEmulator();
}
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
{
u_int8_t position = HoermannSingleton::getInstance()->getEmulator()->getState().doorCurrentPosition;
if(pos != position){
this->position = (float) position / 200.0;
this->publish_state();
pos = position;
}
}
};
} // namespace hoermann
} // namespace esphome
#endif