This commit is contained in:
J. Nick Koston 2023-06-05 13:07:10 -05:00
parent 6a00edce30
commit 69cf8231a1
No known key found for this signature in database
2 changed files with 64 additions and 81 deletions

View File

@ -327,10 +327,6 @@ void RATGDOComponent::sendCurrentCounter() {
ESP_LOGD(TAG, "Current counter %d", rollingCodeCounter); ESP_LOGD(TAG, "Current counter %d", rollingCodeCounter);
} }
/********************************** MANAGE HARDWARE BUTTON
* *****************************************/
void RATGDOComponent::manageHardwareButton() {}
/************************* DOOR COMMUNICATION *************************/ /************************* DOOR COMMUNICATION *************************/
/* /*
* Transmit a message to the door opener over uart1 * Transmit a message to the door opener over uart1

View File

@ -11,8 +11,8 @@
* GNU GENERAL PUBLIC LICENSE * GNU GENERAL PUBLIC LICENSE
************************************/ ************************************/
#ifndef _RATGDO_H #pragma once
#define _RATGDO_H
#include "SoftwareSerial.h" #include "SoftwareSerial.h"
#include "rolling_code.h" #include "rolling_code.h"
@ -40,92 +40,79 @@ namespace ratgdo {
SoftwareSerial swSerial; SoftwareSerial swSerial;
/********************************** BOOTSTRAP MANAGER
* *****************************************/
BootstrapManager bootstrapManager;
/********************************** MQTT TOPICS class RATGDOComponent; // this component
* *****************************************/
String doorCommandTopic = ""; // will be mqttTopicPrefix/deviceName/command
String setCounterTopic =
""; // will be mqttTopicPrefix/deviceName/set_code_counter
String doorCommand = ""; // will be [open|close|light] class RATGDOComponent : public Component {
String overallStatusTopic = public:
""; // legacy from 1.0. Will be mqttTopicPrefix/deviceName/status void setup() override;
String availabilityStatusTopic = ""; // online|offline void loop() override;
String obstructionStatusTopic = ""; // obstructed|clear /********************************** GLOBAL VARS
String doorStatusTopic = * *****************************************/
""; // open|opening|closing|closed|reed_open|reed_closed unsigned int rollingCodeCounter;
String rollingCodeTopic = byte rollingCode[CODE_LENGTH];
""; // broadcast the current rolling code count for debugging purposes String doorState =
"unknown"; // will be
// [online|offline|opening|open|closing|closed|obstructed|clear|reed_open|reed_closed]
/********************************** GLOBAL VARS unsigned int obstructionLowCount = 0; // count obstruction low pulses
* *****************************************/ unsigned long lastObstructionHigh =
bool setupComplete = false; 0; // count time between high pulses from the obst ISR
unsigned int rollingCodeCounter;
byte rollingCode[CODE_LENGTH];
String doorState =
"unknown"; // will be
// [online|offline|opening|open|closing|closed|obstructed|clear|reed_open|reed_closed]
unsigned int obstructionLowCount = 0; // count obstruction low pulses bool doorIsObstructed = false;
unsigned long lastObstructionHigh = bool dryContactDoorOpen = false;
0; // count time between high pulses from the obst ISR bool dryContactDoorClose = false;
bool dryContactToggleLight = false;
int doorPositionCounter = 0; // calculate the door's movement and position
bool rpm1Pulsed =
false; // did rpm1 get a pulse or not - eliminates an issue when the sensor
// is parked on a high pulse which fires rpm2 isr
bool doorIsObstructed = false; /********************************** FUNCTION DECLARATION
bool dryContactDoorOpen = false; * *****************************************/
bool dryContactDoorClose = false; void transmit(byte *payload, unsigned int length);
bool dryContactToggleLight = false; void sync();
int doorPositionCounter = 0; // calculate the door's movement and position void openDoor();
bool rpm1Pulsed = void closeDoor();
false; // did rpm1 get a pulse or not - eliminates an issue when the sensor void toggleLight();
// is parked on a high pulse which fires rpm2 isr
/********************************** FUNCTION DECLARATION void obstructionLoop();
* *****************************************/ void obstructionDetected();
void transmit(byte *payload, unsigned int length); void obstructionCleared();
void sync();
void openDoor();
void closeDoor();
void toggleLight();
void obstructionLoop(); void sendDoorStatus();
void obstructionDetected();
void obstructionCleared();
void sendDoorStatus(); void doorStateLoop();
void dryContactLoop();
void doorStateLoop(); /********************************** INTERRUPT SERVICE ROUTINES
void dryContactLoop(); * ***********************************/
void IRAM_ATTR isrDebounce(const char *type);
void IRAM_ATTR isrDoorOpen();
void IRAM_ATTR isrDoorClose();
void IRAM_ATTR isrLight();
void IRAM_ATTR isrObstruction();
void IRAM_ATTR isrRPM1();
void IRAM_ATTR isrRPM2();
/********************************** INTERRUPT SERVICE ROUTINES /*** Static Codes ***/
* ***********************************/ byte SYNC1[] = {0x55, 0x01, 0x00, 0x61, 0x12, 0x49, 0x2c, 0x92, 0x5b, 0x24,
void IRAM_ATTR isrDebounce(const char *type); 0x96, 0x86, 0x0b, 0x65, 0x96, 0xd9, 0x8f, 0x26, 0x4a};
void IRAM_ATTR isrDoorOpen(); byte SYNC2[] = {0x55, 0x01, 0x00, 0x08, 0x34, 0x93, 0x49, 0xb4, 0x92, 0x4d,
void IRAM_ATTR isrDoorClose(); 0x20, 0x26, 0x1b, 0x4d, 0xb4, 0xdb, 0xad, 0x76, 0x93};
void IRAM_ATTR isrLight(); byte SYNC3[] = {0x55, 0x01, 0x00, 0x06, 0x1b, 0x2c, 0xbf, 0x4b, 0x6d, 0xb6,
void IRAM_ATTR isrObstruction(); 0x4b, 0x18, 0x20, 0x92, 0x09, 0x20, 0xf2, 0x11, 0x2c};
void IRAM_ATTR isrRPM1(); byte SYNC4[] = {0x55, 0x01, 0x00, 0x95, 0x29, 0x36, 0x91, 0x29, 0x36, 0x9a,
void IRAM_ATTR isrRPM2(); 0x69, 0x05, 0x2f, 0xbe, 0xdf, 0x6d, 0x16, 0xcb, 0xe7};
byte *SYNC_CODE[] = {SYNC1, SYNC2, SYNC3, SYNC4};
/*** Static Codes ***/ byte DOOR_CODE[] = {0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe,
byte SYNC1[] = {0x55, 0x01, 0x00, 0x61, 0x12, 0x49, 0x2c, 0x92, 0x5b, 0x24, 0xfc, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x36, 0xb3};
0x96, 0x86, 0x0b, 0x65, 0x96, 0xd9, 0x8f, 0x26, 0x4a};
byte SYNC2[] = {0x55, 0x01, 0x00, 0x08, 0x34, 0x93, 0x49, 0xb4, 0x92, 0x4d,
0x20, 0x26, 0x1b, 0x4d, 0xb4, 0xdb, 0xad, 0x76, 0x93};
byte SYNC3[] = {0x55, 0x01, 0x00, 0x06, 0x1b, 0x2c, 0xbf, 0x4b, 0x6d, 0xb6,
0x4b, 0x18, 0x20, 0x92, 0x09, 0x20, 0xf2, 0x11, 0x2c};
byte SYNC4[] = {0x55, 0x01, 0x00, 0x95, 0x29, 0x36, 0x91, 0x29, 0x36, 0x9a,
0x69, 0x05, 0x2f, 0xbe, 0xdf, 0x6d, 0x16, 0xcb, 0xe7};
byte *SYNC_CODE[] = {SYNC1, SYNC2, SYNC3, SYNC4};
byte DOOR_CODE[] = {0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe, byte LIGHT_CODE[] = {0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe,
0xfc, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x36, 0xb3}; 0xff, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x76, 0xb1};
byte LIGHT_CODE[] = {0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe, } // RATGDOComponent
0xff, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x76, 0xb1};
#endif } // namespace ratgdo
} } // namespace esphome
}