Restore esp32 support (#3)

This commit is contained in:
J. Nick Koston 2023-06-17 09:50:38 -05:00 committed by GitHub
parent 3edf018212
commit b451c8e591
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 47 deletions

View File

@ -9,15 +9,6 @@ external_components:
ratgdo: ratgdo:
id: ${id_prefix} id: ${id_prefix}
uart:
tx_pin:
number: ${uart_tx_pin} # red control terminal / GarageDoorOpener (UART1 TX) pin is D4 on D1 Mini
inverted: true
rx_pin:
number: ${uart_rx_pin} # red control terminal / GarageDoorOpener (UART1 RX) pin is D2 on D1 Mini
inverted: true
baud_rate: 9600
sensor: sensor:
- platform: ratgdo - platform: ratgdo
id: ${id_prefix}_openings id: ${id_prefix}_openings

View File

@ -1,15 +1,14 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome import pins from esphome import pins
from esphome.components import uart
from esphome.const import CONF_ID from esphome.const import CONF_ID
DEPENDENCIES = ["preferences", "uart"] DEPENDENCIES = ["preferences"]
MULTI_CONF = True MULTI_CONF = True
ratgdo_ns = cg.esphome_ns.namespace("ratgdo") ratgdo_ns = cg.esphome_ns.namespace("ratgdo")
RATGDO = ratgdo_ns.class_("RATGDOComponent", cg.Component, uart.UARTDevice) RATGDO = ratgdo_ns.class_("RATGDOComponent", cg.Component)
CONF_OUTPUT_GDO = "output_gdo_pin" CONF_OUTPUT_GDO = "output_gdo_pin"
@ -25,24 +24,20 @@ DEFAULT_INPUT_OBST = "D7" # D7 black obstruction sensor terminal
CONF_RATGDO_ID = "ratgdo_id" CONF_RATGDO_ID = "ratgdo_id"
CONFIG_SCHEMA = ( CONFIG_SCHEMA = cv.Schema(
cv.Schema( {
{ cv.GenerateID(): cv.declare_id(RATGDO),
cv.GenerateID(): cv.declare_id(RATGDO), cv.Optional(
cv.Optional( CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO
CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO ): pins.gpio_output_pin_schema,
): pins.gpio_output_pin_schema, cv.Optional(
cv.Optional( CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO
CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO ): pins.gpio_input_pin_schema,
): pins.gpio_input_pin_schema, cv.Optional(
cv.Optional( CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST
CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST ): pins.gpio_input_pin_schema,
): pins.gpio_input_pin_schema, }
} ).extend(cv.COMPONENT_SCHEMA)
)
.extend(cv.COMPONENT_SCHEMA)
.extend(uart.UART_DEVICE_SCHEMA)
)
RATGDO_CLIENT_SCHMEA = cv.Schema( RATGDO_CLIENT_SCHMEA = cv.Schema(
{ {
@ -66,10 +61,13 @@ async def to_code(config):
pin = await cg.gpio_pin_expression(config[CONF_INPUT_OBST]) pin = await cg.gpio_pin_expression(config[CONF_INPUT_OBST])
cg.add(var.set_input_obst_pin(pin)) cg.add(var.set_input_obst_pin(pin))
await uart.register_uart_device(var, config)
cg.add_library( cg.add_library(
name="secplus", name="secplus",
repository="https://github.com/esphome-ratgdo/secplus", repository="https://github.com/esphome-ratgdo/secplus",
version="f98c3220356c27717a25102c0b35815ebbd26ccc", version="f98c3220356c27717a25102c0b35815ebbd26ccc",
) )
cg.add_library(
name="espsoftwareserial",
repository="https://github.com/esphome-ratgdo/espsoftwareserial",
version="2f408224633316b997f82339e5b2731b1e561060",
)

View File

@ -52,7 +52,7 @@ namespace ratgdo {
this->input_gdo_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); this->input_gdo_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
this->input_obst_pin_->pin_mode(gpio::FLAG_INPUT); this->input_obst_pin_->pin_mode(gpio::FLAG_INPUT);
this->check_uart_settings(9600, 1, esphome::uart::UART_CONFIG_PARITY_NONE, 8); this->swSerial.begin(9600, SWSERIAL_8N1, this->input_gdo_pin_->get_pin(), this->output_gdo_pin_->get_pin(), true);
this->input_obst_pin_->attach_interrupt(RATGDOStore::isrObstruction, &this->store_, gpio::INTERRUPT_ANY_EDGE); this->input_obst_pin_->attach_interrupt(RATGDOStore::isrObstruction, &this->store_, gpio::INTERRUPT_ANY_EDGE);
@ -226,20 +226,15 @@ namespace ratgdo {
void RATGDOComponent::gdoStateLoop() void RATGDOComponent::gdoStateLoop()
{ {
if (!this->swSerial.available()) {
// ESP_LOGD(TAG, "No data available input:%d output:%d", this->input_gdo_pin_->get_pin(), this->output_gdo_pin_->get_pin());
return;
}
uint8_t serData = this->swSerial.read();
static uint32_t msgStart; static uint32_t msgStart;
static bool reading = false; static bool reading = false;
static uint16_t byteCount = 0; static uint16_t byteCount = 0;
static bool isStatus = false;
if (!this->available()) {
// ESP_LOGV(TAG, "No data available input:%d output:%d", this->input_gdo_pin_->get_pin(), this->output_gdo_pin_->get_pin());
return;
}
uint8_t serData;
if (!this->read_byte(&serData)) {
ESP_LOGV(TAG, "Failed to read byte");
return;
}
if (!reading) { if (!reading) {
// shift serial byte onto msg start // shift serial byte onto msg start
msgStart <<= 8; msgStart <<= 8;
@ -368,7 +363,7 @@ namespace ratgdo {
this->output_gdo_pin_->digital_write(false); // bring the line low this->output_gdo_pin_->digital_write(false); // bring the line low
delayMicroseconds(1260); // "LOW" pulse duration before the message start delayMicroseconds(1260); // "LOW" pulse duration before the message start
this->write_array(this->txRollingCode, CODE_LENGTH); this->swSerial.write(this->txRollingCode, CODE_LENGTH);
} }
void RATGDOComponent::sync() void RATGDOComponent::sync()

View File

@ -12,7 +12,7 @@
************************************/ ************************************/
#pragma once #pragma once
#include "esphome/components/uart/uart.h" #include "SoftwareSerial.h" // Using espsoftwareserial https://github.com/plerup/espsoftwareserial
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/gpio.h" #include "esphome/core/gpio.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
@ -76,12 +76,14 @@ namespace ratgdo {
static void IRAM_ATTR HOT isrObstruction(RATGDOStore* arg); static void IRAM_ATTR HOT isrObstruction(RATGDOStore* arg);
}; };
class RATGDOComponent : public uart::UARTDevice, public Component { class RATGDOComponent : public Component {
public: public:
void setup() override; void setup() override;
void loop() override; void loop() override;
void dump_config() override; void dump_config() override;
EspSoftwareSerial::UART swSerial;
uint32_t rollingCodeCounter { 0 }; uint32_t rollingCodeCounter { 0 };
uint32_t lastSyncedRollingCodeCounter { 0 }; uint32_t lastSyncedRollingCodeCounter { 0 };
@ -158,4 +160,4 @@ namespace ratgdo {
}; // RATGDOComponent }; // RATGDOComponent
} // namespace ratgdo } // namespace ratgdo
} // namespace esphome } // namespace esphome