diff --git a/external_components/hoermann_door/cover_component.h b/external_components/hoermann_door/cover_component.h index 7d3a58b..729ab43 100644 --- a/external_components/hoermann_door/cover_component.h +++ b/external_components/hoermann_door/cover_component.h @@ -1,8 +1,6 @@ #pragma once -#ifdef USE_COVER - -class HoermannDoorx; +//#ifdef USE_COVER #include "esphome.h" #include "hoermann.h" @@ -55,7 +53,7 @@ public: manual = false; } else{ - ESP_LOGD("Door controller", "Not yet supported"); + ESP_LOGD(COMP_TAG, "Not yet supported"); } } @@ -106,4 +104,4 @@ public: } // namespace hoermann } // namespace esphome -#endif \ No newline at end of file +//#endif \ No newline at end of file diff --git a/external_components/hoermann_door/hciemulator.cpp b/external_components/hoermann_door/hciemulator.cpp index 39b5e2a..703edeb 100644 --- a/external_components/hoermann_door/hciemulator.cpp +++ b/external_components/hoermann_door/hciemulator.cpp @@ -1,5 +1,9 @@ #include "hciemulator.h" + +namespace esphome { +namespace hoermann_door { + #define CHECKCHANGEDSET(Target, Value, Flag) \ if ((Target) != (Value)) \ { \ @@ -8,9 +12,9 @@ } int hciloglevel = LL_DEBUG; -#define SOFTSERIAL 1 +//#define SOFTSERIAL 1 -#ifdef SOFTSERIAL +//#ifdef SOFTSERIAL #define Log(Level, Message) LogCore(Level, Message) #define Log3(Level, Message, Buffer, Len) LogCore(Level, Message, Buffer, Len) // LOGLEVEL @@ -23,7 +27,7 @@ void LogCore(int Level, const char *msg, const unsigned char *data = NULL, size_ if (data != NULL && datalen > 0) { //std::string newmsg(msg); - char* newmsg = (char*)malloc(strlen(msg) + datalen * 3 + 1); + char* newmsg = (char*)malloc(strlen(msg) + (datalen * 3) + 1); strncpy(newmsg, msg, strlen(msg) + 1); newmsg[strlen(msg)] = '\0'; char str[4]; @@ -41,10 +45,10 @@ void LogCore(int Level, const char *msg, const unsigned char *data = NULL, size_ ESP_LOGD(TAG, msg); } } -#else -#define Log(Level, Message) -#define Log3(Level, Message, Buffer, Len) -#endif +//#else +//#define Log(Level, Message) +//#define Log3(Level, Message, Buffer, Len) +//#endif int HCIEmulator::getLogLevel() { @@ -203,6 +207,7 @@ void HCIEmulator::poll() void HCIEmulator::processFrame() { m_txlen = 0; // clear send buffer + Log3(LL_DEBUG, "Incomming Data: ", m_rxbuffer, m_rxlen); if (m_rxlen < 5) { @@ -509,3 +514,6 @@ void HCIEmulator::onStatusChanged(callback_function_t handler) { m_statusCallback = handler; } + +} +} diff --git a/external_components/hoermann_door/hciemulator.h b/external_components/hoermann_door/hciemulator.h index bf313f4..5366500 100644 --- a/external_components/hoermann_door/hciemulator.h +++ b/external_components/hoermann_door/hciemulator.h @@ -1,12 +1,6 @@ #ifndef __hciemulator_h #define __hciemulator_h -#ifdef USE_ESP_IDF - //#include - //#include - //#include -#endif - #include "esphome/components/uart/uart.h" #define LL_OFF 0 @@ -32,6 +26,9 @@ #define T1_5 750 #define T3_5 4800 // +namespace esphome { +namespace hoermann_door { + static const char *const TAG = "HCIEmulator"; enum DoorState : uint8_t @@ -81,7 +78,7 @@ class HCIEmulator public: typedef std::function callback_function_t; - HCIEmulator(esphome::InternalGPIOPin* pin, esphome::uart::UARTComponent* uart); + HCIEmulator(InternalGPIOPin* pin, uart::UARTComponent* uart); void poll(); @@ -94,7 +91,7 @@ public: const SHCIState &getState() { - if (esphome::micros() - m_recvTime > 2000000) + if (micros() - m_recvTime > 2000000) { // 2 sec without statusmessage m_state.valid = false; @@ -104,7 +101,7 @@ public: unsigned long getMessageAge() { - return esphome::micros() - m_recvTime; + return micros() - m_recvTime; } int getLogLevel(); @@ -124,8 +121,8 @@ protected: private: callback_function_t m_statusCallback; - esphome::InternalGPIOPin* m_pin; - esphome::uart::UARTComponent* m_port; + InternalGPIOPin* m_pin; + uart::UARTComponent* m_port; SHCIState m_state; StateMachine m_statemachine; @@ -147,4 +144,7 @@ private: bool m_skipFrame; }; +} +} + #endif diff --git a/external_components/hoermann_door/hoermann.h b/external_components/hoermann_door/hoermann.h index 138f336..22067ef 100644 --- a/external_components/hoermann_door/hoermann.h +++ b/external_components/hoermann_door/hoermann.h @@ -2,14 +2,17 @@ #include +namespace esphome { +namespace hoermann_door { class HoermannMainComponent; +} +} #include "hciemulator.h" #include "esphome/components/uart/uart.h" namespace esphome { namespace hoermann_door { - -static const char *const TAG = "Hoermann"; +static const char *const COMP_TAG = "Hoermann"; void dispatcherFn(void *arg); @@ -72,8 +75,8 @@ class HoermannMainComponent: public Component{ } void dump_config() override { - ESP_LOGCONFIG(TAG, "hoermann_door_component:"); - ESP_LOGCONFIG(TAG, " UART: %d", this->_uart->get_baud_rate()); + ESP_LOGCONFIG(COMP_TAG, "hoermann_door_component:"); + ESP_LOGCONFIG(COMP_TAG, " UART: %d", this->_uart->get_baud_rate()); //LOG_PIN(TAG, this->_tx_on); } }; diff --git a/external_components/hoermann_door/light_component.h b/external_components/hoermann_door/light_component.h index 1a6eba5..793ec4b 100644 --- a/external_components/hoermann_door/light_component.h +++ b/external_components/hoermann_door/light_component.h @@ -13,8 +13,6 @@ class NbsLightManager; #define TX_ON 25 //#define configMAX_PRIORITIES 25 -#define TAG "hoermann_door" - namespace esphome { namespace hoermann_door { @@ -61,7 +59,7 @@ class NbsLightOutput: public output::BinaryOutput, public Component{ } void set_state_callback(light::LightState *callback){ - if(callback == nullptr) ESP_LOGW("Hoermann_door(Light)", "Got Nullable callback"); + if(callback == nullptr) ESP_LOGW(COMP_TAG, "Got Nullable callback"); this->callback = callback; } void set_emulator_component(HoermannMainComponent* component){ @@ -74,14 +72,14 @@ class NbsLightOutput: public output::BinaryOutput, public Component{ //ESP_LOGD("Test", "I have no idea"); lastState = mainComponent->getEmulator()->getState().lampOn; if(lastState == true){ - ESP_LOGD(TAG, "Hoermann_door(Light)", "Light State ON"); + ESP_LOGD(COMP_TAG, "Light State ON"); auto call = callback->make_call(); call.set_state(true); call.perform(); } else { - ESP_LOGD(TAG, "Hoermann_door(Light)", "Light State OFF"); + ESP_LOGD(COMP_TAG, "Light State OFF"); auto call = callback->make_call(); call.set_state(false); call.perform(); diff --git a/garage1.yaml b/garage1.yaml index 58ea4ec..11654eb 100644 --- a/garage1.yaml +++ b/garage1.yaml @@ -7,7 +7,7 @@ esphome: esp32: board: wemos_d1_mini32 framework: - type: esp-idf + type: arduino # esp-idf is used by side wo, but sy uses an older esp32 chip that seems to crash with esp-idf (likely power issues) ota: - platform: esphome @@ -41,15 +41,19 @@ uart: tx_pin: 17 baud_rate: 57600 id: hm_connection - data_bits: 8 # Standard - parity: EVEN # NON Standard, None would be standard - stop_bits: 1 # Standard + data_bits: 8 # Standard, just defined for clarity + parity: EVEN # The chip uses even parity + stop_bits: 1 # Standard, just defined for clarity + hoermann_door: id: door_controll_internal uart_connection: hm_connection - tx_pin: 25 + tx_pin: + number: 25 + inverted: false + light: - platform: binary