HoermannDoor: Now uses GPIOInternalPin and UARTComponent to communicate.

This commit is contained in:
2025-09-26 21:03:45 +02:00
parent 8198d8f62e
commit d3f0520123
10 changed files with 250 additions and 153 deletions

View File

@@ -2,10 +2,11 @@
#ifdef USE_LIGHT
class NbsLightManager;
#include "esphome.h"
#include "Arduino.h"
#include "hciemulator.h"
#include "door_singleton.h"
#include "hoermann.h"
//#include "cover.h"
#define RS485 Serial2
@@ -20,13 +21,14 @@ namespace hoermann_door {
// Custom binary output, for exposing binary states
class NbsLightManager: public binary::BinaryLightOutput, public light::LightState {
protected:
HoermannSingleton *single;
public:
void setup() override {
//single = HoermannSingleton::getInstance();
//single->initializeGetInstance
}
bool lastState = false;
bool firstState = false;
void loop() override {
@@ -45,15 +47,15 @@ class NbsLightManager: public binary::BinaryLightOutput, public light::LightStat
class NbsLightOutput: public output::BinaryOutput, public Component{
light::LightState *callback;
HoermannSingleton *single;
bool lastState = false;
bool firstState = true;
HoermannMainComponent *mainComponent;
public:
virtual void write_state(bool state){
if(lastState != state){
single->getEmulator()->toggleLamp();
mainComponent->getEmulator()->toggleLamp();
//lastState = state;
}
}
@@ -62,21 +64,24 @@ class NbsLightOutput: public output::BinaryOutput, public Component{
if(callback == nullptr) ESP_LOGW("Hoermann_door(Light)", "Got Nullable callback");
this->callback = callback;
}
void set_emulator_component(HoermannMainComponent* component){
this->mainComponent = component;
}
void loop() override {
if(!single->getEmulator()->getState().valid) false;
if(firstState || single->getEmulator()->getState().lampOn != lastState){
if(!mainComponent->getEmulator()->getState().valid) false;
if(firstState || mainComponent->getEmulator()->getState().lampOn != lastState){
//ESP_LOGD("Test", "I have no idea");
lastState = single->getEmulator()->getState().lampOn;
lastState = mainComponent->getEmulator()->getState().lampOn;
if(lastState == true){
ESP_LOGD("Hoermann_door(Light)", "Light State ON");
ESP_LOGD(TAG, "Hoermann_door(Light)", "Light State ON");
auto call = callback->make_call();
call.set_state(true);
call.perform();
}
else {
ESP_LOGD("Hoermann_door(Light)", "Light State OFF");
ESP_LOGD(TAG, "Hoermann_door(Light)", "Light State OFF");
auto call = callback->make_call();
call.set_state(false);
call.perform();
@@ -87,8 +92,7 @@ class NbsLightOutput: public output::BinaryOutput, public Component{
}
void setup() override {
single = HoermannSingleton::getInstance();
single->initializeEmulator();
}
void turn_on() override {