This commit is contained in:
J. Nick Koston 2023-06-05 12:29:04 -05:00
parent 3ef85940ce
commit 6faf247491
No known key found for this signature in database
2 changed files with 59 additions and 38 deletions

View File

@ -14,55 +14,74 @@
#ifndef _RATGDO_H #ifndef _RATGDO_H
#define _RATGDO_H #define _RATGDO_H
#include "rolling_code.h" #include "rolling_code.h"
SoftwareSerial swSerial; SoftwareSerial swSerial;
/********************************** BOOTSTRAP MANAGER *****************************************/ /********************************** BOOTSTRAP MANAGER
* *****************************************/
BootstrapManager bootstrapManager; BootstrapManager bootstrapManager;
/********************************** PIN DEFINITIONS *****************************************/ /********************************** PIN DEFINITIONS
#define OUTPUT_GDO D4 // red control terminal / GarageDoorOpener (UART1 TX) pin is D4 on D1 Mini * *****************************************/
#define OUTPUT_GDO \
D4 // red control terminal / GarageDoorOpener (UART1 TX) pin is D4 on D1 Mini
#define TRIGGER_OPEN D5 // dry contact for opening door #define TRIGGER_OPEN D5 // dry contact for opening door
#define TRIGGER_CLOSE D6 // dry contact for closing door #define TRIGGER_CLOSE D6 // dry contact for closing door
#define TRIGGER_LIGHT D3 // dry contact for triggering light (no discrete light commands, so toggle only) #define TRIGGER_LIGHT \
D3 // dry contact for triggering light (no discrete light commands, so toggle
// only)
#define STATUS_DOOR D0 // output door status, HIGH for open, LOW for closed #define STATUS_DOOR D0 // output door status, HIGH for open, LOW for closed
#define STATUS_OBST D8 // output for obstruction status, HIGH for obstructed, LOW for clear #define STATUS_OBST \
#define INPUT_RPM1 D1 // RPM1 rotary encoder input OR reed switch if not soldering to the door opener logic board D8 // output for obstruction status, HIGH for obstructed, LOW for clear
#define INPUT_RPM2 D2 // RPM2 rotary encoder input OR not used if using reed switch #define INPUT_RPM1 \
D1 // RPM1 rotary encoder input OR reed switch if not soldering to the door
// opener logic board
#define INPUT_RPM2 \
D2 // RPM2 rotary encoder input OR not used if using reed switch
#define INPUT_OBST D7 // black obstruction sensor terminal #define INPUT_OBST D7 // black obstruction sensor terminal
/********************************** MQTT TOPICS
/********************************** MQTT TOPICS *****************************************/ * *****************************************/
String doorCommandTopic = ""; // will be mqttTopicPrefix/deviceName/command String doorCommandTopic = ""; // will be mqttTopicPrefix/deviceName/command
String setCounterTopic = ""; // will be mqttTopicPrefix/deviceName/set_code_counter String setCounterTopic =
""; // will be mqttTopicPrefix/deviceName/set_code_counter
String doorCommand = ""; // will be [open|close|light] String doorCommand = ""; // will be [open|close|light]
String overallStatusTopic = ""; // legacy from 1.0. Will be mqttTopicPrefix/deviceName/status String overallStatusTopic =
""; // legacy from 1.0. Will be mqttTopicPrefix/deviceName/status
String availabilityStatusTopic = ""; // online|offline String availabilityStatusTopic = ""; // online|offline
String obstructionStatusTopic = ""; // obstructed|clear String obstructionStatusTopic = ""; // obstructed|clear
String doorStatusTopic = ""; // open|opening|closing|closed|reed_open|reed_closed String doorStatusTopic =
String rollingCodeTopic = ""; // broadcast the current rolling code count for debugging purposes ""; // open|opening|closing|closed|reed_open|reed_closed
String rollingCodeTopic =
""; // broadcast the current rolling code count for debugging purposes
/********************************** GLOBAL VARS *****************************************/ /********************************** GLOBAL VARS
* *****************************************/
bool setupComplete = false; bool setupComplete = false;
unsigned int rollingCodeCounter; unsigned int rollingCodeCounter;
byte rollingCode[CODE_LENGTH]; byte rollingCode[CODE_LENGTH];
String doorState = "unknown"; // will be [online|offline|opening|open|closing|closed|obstructed|clear|reed_open|reed_closed] 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 unsigned int obstructionLowCount = 0; // count obstruction low pulses
unsigned long lastObstructionHigh = 0; // count time between high pulses from the obst ISR unsigned long lastObstructionHigh =
0; // count time between high pulses from the obst ISR
bool doorIsObstructed = false; bool doorIsObstructed = false;
bool dryContactDoorOpen = false; bool dryContactDoorOpen = false;
bool dryContactDoorClose = false; bool dryContactDoorClose = false;
bool dryContactToggleLight = false; bool dryContactToggleLight = false;
int doorPositionCounter = 0; // calculate the door's movement and position 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 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
/********************************** FUNCTION DECLARATION *****************************************/ /********************************** FUNCTION DECLARATION
void transmit(byte* payload, unsigned int length); * *****************************************/
void transmit(byte *payload, unsigned int length);
void sync(); void sync();
void openDoor(); void openDoor();
void closeDoor(); void closeDoor();
@ -77,7 +96,8 @@ void sendDoorStatus();
void doorStateLoop(); void doorStateLoop();
void dryContactLoop(); void dryContactLoop();
/********************************** INTERRUPT SERVICE ROUTINES ***********************************/ /********************************** INTERRUPT SERVICE ROUTINES
* ***********************************/
void IRAM_ATTR isrDebounce(const char *type); void IRAM_ATTR isrDebounce(const char *type);
void IRAM_ATTR isrDoorOpen(); void IRAM_ATTR isrDoorOpen();
void IRAM_ATTR isrDoorClose(); void IRAM_ATTR isrDoorClose();
@ -87,14 +107,20 @@ void IRAM_ATTR isrRPM1();
void IRAM_ATTR isrRPM2(); void IRAM_ATTR isrRPM2();
/*** Static Codes ***/ /*** Static Codes ***/
byte SYNC1[] = {0x55,0x01,0x00,0x61,0x12,0x49,0x2c,0x92,0x5b,0x24,0x96,0x86,0x0b,0x65,0x96,0xd9,0x8f,0x26,0x4a}; byte SYNC1[] = {0x55, 0x01, 0x00, 0x61, 0x12, 0x49, 0x2c, 0x92, 0x5b, 0x24,
byte SYNC2[] = {0x55,0x01,0x00,0x08,0x34,0x93,0x49,0xb4,0x92,0x4d,0x20,0x26,0x1b,0x4d,0xb4,0xdb,0xad,0x76,0x93}; 0x96, 0x86, 0x0b, 0x65, 0x96, 0xd9, 0x8f, 0x26, 0x4a};
byte SYNC3[] = {0x55,0x01,0x00,0x06,0x1b,0x2c,0xbf,0x4b,0x6d,0xb6,0x4b,0x18,0x20,0x92,0x09,0x20,0xf2,0x11,0x2c}; byte SYNC2[] = {0x55, 0x01, 0x00, 0x08, 0x34, 0x93, 0x49, 0xb4, 0x92, 0x4d,
byte SYNC4[] = {0x55,0x01,0x00,0x95,0x29,0x36,0x91,0x29,0x36,0x9a,0x69,0x05,0x2f,0xbe,0xdf,0x6d,0x16,0xcb,0xe7}; 0x20, 0x26, 0x1b, 0x4d, 0xb4, 0xdb, 0xad, 0x76, 0x93};
byte* SYNC_CODE[] = {SYNC1,SYNC2,SYNC3,SYNC4}; 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,0xfc,0xa6,0x1a,0x4d,0xa6,0xda,0x8d,0x36,0xb3}; byte DOOR_CODE[] = {0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe,
0xfc, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x36, 0xb3};
byte LIGHT_CODE[] = {0x55,0x01,0x00,0x94,0x3f,0xef,0xbc,0xfb,0x7f,0xbe,0xff,0xa6,0x1a,0x4d,0xa6,0xda,0x8d,0x76,0xb1}; byte LIGHT_CODE[] = {0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe,
0xff, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x76, 0xb1};
#endif #endif

View File

@ -1,11 +1,6 @@
#ifndef _RATGDO_ROLLING_CODE_H #ifndef _RATGDO_ROLLING_CODE_H
#define _RATGDO_ROLLING_CODE_H #define _RATGDO_ROLLING_CODE_H
#include "BootstrapManager.h"
#include <Arduino.h>
#include <ArduinoJson.h>
#include <LittleFS.h>
extern "C" { extern "C" {
#include "secplus.h" #include "secplus.h"
} }