Restore esp32 support (#3)
This commit is contained in:
parent
3edf018212
commit
b451c8e591
|
@ -9,15 +9,6 @@ external_components:
|
|||
ratgdo:
|
||||
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:
|
||||
- platform: ratgdo
|
||||
id: ${id_prefix}_openings
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.components import uart
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
DEPENDENCIES = ["preferences", "uart"]
|
||||
DEPENDENCIES = ["preferences"]
|
||||
MULTI_CONF = True
|
||||
|
||||
|
||||
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"
|
||||
|
@ -25,24 +24,20 @@ DEFAULT_INPUT_OBST = "D7" # D7 black obstruction sensor terminal
|
|||
|
||||
CONF_RATGDO_ID = "ratgdo_id"
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(RATGDO),
|
||||
cv.Optional(
|
||||
CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO
|
||||
): pins.gpio_output_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO
|
||||
): pins.gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST
|
||||
): pins.gpio_input_pin_schema,
|
||||
}
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
.extend(uart.UART_DEVICE_SCHEMA)
|
||||
)
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(RATGDO),
|
||||
cv.Optional(
|
||||
CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO
|
||||
): pins.gpio_output_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO
|
||||
): pins.gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST
|
||||
): pins.gpio_input_pin_schema,
|
||||
}
|
||||
).extend(cv.COMPONENT_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])
|
||||
cg.add(var.set_input_obst_pin(pin))
|
||||
|
||||
await uart.register_uart_device(var, config)
|
||||
|
||||
cg.add_library(
|
||||
name="secplus",
|
||||
repository="https://github.com/esphome-ratgdo/secplus",
|
||||
version="f98c3220356c27717a25102c0b35815ebbd26ccc",
|
||||
)
|
||||
cg.add_library(
|
||||
name="espsoftwareserial",
|
||||
repository="https://github.com/esphome-ratgdo/espsoftwareserial",
|
||||
version="2f408224633316b997f82339e5b2731b1e561060",
|
||||
)
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace ratgdo {
|
|||
this->input_gdo_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
|
||||
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);
|
||||
|
||||
|
@ -226,20 +226,15 @@ namespace ratgdo {
|
|||
|
||||
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 bool reading = false;
|
||||
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) {
|
||||
// shift serial byte onto msg start
|
||||
msgStart <<= 8;
|
||||
|
@ -368,7 +363,7 @@ namespace ratgdo {
|
|||
this->output_gdo_pin_->digital_write(false); // bring the line low
|
||||
|
||||
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()
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
************************************/
|
||||
|
||||
#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/gpio.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
@ -76,12 +76,14 @@ namespace ratgdo {
|
|||
static void IRAM_ATTR HOT isrObstruction(RATGDOStore* arg);
|
||||
};
|
||||
|
||||
class RATGDOComponent : public uart::UARTDevice, public Component {
|
||||
class RATGDOComponent : public Component {
|
||||
public:
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
void dump_config() override;
|
||||
|
||||
EspSoftwareSerial::UART swSerial;
|
||||
|
||||
uint32_t rollingCodeCounter { 0 };
|
||||
uint32_t lastSyncedRollingCodeCounter { 0 };
|
||||
|
||||
|
|
Loading…
Reference in New Issue