This commit is contained in:
J. Nick Koston 2023-06-05 12:54:46 -05:00
parent b2588fa06f
commit 580f2cd831
No known key found for this signature in database
2 changed files with 21 additions and 19 deletions

View File

@ -63,12 +63,9 @@ void RATGDOComponent::loop() {
dryContactLoop(); dryContactLoop();
} }
} // namespace ratgdo
} // namespace esphome
/*************************** DETECTING THE DOOR STATE /*************************** DETECTING THE DOOR STATE
* ***************************/ * ***************************/
void doorStateLoop() { void RATGDOComponent::doorStateLoop() {
static bool rotaryEncoderDetected = false; static bool rotaryEncoderDetected = false;
static int lastDoorPositionCounter = 0; static int lastDoorPositionCounter = 0;
static int lastDirectionChangeCounter = 0; static int lastDirectionChangeCounter = 0;
@ -140,7 +137,7 @@ void doorStateLoop() {
/*************************** DRY CONTACT CONTROL OF LIGHT & DOOR /*************************** DRY CONTACT CONTROL OF LIGHT & DOOR
* ***************************/ * ***************************/
void IRAM_ATTR isrDebounce(const char *type) { void IRAM_ATTR RATGDOComponent::isrDebounce(const char *type) {
static unsigned long lastOpenDoorTime = 0; static unsigned long lastOpenDoorTime = 0;
static unsigned long lastCloseDoorTime = 0; static unsigned long lastCloseDoorTime = 0;
static unsigned long lastToggleLightTime = 0; static unsigned long lastToggleLightTime = 0;
@ -204,7 +201,7 @@ void IRAM_ATTR isrRPM1() { rpm1Pulsed = true; }
// When RPM1 LOW on RPM2 rising edge, door opening: // When RPM1 LOW on RPM2 rising edge, door opening:
// RPM1: ___|--|__ // RPM1: ___|--|__
// RPM2: __|--|___ // RPM2: __|--|___
void IRAM_ATTR isrRPM2() { void IRAM_ATTR RATGDOComponent::isrRPM2() {
// The encoder updates faster than the ESP wants to process, so by sampling // The encoder updates faster than the ESP wants to process, so by sampling
// every 5ms we get a more reliable curve The counter is behind the actual // every 5ms we get a more reliable curve The counter is behind the actual
// pulse counter, but it doesn't matter since we only need a reliable linear // pulse counter, but it doesn't matter since we only need a reliable linear
@ -238,7 +235,7 @@ void IRAM_ATTR isrRPM2() {
} }
// handle changes to the dry contact state // handle changes to the dry contact state
void dryContactLoop() { void RATGDOComponent::dryContactLoop() {
if (dryContactDoorOpen) { if (dryContactDoorOpen) {
ESP_LOGD(TAG, "Dry Contact: open the door"); ESP_LOGD(TAG, "Dry Contact: open the door");
dryContactDoorOpen = false; dryContactDoorOpen = false;
@ -267,7 +264,7 @@ void IRAM_ATTR isrObstruction() {
} }
} }
void obstructionLoop() { void RATGDOComponent::obstructionLoop() {
long currentMillis = millis(); long currentMillis = millis();
static unsigned long lastMillis = 0; static unsigned long lastMillis = 0;
@ -301,7 +298,7 @@ void obstructionLoop() {
} }
} }
void obstructionDetected() { void RATGDOComponent::obstructionDetected() {
static unsigned long lastInterruptTime = 0; static unsigned long lastInterruptTime = 0;
unsigned long interruptTime = millis(); unsigned long interruptTime = millis();
// Anything less than 100ms is a bounce and is ignored // Anything less than 100ms is a bounce and is ignored
@ -313,7 +310,7 @@ void obstructionDetected() {
lastInterruptTime = interruptTime; lastInterruptTime = interruptTime;
} }
void obstructionCleared() { void RATGDOComponent::obstructionCleared() {
if (doorIsObstructed) { if (doorIsObstructed) {
doorIsObstructed = false; doorIsObstructed = false;
digitalWrite(STATUS_OBST, LOW); digitalWrite(STATUS_OBST, LOW);
@ -321,16 +318,18 @@ void obstructionCleared() {
} }
} }
void sendDoorStatus() { ESP_LOGD(TAG, "Door state %s", doorState); } void RATGDOComponent::sendDoorStatus() {
ESP_LOGD(TAG, "Door state %s", doorState);
}
void sendCurrentCounter() { void RATGDOComponent::sendCurrentCounter() {
String msg = String(rollingCodeCounter); String msg = String(rollingCodeCounter);
ESP_LOGD(TAG, "Current counter %d", rollingCodeCounter); ESP_LOGD(TAG, "Current counter %d", rollingCodeCounter);
} }
/********************************** MANAGE HARDWARE BUTTON /********************************** MANAGE HARDWARE BUTTON
* *****************************************/ * *****************************************/
void manageHardwareButton() {} void RATGDOComponent::manageHardwareButton() {}
/************************* DOOR COMMUNICATION *************************/ /************************* DOOR COMMUNICATION *************************/
/* /*
@ -341,7 +340,7 @@ void manageHardwareButton() {}
* The opener requires a specific duration low/high pulse before it will accept * The opener requires a specific duration low/high pulse before it will accept
* a message * a message
*/ */
void transmit(byte *payload, unsigned int length) { void RATGDOComponent::transmit(byte *payload, unsigned int length) {
digitalWrite(OUTPUT_GDO, HIGH); // pull the line high for 1305 micros so the digitalWrite(OUTPUT_GDO, HIGH); // pull the line high for 1305 micros so the
// door opener responds to the message // door opener responds to the message
delayMicroseconds(1305); delayMicroseconds(1305);
@ -351,7 +350,7 @@ void transmit(byte *payload, unsigned int length) {
swSerial.write(payload, length); swSerial.write(payload, length);
} }
void sync() { void RATGDOComponent::sync() {
if (!useRollingCodes) if (!useRollingCodes)
return; return;
@ -382,7 +381,7 @@ void sync() {
writeCounterToFlash(); writeCounterToFlash();
} }
void openDoor() { void RATGDOComponent::openDoor() {
if (doorState == "open" || doorState == "opening") { if (doorState == "open" || doorState == "opening") {
ESP_LOGD(TAG, "The door is already %s", doorState); ESP_LOGD(TAG, "The door is already %s", doorState);
return; return;
@ -414,7 +413,7 @@ void openDoor() {
} }
} }
void closeDoor() { void RATGDOComponent::closeDoor() {
if (doorState == "closed" || doorState == "closing") { if (doorState == "closed" || doorState == "closing") {
ESP_LOGD(TAG, "The door is already %s", doorState); ESP_LOGD(TAG, "The door is already %s", doorState);
return; return;
@ -446,7 +445,7 @@ void closeDoor() {
} }
} }
void toggleLight() { void RATGDOComponent::toggleLight() {
if (useRollingCodes) { if (useRollingCodes) {
getRollingCode("light"); getRollingCode("light");
transmit(rollingCode, CODE_LENGTH); transmit(rollingCode, CODE_LENGTH);
@ -462,3 +461,6 @@ void toggleLight() {
transmit(LIGHT_CODE, CODE_LENGTH); transmit(LIGHT_CODE, CODE_LENGTH);
} }
} }
} // namespace ratgdo
} // namespace esphome

View File

@ -14,8 +14,8 @@
#ifndef _RATGDO_H #ifndef _RATGDO_H
#define _RATGDO_H #define _RATGDO_H
#include "rolling_code.h"
#include "SoftwareSerial.h" #include "SoftwareSerial.h"
#include "rolling_code.h"
SoftwareSerial swSerial; SoftwareSerial swSerial;