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

@@ -1,5 +1,5 @@
#include "hciemulator.h"
#include "Arduino.h"
#define CHECKCHANGEDSET(Target, Value, Flag) \
if ((Target) != (Value)) \
{ \
@@ -33,7 +33,7 @@ void LogCore(int Level, const char *msg, const unsigned char *data = NULL, size_
}
else
{
Serial.println(msg);
ESP_LOGD(TAG, msg);
}
}
#else
@@ -98,14 +98,15 @@ uint16_t calculateCRC(uint8_t *buffer, int length)
return crc;
}
HCIEmulator::HCIEmulator()
HCIEmulator::HCIEmulator(esphome::InternalGPIOPin* pin, esphome::uart::UARTComponent* uart)
{
m_state.valid = false;
m_statemachine = WAITING;
m_rxlen = m_txlen = 0;
m_recvTime = m_lastStateTime = 0;
m_skipFrame = false;
m_port = &Serial2;
m_port = uart;
m_pin = pin;
m_statusCallback = NULL;
setLogLevel(DEFAULTLOGLEVEL);
};
@@ -122,7 +123,7 @@ void HCIEmulator::poll()
if (m_port->available() > 0)
{
// Serial.println("got data");
m_rxlen += m_port->readBytes((char *)(m_rxbuffer + m_rxlen), _min((int)(255 - m_rxlen), m_port->available()));
m_rxlen += m_port->read_array((u_int8_t *)(m_rxbuffer + m_rxlen), _min((int)(255 - m_rxlen), m_port->available()));
if (m_rxlen > 254)
{
Log(LL_ERROR, "RX Bufferoverflow, skip next Frame");
@@ -162,18 +163,19 @@ void HCIEmulator::poll()
// Log(LL_DEBUG, ("ST:"+String(m_lastSendTime)).c_str());
digitalWrite(TX_ON, HIGH);
m_pin->digital_write(HIGH);
// Log3(LL_DEBUG, "write data: ");
m_port->write(m_txbuffer, m_txlen);
m_port->write_array(m_txbuffer, m_txlen);
Log3(LL_DEBUG, "Response: ", m_txbuffer, m_txlen);
delayMicroseconds(m_txlen * 9 * 22); // 8 bits + par * Bittime 18 micros on 57600 bauds
digitalWrite(TX_ON, LOW);
m_pin->digital_write(LOW);
m_txlen = 0;
}
}
else
{
Serial.println("skipped frame");
ESP_LOGD(TAG, "skipped frame");
}
m_skipFrame = false;