fix
This commit is contained in:
parent
0eb1d11cfb
commit
6d45245ede
|
@ -17,25 +17,26 @@
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ratgdo {
|
namespace ratgdo {
|
||||||
|
|
||||||
static const char *const TAG = "ratgdo";
|
static const char* const TAG = "ratgdo";
|
||||||
/*** Static Codes ***/
|
/*** Static Codes ***/
|
||||||
static const byte SYNC1[] = {0x55, 0x01, 0x00, 0x61, 0x12, 0x49, 0x2c, 0x92, 0x5b, 0x24,
|
static const byte SYNC1[] = { 0x55, 0x01, 0x00, 0x61, 0x12, 0x49, 0x2c, 0x92, 0x5b, 0x24,
|
||||||
0x96, 0x86, 0x0b, 0x65, 0x96, 0xd9, 0x8f, 0x26, 0x4a};
|
0x96, 0x86, 0x0b, 0x65, 0x96, 0xd9, 0x8f, 0x26, 0x4a };
|
||||||
static const byte SYNC2[] = {0x55, 0x01, 0x00, 0x08, 0x34, 0x93, 0x49, 0xb4, 0x92, 0x4d,
|
static const byte SYNC2[] = { 0x55, 0x01, 0x00, 0x08, 0x34, 0x93, 0x49, 0xb4, 0x92, 0x4d,
|
||||||
0x20, 0x26, 0x1b, 0x4d, 0xb4, 0xdb, 0xad, 0x76, 0x93};
|
0x20, 0x26, 0x1b, 0x4d, 0xb4, 0xdb, 0xad, 0x76, 0x93 };
|
||||||
static const byte SYNC3[] = {0x55, 0x01, 0x00, 0x06, 0x1b, 0x2c, 0xbf, 0x4b, 0x6d, 0xb6,
|
static const byte SYNC3[] = { 0x55, 0x01, 0x00, 0x06, 0x1b, 0x2c, 0xbf, 0x4b, 0x6d, 0xb6,
|
||||||
0x4b, 0x18, 0x20, 0x92, 0x09, 0x20, 0xf2, 0x11, 0x2c};
|
0x4b, 0x18, 0x20, 0x92, 0x09, 0x20, 0xf2, 0x11, 0x2c };
|
||||||
static const byte SYNC4[] = {0x55, 0x01, 0x00, 0x95, 0x29, 0x36, 0x91, 0x29, 0x36, 0x9a,
|
static const byte SYNC4[] = { 0x55, 0x01, 0x00, 0x95, 0x29, 0x36, 0x91, 0x29, 0x36, 0x9a,
|
||||||
0x69, 0x05, 0x2f, 0xbe, 0xdf, 0x6d, 0x16, 0xcb, 0xe7};
|
0x69, 0x05, 0x2f, 0xbe, 0xdf, 0x6d, 0x16, 0xcb, 0xe7 };
|
||||||
static const byte *SYNC_CODE[] = {SYNC1, SYNC2, SYNC3, SYNC4};
|
static const byte* SYNC_CODE[] = { SYNC1, SYNC2, SYNC3, SYNC4 };
|
||||||
|
|
||||||
static const byte DOOR_CODE[] = {0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe,
|
static const byte DOOR_CODE[] = { 0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe,
|
||||||
0xfc, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x36, 0xb3};
|
0xfc, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x36, 0xb3 };
|
||||||
|
|
||||||
static const byte LIGHT_CODE[] = {0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe,
|
static const byte LIGHT_CODE[] = { 0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe,
|
||||||
0xff, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x76, 0xb1};
|
0xff, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x76, 0xb1 };
|
||||||
|
|
||||||
void RATGDOComponent::setup() {
|
void RATGDOComponent::setup()
|
||||||
|
{
|
||||||
this->pref_ = global_preferences->make_preference<int>(734874333U);
|
this->pref_ = global_preferences->make_preference<int>(734874333U);
|
||||||
if (!this->pref_.load(&this->rollingCodeCounter)) {
|
if (!this->pref_.load(&this->rollingCodeCounter)) {
|
||||||
this->rollingCodeCounter = 0;
|
this->rollingCodeCounter = 0;
|
||||||
|
@ -68,21 +69,24 @@ void RATGDOComponent::setup() {
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGD(TAG, "Rolling codes are disabled.");
|
ESP_LOGD(TAG, "Rolling codes are disabled.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::loop() {
|
void RATGDOComponent::loop()
|
||||||
|
{
|
||||||
obstructionLoop();
|
obstructionLoop();
|
||||||
doorStateLoop();
|
doorStateLoop();
|
||||||
dryContactLoop();
|
dryContactLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::set_rolling_codes(bool useRollingCodes) {
|
void RATGDOComponent::set_rolling_codes(bool useRollingCodes)
|
||||||
|
{
|
||||||
this->useRollingCodes_ = useRollingCodes;
|
this->useRollingCodes_ = useRollingCodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************** DETECTING THE DOOR STATE
|
/*************************** DETECTING THE DOOR STATE
|
||||||
* ***************************/
|
* ***************************/
|
||||||
void RATGDOComponent::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;
|
||||||
|
@ -150,11 +154,12 @@ void RATGDOComponent::doorStateLoop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
lastDoorPositionCounter = doorPositionCounter;
|
lastDoorPositionCounter = doorPositionCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************** DRY CONTACT CONTROL OF LIGHT & DOOR
|
/*************************** DRY CONTACT CONTROL OF LIGHT & DOOR
|
||||||
* ***************************/
|
* ***************************/
|
||||||
void IRAM_ATTR RATGDOComponent::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;
|
||||||
|
@ -168,8 +173,7 @@ void IRAM_ATTR RATGDOComponent::isrDebounce(const char *type) {
|
||||||
if (digitalRead(TRIGGER_OPEN) == LOW) {
|
if (digitalRead(TRIGGER_OPEN) == LOW) {
|
||||||
// save the time of the falling edge
|
// save the time of the falling edge
|
||||||
lastOpenDoorTime = currentMillis;
|
lastOpenDoorTime = currentMillis;
|
||||||
} else if (currentMillis - lastOpenDoorTime > 500 &&
|
} else if (currentMillis - lastOpenDoorTime > 500 && currentMillis - lastOpenDoorTime < 10000) {
|
||||||
currentMillis - lastOpenDoorTime < 10000) {
|
|
||||||
// now see if the rising edge was between 500ms and 10 seconds after the
|
// now see if the rising edge was between 500ms and 10 seconds after the
|
||||||
// falling edge
|
// falling edge
|
||||||
this->dryContactDoorOpen = true;
|
this->dryContactDoorOpen = true;
|
||||||
|
@ -180,8 +184,7 @@ void IRAM_ATTR RATGDOComponent::isrDebounce(const char *type) {
|
||||||
if (digitalRead(TRIGGER_CLOSE) == LOW) {
|
if (digitalRead(TRIGGER_CLOSE) == LOW) {
|
||||||
// save the time of the falling edge
|
// save the time of the falling edge
|
||||||
lastCloseDoorTime = currentMillis;
|
lastCloseDoorTime = currentMillis;
|
||||||
} else if (currentMillis - lastCloseDoorTime > 500 &&
|
} else if (currentMillis - lastCloseDoorTime > 500 && currentMillis - lastCloseDoorTime < 10000) {
|
||||||
currentMillis - lastCloseDoorTime < 10000) {
|
|
||||||
// now see if the rising edge was between 500ms and 10 seconds after the
|
// now see if the rising edge was between 500ms and 10 seconds after the
|
||||||
// falling edge
|
// falling edge
|
||||||
this->dryContactDoorClose = true;
|
this->dryContactDoorClose = true;
|
||||||
|
@ -192,33 +195,33 @@ void IRAM_ATTR RATGDOComponent::isrDebounce(const char *type) {
|
||||||
if (digitalRead(TRIGGER_LIGHT) == LOW) {
|
if (digitalRead(TRIGGER_LIGHT) == LOW) {
|
||||||
// save the time of the falling edge
|
// save the time of the falling edge
|
||||||
lastToggleLightTime = currentMillis;
|
lastToggleLightTime = currentMillis;
|
||||||
} else if (currentMillis - lastToggleLightTime > 500 &&
|
} else if (currentMillis - lastToggleLightTime > 500 && currentMillis - lastToggleLightTime < 10000) {
|
||||||
currentMillis - lastToggleLightTime < 10000) {
|
|
||||||
// now see if the rising edge was between 500ms and 10 seconds after the
|
// now see if the rising edge was between 500ms and 10 seconds after the
|
||||||
// falling edge
|
// falling edge
|
||||||
this->dryContactToggleLight = true;
|
this->dryContactToggleLight = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR RATGDOComponent::isrDoorOpen() { isrDebounce("openDoor"); }
|
void IRAM_ATTR RATGDOComponent::isrDoorOpen() { isrDebounce("openDoor"); }
|
||||||
|
|
||||||
void IRAM_ATTR RATGDOComponent::isrDoorClose() { isrDebounce("closeDoor"); }
|
void IRAM_ATTR RATGDOComponent::isrDoorClose() { isrDebounce("closeDoor"); }
|
||||||
|
|
||||||
void IRAM_ATTR RATGDOComponent::isrLight() { isrDebounce("toggleLight"); }
|
void IRAM_ATTR RATGDOComponent::isrLight() { isrDebounce("toggleLight"); }
|
||||||
|
|
||||||
// Fire on RISING edge of RPM1
|
// Fire on RISING edge of RPM1
|
||||||
void IRAM_ATTR RATGDOComponent::isrRPM1() { this->rpm1Pulsed = true; }
|
void IRAM_ATTR RATGDOComponent::isrRPM1() { this->rpm1Pulsed = true; }
|
||||||
|
|
||||||
// Fire on RISING edge of RPM2
|
// Fire on RISING edge of RPM2
|
||||||
// When RPM1 HIGH on RPM2 rising edge, door closing:
|
// When RPM1 HIGH on RPM2 rising edge, door closing:
|
||||||
// RPM1: __|--|___
|
// RPM1: __|--|___
|
||||||
// RPM2: ___|--|__
|
// RPM2: ___|--|__
|
||||||
|
|
||||||
// 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 RATGDOComponent::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
|
||||||
|
@ -249,10 +252,11 @@ void IRAM_ATTR RATGDOComponent::isrRPM2() {
|
||||||
} else {
|
} else {
|
||||||
this->doorPositionCounter++;
|
this->doorPositionCounter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle changes to the dry contact state
|
// handle changes to the dry contact state
|
||||||
void RATGDOComponent::dryContactLoop() {
|
void RATGDOComponent::dryContactLoop()
|
||||||
|
{
|
||||||
if (this->dryContactDoorOpen) {
|
if (this->dryContactDoorOpen) {
|
||||||
ESP_LOGD(TAG, "Dry Contact: open the door");
|
ESP_LOGD(TAG, "Dry Contact: open the door");
|
||||||
this->dryContactDoorOpen = false;
|
this->dryContactDoorOpen = false;
|
||||||
|
@ -270,18 +274,20 @@ void RATGDOComponent::dryContactLoop() {
|
||||||
this->dryContactToggleLight = false;
|
this->dryContactToggleLight = false;
|
||||||
toggleLight();
|
toggleLight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************** OBSTRUCTION DETECTION ***************************/
|
/*************************** OBSTRUCTION DETECTION ***************************/
|
||||||
void IRAM_ATTR RATGDOComponent::isrObstruction() {
|
void IRAM_ATTR RATGDOComponent::isrObstruction()
|
||||||
|
{
|
||||||
if (digitalRead(INPUT_OBST)) {
|
if (digitalRead(INPUT_OBST)) {
|
||||||
this->lastObstructionHigh = millis();
|
this->lastObstructionHigh = millis();
|
||||||
} else {
|
} else {
|
||||||
this->obstructionLowCount++;
|
this->obstructionLowCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::obstructionLoop() {
|
void RATGDOComponent::obstructionLoop()
|
||||||
|
{
|
||||||
long currentMillis = millis();
|
long currentMillis = millis();
|
||||||
static unsigned long lastMillis = 0;
|
static unsigned long lastMillis = 0;
|
||||||
|
|
||||||
|
@ -313,9 +319,10 @@ void RATGDOComponent::obstructionLoop() {
|
||||||
lastMillis = currentMillis;
|
lastMillis = currentMillis;
|
||||||
this->obstructionLowCount = 0;
|
this->obstructionLowCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::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
|
||||||
|
@ -325,18 +332,19 @@ void RATGDOComponent::obstructionDetected() {
|
||||||
ESP_LOGD(TAG, "Obstruction Detected");
|
ESP_LOGD(TAG, "Obstruction Detected");
|
||||||
}
|
}
|
||||||
lastInterruptTime = interruptTime;
|
lastInterruptTime = interruptTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::obstructionCleared() {
|
void RATGDOComponent::obstructionCleared()
|
||||||
|
{
|
||||||
if (this->doorIsObstructed) {
|
if (this->doorIsObstructed) {
|
||||||
this->doorIsObstructed = false;
|
this->doorIsObstructed = false;
|
||||||
digitalWrite(STATUS_OBST, LOW);
|
digitalWrite(STATUS_OBST, LOW);
|
||||||
ESP_LOGD(TAG, "Obstruction Cleared");
|
ESP_LOGD(TAG, "Obstruction Cleared");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************* DOOR COMMUNICATION *************************/
|
/************************* DOOR COMMUNICATION *************************/
|
||||||
/*
|
/*
|
||||||
* Transmit a message to the door opener over uart1
|
* Transmit a message to the door opener over uart1
|
||||||
* The TX1 pin is controlling a transistor, so the logic is inverted
|
* The TX1 pin is controlling a transistor, so the logic is inverted
|
||||||
* A HIGH state on TX1 will pull the 12v line LOW
|
* A HIGH state on TX1 will pull the 12v line LOW
|
||||||
|
@ -344,7 +352,8 @@ void RATGDOComponent::obstructionCleared() {
|
||||||
* 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 RATGDOComponent::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);
|
||||||
|
@ -352,9 +361,10 @@ void RATGDOComponent::transmit(byte *payload, unsigned int length) {
|
||||||
|
|
||||||
delayMicroseconds(1260); // "LOW" pulse duration before the message start
|
delayMicroseconds(1260); // "LOW" pulse duration before the message start
|
||||||
this->swSerial.write(payload, length);
|
this->swSerial.write(payload, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::sync() {
|
void RATGDOComponent::sync()
|
||||||
|
{
|
||||||
if (!this->useRollingCodes_)
|
if (!this->useRollingCodes_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -383,9 +393,10 @@ void RATGDOComponent::sync() {
|
||||||
delay(45);
|
delay(45);
|
||||||
|
|
||||||
this->pref_.save(&this->rollingCodeCounter);
|
this->pref_.save(&this->rollingCodeCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::openDoor() {
|
void RATGDOComponent::openDoor()
|
||||||
|
{
|
||||||
if (this->doorState == "open" || this->doorState == "opening") {
|
if (this->doorState == "open" || this->doorState == "opening") {
|
||||||
ESP_LOGD(TAG, "The door is already %s", doorState);
|
ESP_LOGD(TAG, "The door is already %s", doorState);
|
||||||
return;
|
return;
|
||||||
|
@ -415,9 +426,10 @@ void RATGDOComponent::openDoor() {
|
||||||
ESP_LOGD(TAG, "door_code")
|
ESP_LOGD(TAG, "door_code")
|
||||||
transmit(DOOR_CODE, CODE_LENGTH);
|
transmit(DOOR_CODE, CODE_LENGTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::closeDoor() {
|
void RATGDOComponent::closeDoor()
|
||||||
|
{
|
||||||
if (this->doorState == "closed" || this->doorState == "closing") {
|
if (this->doorState == "closed" || this->doorState == "closing") {
|
||||||
ESP_LOGD(TAG, "The door is already %s", this->doorState);
|
ESP_LOGD(TAG, "The door is already %s", this->doorState);
|
||||||
return;
|
return;
|
||||||
|
@ -447,9 +459,10 @@ void RATGDOComponent::closeDoor() {
|
||||||
ESP_LOGD(TAG, "door_code")
|
ESP_LOGD(TAG, "door_code")
|
||||||
transmit(DOOR_CODE, CODE_LENGTH);
|
transmit(DOOR_CODE, CODE_LENGTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::toggleLight() {
|
void RATGDOComponent::toggleLight()
|
||||||
|
{
|
||||||
if (this->useRollingCodes) {
|
if (this->useRollingCodes) {
|
||||||
getRollingCode("light");
|
getRollingCode("light");
|
||||||
transmit(this->rollingCode, CODE_LENGTH);
|
transmit(this->rollingCode, CODE_LENGTH);
|
||||||
|
@ -464,44 +477,44 @@ void RATGDOComponent::toggleLight() {
|
||||||
ESP_LOGD(TAG, "light_code")
|
ESP_LOGD(TAG, "light_code")
|
||||||
transmit(LIGHT_CODE, CODE_LENGTH);
|
transmit(LIGHT_CODE, CODE_LENGTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RATGDOComponent::getRollingCode(const char* command)
|
||||||
void RATGDOComponent::getRollingCode(const char *command){
|
{
|
||||||
|
|
||||||
uint64_t id = 0x539;
|
uint64_t id = 0x539;
|
||||||
uint64_t fixed = 0;
|
uint64_t fixed = 0;
|
||||||
uint32_t data = 0;
|
uint32_t data = 0;
|
||||||
|
|
||||||
if(strcmp(command,"reboot1") == 0){
|
if (strcmp(command, "reboot1") == 0) {
|
||||||
fixed = 0x400000000;
|
fixed = 0x400000000;
|
||||||
data = 0x0000618b;
|
data = 0x0000618b;
|
||||||
}else if(strcmp(command,"reboot2") == 0){
|
} else if (strcmp(command, "reboot2") == 0) {
|
||||||
fixed = 0;
|
fixed = 0;
|
||||||
data = 0x01009080;
|
data = 0x01009080;
|
||||||
}else if(strcmp(command,"reboot3") == 0){
|
} else if (strcmp(command, "reboot3") == 0) {
|
||||||
fixed = 0;
|
fixed = 0;
|
||||||
data = 0x0000b1a0;
|
data = 0x0000b1a0;
|
||||||
}else if(strcmp(command,"reboot4") == 0){
|
} else if (strcmp(command, "reboot4") == 0) {
|
||||||
fixed = 0;
|
fixed = 0;
|
||||||
data = 0x01009080;
|
data = 0x01009080;
|
||||||
}else if(strcmp(command,"reboot5") == 0){
|
} else if (strcmp(command, "reboot5") == 0) {
|
||||||
fixed = 0x300000000;
|
fixed = 0x300000000;
|
||||||
data = 0x00008092;
|
data = 0x00008092;
|
||||||
}else if(strcmp(command,"reboot6") == 0){
|
} else if (strcmp(command, "reboot6") == 0) {
|
||||||
fixed = 0x300000000;
|
fixed = 0x300000000;
|
||||||
data = 0x00008092;
|
data = 0x00008092;
|
||||||
}else if(strcmp(command,"door1") == 0){
|
} else if (strcmp(command, "door1") == 0) {
|
||||||
fixed = 0x200000000;
|
fixed = 0x200000000;
|
||||||
data = 0x01018280;
|
data = 0x01018280;
|
||||||
}else if(strcmp(command,"door2") == 0){
|
} else if (strcmp(command, "door2") == 0) {
|
||||||
fixed = 0x200000000;
|
fixed = 0x200000000;
|
||||||
data = 0x01009280;
|
data = 0x01009280;
|
||||||
}else if(strcmp(command,"light") == 0){
|
} else if (strcmp(command, "light") == 0) {
|
||||||
fixed = 0x200000000;
|
fixed = 0x200000000;
|
||||||
data = 0x00009281;
|
data = 0x00009281;
|
||||||
}else{
|
} else {
|
||||||
ESP_LOGD(TAG,"ERROR: Invalid command");
|
ESP_LOGD(TAG, "ERROR: Invalid command");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,18 +524,20 @@ void RATGDOComponent::getRollingCode(const char *command){
|
||||||
|
|
||||||
printRollingCode();
|
printRollingCode();
|
||||||
|
|
||||||
if(strcmp(command,"door1") != 0){ // door2 is created with same counter and should always be called after door1
|
if (strcmp(command, "door1") != 0) { // door2 is created with same counter and should always be called after door1
|
||||||
this->rollingCodeCounter = (this->rollingCodeCounter + 1) & 0xfffffff;
|
this->rollingCodeCounter = (this->rollingCodeCounter + 1) & 0xfffffff;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::printRollingCode(){
|
void RATGDOComponent::printRollingCode()
|
||||||
for(int i = 0; i < CODE_LENGTH; i++){
|
{
|
||||||
if(this->rollingCode[i] <= 0x0f) ESP_LOGD(TAG, "0");
|
for (int i = 0; i < CODE_LENGTH; i++) {
|
||||||
|
if (this->rollingCode[i] <= 0x0f)
|
||||||
|
ESP_LOGD(TAG, "0");
|
||||||
ESP_LOGD(TAG, "%x", this->rollingCode[i]);
|
ESP_LOGD(TAG, "%x", this->rollingCode[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ratgdo
|
} // namespace ratgdo
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/core/preferences.h"
|
#include "esphome/core/preferences.h"
|
||||||
|
|
||||||
|
|
||||||
#include "SoftwareSerial.h"
|
#include "SoftwareSerial.h"
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "secplus.h"
|
#include "secplus.h"
|
||||||
|
@ -33,7 +32,6 @@ static const uint8_t D8 = 15;
|
||||||
static const uint8_t D9 = 3;
|
static const uint8_t D9 = 3;
|
||||||
static const uint8_t D10 = 1;
|
static const uint8_t D10 = 1;
|
||||||
|
|
||||||
|
|
||||||
#define CODE_LENGTH 19 // the length of each command sent to the door.
|
#define CODE_LENGTH 19 // the length of each command sent to the door.
|
||||||
/********************************** PIN DEFINITIONS
|
/********************************** PIN DEFINITIONS
|
||||||
* *****************************************/
|
* *****************************************/
|
||||||
|
@ -57,7 +55,7 @@ static const uint8_t D10 = 1;
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ratgdo {
|
namespace ratgdo {
|
||||||
|
|
||||||
class RATGDOComponent : public Component {
|
class RATGDOComponent : public Component {
|
||||||
public:
|
public:
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
@ -66,13 +64,11 @@ class RATGDOComponent : public Component {
|
||||||
unsigned int rollingCodeCounter;
|
unsigned int rollingCodeCounter;
|
||||||
SoftwareSerial swSerial;
|
SoftwareSerial swSerial;
|
||||||
byte rollingCode[CODE_LENGTH];
|
byte rollingCode[CODE_LENGTH];
|
||||||
String doorState =
|
String doorState = "unknown"; // will be
|
||||||
"unknown"; // will be
|
|
||||||
// [online|offline|opening|open|closing|closed|obstructed|clear|reed_open|reed_closed]
|
// [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 =
|
unsigned long lastObstructionHigh = 0; // count time between high pulses from the obst ISR
|
||||||
0; // count time between high pulses from the obst ISR
|
|
||||||
|
|
||||||
bool useRollingCodes = true; // use rolling codes or not
|
bool useRollingCodes = true; // use rolling codes or not
|
||||||
bool doorIsObstructed = false;
|
bool doorIsObstructed = false;
|
||||||
|
@ -80,14 +76,13 @@ class RATGDOComponent : public Component {
|
||||||
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 =
|
bool rpm1Pulsed = false; // did rpm1 get a pulse or not - eliminates an issue when the
|
||||||
false; // did rpm1 get a pulse or not - eliminates an issue when the sensor
|
// sensor is parked on a high pulse which fires rpm2 isr
|
||||||
// is parked on a high pulse which fires rpm2 isr
|
|
||||||
|
|
||||||
/********************************** FUNCTION DECLARATION
|
/********************************** FUNCTION DECLARATION
|
||||||
* *****************************************/
|
* *****************************************/
|
||||||
void set_rolling_codes(bool useRollingCodes);
|
void set_rolling_codes(bool useRollingCodes);
|
||||||
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();
|
||||||
|
@ -104,7 +99,7 @@ class RATGDOComponent : public Component {
|
||||||
|
|
||||||
/********************************** 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();
|
||||||
void IRAM_ATTR isrLight();
|
void IRAM_ATTR isrLight();
|
||||||
|
@ -112,14 +107,11 @@ class RATGDOComponent : public Component {
|
||||||
void IRAM_ATTR isrRPM1();
|
void IRAM_ATTR isrRPM1();
|
||||||
void IRAM_ATTR isrRPM2();
|
void IRAM_ATTR isrRPM2();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ESPPreferenceObject pref_;
|
ESPPreferenceObject pref_;
|
||||||
bool useRollingCodes_;
|
bool useRollingCodes_;
|
||||||
|
|
||||||
|
}; // RATGDOComponent
|
||||||
}; // RATGDOComponent
|
|
||||||
|
|
||||||
} // namespace ratgdo
|
} // namespace ratgdo
|
||||||
} // namespace esphome
|
} // namespace esphome
|
Loading…
Reference in New Issue