more flex
This commit is contained in:
parent
c62486f296
commit
39fdc5f881
|
@ -21,13 +21,6 @@ DEFAULT_INPUT_GDO = "D2" # D2 red control terminal / GarageDoorOpener (UART1 RX)
|
|||
CONF_INPUT_OBST = "input_obst_pin"
|
||||
DEFAULT_INPUT_OBST = "D7" # D7 black obstruction sensor terminal
|
||||
|
||||
CONF_TRIGGER_OPEN = "trigger_open_pin"
|
||||
DEFAULT_TRIGGER_OPEN = "D5" # D5 dry contact for opening door
|
||||
CONF_TRIGGER_CLOSE = "trigger_close_pin"
|
||||
DEFAULT_TRIGGER_CLOSE = "D6" # D6 dry contact for closing door
|
||||
CONF_TRIGGER_LIGHT = "trigger_light_pin"
|
||||
DEFAULT_TRIGGER_LIGHT = "D3" # D3 dry contact for triggering light (no discrete light commands, so toggle only)
|
||||
|
||||
CONF_STATUS_DOOR = "status_door_pin"
|
||||
DEFAULT_STATUS_DOOR = "D0" # D0 output door status, HIGH for open, LOW for closed
|
||||
CONF_STATUS_OBST = "status_obst_pin"
|
||||
|
@ -49,15 +42,6 @@ CONFIG_SCHEMA = (
|
|||
cv.Optional(
|
||||
CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST
|
||||
): pins.gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_TRIGGER_OPEN, default=DEFAULT_TRIGGER_OPEN
|
||||
): pins.gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_TRIGGER_CLOSE, default=DEFAULT_TRIGGER_CLOSE
|
||||
): pins.gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_TRIGGER_LIGHT, default=DEFAULT_TRIGGER_LIGHT
|
||||
): pins.gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_STATUS_DOOR, default=DEFAULT_STATUS_DOOR
|
||||
): pins.gpio_output_pin_schema,
|
||||
|
|
|
@ -23,65 +23,6 @@ namespace ratgdo {
|
|||
static const char* const TAG = "ratgdo";
|
||||
static const int STARTUP_DELAY = 2000; // delay before enabling interrupts
|
||||
|
||||
/*************************** DRY CONTACT CONTROL OF LIGHT & DOOR
|
||||
* ***************************/
|
||||
void IRAM_ATTR HOT RATGDOStore::isrDoorOpen(RATGDOStore* arg)
|
||||
{
|
||||
static unsigned long lastOpenDoorTime = 0;
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
// Prevent ISR during the first 2 seconds after reboot
|
||||
if (currentMillis < STARTUP_DELAY)
|
||||
return;
|
||||
|
||||
if (!arg->trigger_open.digital_read()) {
|
||||
// save the time of the falling edge
|
||||
lastOpenDoorTime = currentMillis;
|
||||
} else if (currentMillis - lastOpenDoorTime > 500 && currentMillis - lastOpenDoorTime < 10000) {
|
||||
// now see if the rising edge was between 500ms and 10 seconds after the
|
||||
// falling edge
|
||||
arg->dryContactDoorOpen = true;
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR HOT RATGDOStore::isrDoorClose(RATGDOStore* arg)
|
||||
{
|
||||
static unsigned long lastCloseDoorTime = 0;
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
// Prevent ISR during the first 2 seconds after reboot
|
||||
if (currentMillis < STARTUP_DELAY)
|
||||
return;
|
||||
|
||||
if (!arg->trigger_close.digital_read()) {
|
||||
// save the time of the falling edge
|
||||
lastCloseDoorTime = currentMillis;
|
||||
} else if (currentMillis - lastCloseDoorTime > 500 && currentMillis - lastCloseDoorTime < 10000) {
|
||||
// now see if the rising edge was between 500ms and 10 seconds after the
|
||||
// falling edge
|
||||
arg->dryContactDoorClose = true;
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR HOT RATGDOStore::isrLight(RATGDOStore* arg)
|
||||
{
|
||||
static unsigned long lastToggleLightTime = 0;
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
// Prevent ISR during the first 2 seconds after reboot
|
||||
if (currentMillis < STARTUP_DELAY)
|
||||
return;
|
||||
|
||||
if (!arg->trigger_light.digital_read()) {
|
||||
// save the time of the falling edge
|
||||
lastToggleLightTime = currentMillis;
|
||||
} else if (currentMillis - lastToggleLightTime > 500 && currentMillis - lastToggleLightTime < 10000) {
|
||||
// now see if the rising edge was between 500ms and 10 seconds after the
|
||||
// falling edge
|
||||
arg->dryContactToggleLight = true;
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR HOT RATGDOStore::isrObstruction(RATGDOStore* arg)
|
||||
{
|
||||
if (arg->input_obst.digital_read()) {
|
||||
|
@ -102,23 +43,11 @@ namespace ratgdo {
|
|||
this->input_gdo_pin_->setup();
|
||||
this->input_obst_pin_->setup();
|
||||
|
||||
this->trigger_open_pin_->setup();
|
||||
this->trigger_close_pin_->setup();
|
||||
this->trigger_light_pin_->setup();
|
||||
|
||||
this->status_door_pin_->setup();
|
||||
this->status_obst_pin_->setup();
|
||||
|
||||
this->store_.input_obst = this->input_obst_pin_->to_isr();
|
||||
|
||||
this->store_.trigger_open = this->trigger_open_pin_->to_isr();
|
||||
this->store_.trigger_close = this->trigger_close_pin_->to_isr();
|
||||
this->store_.trigger_light = this->trigger_light_pin_->to_isr();
|
||||
|
||||
this->trigger_open_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
|
||||
this->trigger_close_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
|
||||
this->trigger_light_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
|
||||
|
||||
this->status_door_pin_->pin_mode(gpio::FLAG_OUTPUT);
|
||||
this->status_obst_pin_->pin_mode(gpio::FLAG_OUTPUT);
|
||||
|
||||
|
@ -128,9 +57,6 @@ namespace ratgdo {
|
|||
|
||||
this->check_uart_settings(9600, 1, esphome::uart::UART_CONFIG_PARITY_NONE, 8);
|
||||
|
||||
this->trigger_open_pin_->attach_interrupt(RATGDOStore::isrDoorOpen, &this->store_, gpio::INTERRUPT_ANY_EDGE);
|
||||
this->trigger_close_pin_->attach_interrupt(RATGDOStore::isrDoorClose, &this->store_, gpio::INTERRUPT_ANY_EDGE);
|
||||
this->trigger_light_pin_->attach_interrupt(RATGDOStore::isrLight, &this->store_, gpio::INTERRUPT_ANY_EDGE);
|
||||
this->input_obst_pin_->attach_interrupt(RATGDOStore::isrObstruction, &this->store_, gpio::INTERRUPT_ANY_EDGE);
|
||||
|
||||
ESP_LOGD(TAG, "Syncing rolling code counter after reboot...");
|
||||
|
@ -141,7 +67,6 @@ namespace ratgdo {
|
|||
{
|
||||
obstructionLoop();
|
||||
gdoStateLoop();
|
||||
dryContactLoop();
|
||||
statusUpdateLoop();
|
||||
}
|
||||
|
||||
|
@ -151,9 +76,6 @@ namespace ratgdo {
|
|||
LOG_PIN(" Output GDO Pin: ", this->output_gdo_pin_);
|
||||
LOG_PIN(" Input GDO Pin: ", this->input_gdo_pin_);
|
||||
LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_);
|
||||
LOG_PIN(" Trigger Open Pin: ", this->trigger_open_pin_);
|
||||
LOG_PIN(" Trigger Close Pin: ", this->trigger_close_pin_);
|
||||
LOG_PIN(" Trigger Light Pin: ", this->trigger_light_pin_);
|
||||
LOG_PIN(" Status Door Pin: ", this->status_door_pin_);
|
||||
LOG_PIN(" Status Obstruction Pin: ", this->status_obst_pin_);
|
||||
ESP_LOGCONFIG(TAG, " Rolling Code Counter: %d", this->rollingCodeCounter);
|
||||
|
@ -327,28 +249,6 @@ namespace ratgdo {
|
|||
this->txRollingCode[18]);
|
||||
}
|
||||
|
||||
// handle changes to the dry contact state
|
||||
void RATGDOComponent::dryContactLoop()
|
||||
{
|
||||
if (this->store_.dryContactDoorOpen) {
|
||||
ESP_LOGD(TAG, "Dry Contact: open the door");
|
||||
this->store_.dryContactDoorOpen = false;
|
||||
openDoor();
|
||||
}
|
||||
|
||||
if (this->store_.dryContactDoorClose) {
|
||||
ESP_LOGD(TAG, "Dry Contact: close the door");
|
||||
this->store_.dryContactDoorClose = false;
|
||||
closeDoor();
|
||||
}
|
||||
|
||||
if (this->store_.dryContactToggleLight) {
|
||||
ESP_LOGD(TAG, "Dry Contact: toggle the light");
|
||||
this->store_.dryContactToggleLight = false;
|
||||
toggleLight();
|
||||
}
|
||||
}
|
||||
|
||||
/*************************** OBSTRUCTION DETECTION ***************************/
|
||||
|
||||
void RATGDOComponent::obstructionLoop()
|
||||
|
|
|
@ -48,14 +48,6 @@ namespace ratgdo {
|
|||
struct RATGDOStore {
|
||||
ISRInternalGPIOPin input_obst;
|
||||
|
||||
ISRInternalGPIOPin trigger_open;
|
||||
ISRInternalGPIOPin trigger_close;
|
||||
ISRInternalGPIOPin trigger_light;
|
||||
|
||||
bool dryContactDoorOpen { false };
|
||||
bool dryContactDoorClose { false };
|
||||
bool dryContactToggleLight { false };
|
||||
|
||||
int obstructionLowCount = 0; // count obstruction low pulses
|
||||
long lastObstructionHigh = 0; // count time between high pulses from the obst ISR
|
||||
|
||||
|
@ -93,10 +85,6 @@ namespace ratgdo {
|
|||
void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; };
|
||||
void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; };
|
||||
|
||||
void set_trigger_open_pin(InternalGPIOPin* pin) { this->trigger_open_pin_ = pin; };
|
||||
void set_trigger_close_pin(InternalGPIOPin* pin) { this->trigger_close_pin_ = pin; };
|
||||
void set_trigger_light_pin(InternalGPIOPin* pin) { this->trigger_light_pin_ = pin; };
|
||||
|
||||
void set_status_door_pin(InternalGPIOPin* pin) { this->status_door_pin_ = pin; };
|
||||
void set_status_obst_pin(InternalGPIOPin* pin) { this->status_obst_pin_ = pin; };
|
||||
|
||||
|
@ -129,7 +117,6 @@ namespace ratgdo {
|
|||
void sendMotorStatus();
|
||||
void query();
|
||||
void doorStateLoop();
|
||||
void dryContactLoop();
|
||||
void printRollingCode();
|
||||
void getRollingCode(Commands command);
|
||||
void gdoStateLoop();
|
||||
|
@ -153,10 +140,6 @@ namespace ratgdo {
|
|||
InternalGPIOPin* input_gdo_pin_;
|
||||
InternalGPIOPin* input_obst_pin_;
|
||||
|
||||
InternalGPIOPin* trigger_open_pin_;
|
||||
InternalGPIOPin* trigger_close_pin_;
|
||||
InternalGPIOPin* trigger_light_pin_;
|
||||
|
||||
InternalGPIOPin* status_door_pin_;
|
||||
InternalGPIOPin* status_obst_pin_;
|
||||
|
||||
|
|
Loading…
Reference in New Issue