Updated Hörmann_door to completely use namespaces. Makes code a bit cleaner
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef USE_COVER
|
//#ifdef USE_COVER
|
||||||
|
|
||||||
class HoermannDoorx;
|
|
||||||
|
|
||||||
#include "esphome.h"
|
#include "esphome.h"
|
||||||
#include "hoermann.h"
|
#include "hoermann.h"
|
||||||
@@ -55,7 +53,7 @@ public:
|
|||||||
manual = false;
|
manual = false;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
ESP_LOGD("Door controller", "Not yet supported");
|
ESP_LOGD(COMP_TAG, "Not yet supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -106,4 +104,4 @@ public:
|
|||||||
} // namespace hoermann
|
} // namespace hoermann
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
||||||
#endif
|
//#endif
|
@@ -1,5 +1,9 @@
|
|||||||
#include "hciemulator.h"
|
#include "hciemulator.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace hoermann_door {
|
||||||
|
|
||||||
#define CHECKCHANGEDSET(Target, Value, Flag) \
|
#define CHECKCHANGEDSET(Target, Value, Flag) \
|
||||||
if ((Target) != (Value)) \
|
if ((Target) != (Value)) \
|
||||||
{ \
|
{ \
|
||||||
@@ -8,9 +12,9 @@
|
|||||||
}
|
}
|
||||||
int hciloglevel = LL_DEBUG;
|
int hciloglevel = LL_DEBUG;
|
||||||
|
|
||||||
#define SOFTSERIAL 1
|
//#define SOFTSERIAL 1
|
||||||
|
|
||||||
#ifdef SOFTSERIAL
|
//#ifdef SOFTSERIAL
|
||||||
#define Log(Level, Message) LogCore(Level, Message)
|
#define Log(Level, Message) LogCore(Level, Message)
|
||||||
#define Log3(Level, Message, Buffer, Len) LogCore(Level, Message, Buffer, Len)
|
#define Log3(Level, Message, Buffer, Len) LogCore(Level, Message, Buffer, Len)
|
||||||
// LOGLEVEL
|
// LOGLEVEL
|
||||||
@@ -23,7 +27,7 @@ void LogCore(int Level, const char *msg, const unsigned char *data = NULL, size_
|
|||||||
if (data != NULL && datalen > 0)
|
if (data != NULL && datalen > 0)
|
||||||
{
|
{
|
||||||
//std::string newmsg(msg);
|
//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);
|
strncpy(newmsg, msg, strlen(msg) + 1);
|
||||||
newmsg[strlen(msg)] = '\0';
|
newmsg[strlen(msg)] = '\0';
|
||||||
char str[4];
|
char str[4];
|
||||||
@@ -41,10 +45,10 @@ void LogCore(int Level, const char *msg, const unsigned char *data = NULL, size_
|
|||||||
ESP_LOGD(TAG, msg);
|
ESP_LOGD(TAG, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
//#else
|
||||||
#define Log(Level, Message)
|
//#define Log(Level, Message)
|
||||||
#define Log3(Level, Message, Buffer, Len)
|
//#define Log3(Level, Message, Buffer, Len)
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
int HCIEmulator::getLogLevel()
|
int HCIEmulator::getLogLevel()
|
||||||
{
|
{
|
||||||
@@ -203,6 +207,7 @@ void HCIEmulator::poll()
|
|||||||
void HCIEmulator::processFrame()
|
void HCIEmulator::processFrame()
|
||||||
{
|
{
|
||||||
m_txlen = 0; // clear send buffer
|
m_txlen = 0; // clear send buffer
|
||||||
|
Log3(LL_DEBUG, "Incomming Data: ", m_rxbuffer, m_rxlen);
|
||||||
|
|
||||||
if (m_rxlen < 5)
|
if (m_rxlen < 5)
|
||||||
{
|
{
|
||||||
@@ -509,3 +514,6 @@ void HCIEmulator::onStatusChanged(callback_function_t handler)
|
|||||||
{
|
{
|
||||||
m_statusCallback = handler;
|
m_statusCallback = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,12 +1,6 @@
|
|||||||
#ifndef __hciemulator_h
|
#ifndef __hciemulator_h
|
||||||
#define __hciemulator_h
|
#define __hciemulator_h
|
||||||
|
|
||||||
#ifdef USE_ESP_IDF
|
|
||||||
//#include <cstdint>
|
|
||||||
//#include <functional>
|
|
||||||
//#include <algorithm>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "esphome/components/uart/uart.h"
|
#include "esphome/components/uart/uart.h"
|
||||||
|
|
||||||
#define LL_OFF 0
|
#define LL_OFF 0
|
||||||
@@ -32,6 +26,9 @@
|
|||||||
#define T1_5 750
|
#define T1_5 750
|
||||||
#define T3_5 4800 //
|
#define T3_5 4800 //
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace hoermann_door {
|
||||||
|
|
||||||
static const char *const TAG = "HCIEmulator";
|
static const char *const TAG = "HCIEmulator";
|
||||||
|
|
||||||
enum DoorState : uint8_t
|
enum DoorState : uint8_t
|
||||||
@@ -81,7 +78,7 @@ class HCIEmulator
|
|||||||
public:
|
public:
|
||||||
typedef std::function<void(const SHCIState &)> callback_function_t;
|
typedef std::function<void(const SHCIState &)> callback_function_t;
|
||||||
|
|
||||||
HCIEmulator(esphome::InternalGPIOPin* pin, esphome::uart::UARTComponent* uart);
|
HCIEmulator(InternalGPIOPin* pin, uart::UARTComponent* uart);
|
||||||
|
|
||||||
void poll();
|
void poll();
|
||||||
|
|
||||||
@@ -94,7 +91,7 @@ public:
|
|||||||
|
|
||||||
const SHCIState &getState()
|
const SHCIState &getState()
|
||||||
{
|
{
|
||||||
if (esphome::micros() - m_recvTime > 2000000)
|
if (micros() - m_recvTime > 2000000)
|
||||||
{
|
{
|
||||||
// 2 sec without statusmessage
|
// 2 sec without statusmessage
|
||||||
m_state.valid = false;
|
m_state.valid = false;
|
||||||
@@ -104,7 +101,7 @@ public:
|
|||||||
|
|
||||||
unsigned long getMessageAge()
|
unsigned long getMessageAge()
|
||||||
{
|
{
|
||||||
return esphome::micros() - m_recvTime;
|
return micros() - m_recvTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getLogLevel();
|
int getLogLevel();
|
||||||
@@ -124,8 +121,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
callback_function_t m_statusCallback;
|
callback_function_t m_statusCallback;
|
||||||
|
|
||||||
esphome::InternalGPIOPin* m_pin;
|
InternalGPIOPin* m_pin;
|
||||||
esphome::uart::UARTComponent* m_port;
|
uart::UARTComponent* m_port;
|
||||||
|
|
||||||
SHCIState m_state;
|
SHCIState m_state;
|
||||||
StateMachine m_statemachine;
|
StateMachine m_statemachine;
|
||||||
@@ -147,4 +144,7 @@ private:
|
|||||||
bool m_skipFrame;
|
bool m_skipFrame;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -2,14 +2,17 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace hoermann_door {
|
||||||
class HoermannMainComponent;
|
class HoermannMainComponent;
|
||||||
|
}
|
||||||
|
}
|
||||||
#include "hciemulator.h"
|
#include "hciemulator.h"
|
||||||
#include "esphome/components/uart/uart.h"
|
#include "esphome/components/uart/uart.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace hoermann_door {
|
namespace hoermann_door {
|
||||||
|
static const char *const COMP_TAG = "Hoermann";
|
||||||
static const char *const TAG = "Hoermann";
|
|
||||||
|
|
||||||
void dispatcherFn(void *arg);
|
void dispatcherFn(void *arg);
|
||||||
|
|
||||||
@@ -72,8 +75,8 @@ class HoermannMainComponent: public Component{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dump_config() override {
|
void dump_config() override {
|
||||||
ESP_LOGCONFIG(TAG, "hoermann_door_component:");
|
ESP_LOGCONFIG(COMP_TAG, "hoermann_door_component:");
|
||||||
ESP_LOGCONFIG(TAG, " UART: %d", this->_uart->get_baud_rate());
|
ESP_LOGCONFIG(COMP_TAG, " UART: %d", this->_uart->get_baud_rate());
|
||||||
//LOG_PIN(TAG, this->_tx_on);
|
//LOG_PIN(TAG, this->_tx_on);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -13,8 +13,6 @@ class NbsLightManager;
|
|||||||
#define TX_ON 25
|
#define TX_ON 25
|
||||||
//#define configMAX_PRIORITIES 25
|
//#define configMAX_PRIORITIES 25
|
||||||
|
|
||||||
#define TAG "hoermann_door"
|
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace hoermann_door {
|
namespace hoermann_door {
|
||||||
|
|
||||||
@@ -61,7 +59,7 @@ class NbsLightOutput: public output::BinaryOutput, public Component{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void set_state_callback(light::LightState *callback){
|
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;
|
this->callback = callback;
|
||||||
}
|
}
|
||||||
void set_emulator_component(HoermannMainComponent* component){
|
void set_emulator_component(HoermannMainComponent* component){
|
||||||
@@ -74,14 +72,14 @@ class NbsLightOutput: public output::BinaryOutput, public Component{
|
|||||||
//ESP_LOGD("Test", "I have no idea");
|
//ESP_LOGD("Test", "I have no idea");
|
||||||
lastState = mainComponent->getEmulator()->getState().lampOn;
|
lastState = mainComponent->getEmulator()->getState().lampOn;
|
||||||
if(lastState == true){
|
if(lastState == true){
|
||||||
ESP_LOGD(TAG, "Hoermann_door(Light)", "Light State ON");
|
ESP_LOGD(COMP_TAG, "Light State ON");
|
||||||
|
|
||||||
auto call = callback->make_call();
|
auto call = callback->make_call();
|
||||||
call.set_state(true);
|
call.set_state(true);
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ESP_LOGD(TAG, "Hoermann_door(Light)", "Light State OFF");
|
ESP_LOGD(COMP_TAG, "Light State OFF");
|
||||||
auto call = callback->make_call();
|
auto call = callback->make_call();
|
||||||
call.set_state(false);
|
call.set_state(false);
|
||||||
call.perform();
|
call.perform();
|
||||||
|
14
garage1.yaml
14
garage1.yaml
@@ -7,7 +7,7 @@ esphome:
|
|||||||
esp32:
|
esp32:
|
||||||
board: wemos_d1_mini32
|
board: wemos_d1_mini32
|
||||||
framework:
|
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:
|
ota:
|
||||||
- platform: esphome
|
- platform: esphome
|
||||||
@@ -41,15 +41,19 @@ uart:
|
|||||||
tx_pin: 17
|
tx_pin: 17
|
||||||
baud_rate: 57600
|
baud_rate: 57600
|
||||||
id: hm_connection
|
id: hm_connection
|
||||||
data_bits: 8 # Standard
|
data_bits: 8 # Standard, just defined for clarity
|
||||||
parity: EVEN # NON Standard, None would be standard
|
parity: EVEN # The chip uses even parity
|
||||||
stop_bits: 1 # Standard
|
stop_bits: 1 # Standard, just defined for clarity
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hoermann_door:
|
hoermann_door:
|
||||||
id: door_controll_internal
|
id: door_controll_internal
|
||||||
uart_connection: hm_connection
|
uart_connection: hm_connection
|
||||||
tx_pin: 25
|
tx_pin:
|
||||||
|
number: 25
|
||||||
|
inverted: false
|
||||||
|
|
||||||
|
|
||||||
light:
|
light:
|
||||||
- platform: binary
|
- platform: binary
|
||||||
|
Reference in New Issue
Block a user