diff --git a/src/ratgdo.cpp b/src/ratgdo.cpp index d7b6818..1d62f6b 100644 --- a/src/ratgdo.cpp +++ b/src/ratgdo.cpp @@ -17,7 +17,6 @@ void setup(){ pinMode(INPUT_GDO, INPUT_PULLUP); pinMode(OUTPUT_GDO, OUTPUT); - // swSerial.begin(9600, SWSERIAL_8N2, INPUT_GDO, OUTPUT_GDO, true); swSerial.begin(9600, SWSERIAL_8N1, INPUT_GDO, OUTPUT_GDO, true); Serial.begin(115200); // must remain at 115200 for improv @@ -85,7 +84,7 @@ void setup(){ readCounterFromFlash(); Serial.println("Syncing rolling code counter after reboot..."); - sync(); // if rolling codes are being used (rolling code counter > 0), send reboot/sync to the opener on startup + sync(); // send reboot/sync to the opener on startup delay(500); } @@ -280,19 +279,21 @@ void statusUpdateLoop(){ static uint8_t previousDoorState = 0; static uint8_t previousLightState = 2; static uint8_t previousLockState = 2; - static uint8_t previousMotionState = 0; static uint8_t previousObstructionState = 2; if(doorState != previousDoorState) sendDoorStatus(); if(lightState != previousLightState) sendLightStatus(); if(lockState != previousLockState) sendLockStatus(); - if(motionState != previousMotionState) sendMotionStatus(); if(obstructionState != previousObstructionState) sendObstructionStatus(); + if(motionState == 1){ + sendMotionStatus(); + motionState = 0; + } + previousDoorState = doorState; previousLightState = lightState; previousLockState = lockState; - previousMotionState = motionState; previousObstructionState = obstructionState; } @@ -333,6 +334,8 @@ void sendMotionStatus(){ if(isConfigFileOk){ bootstrapManager.publish(motionStatusTopic.c_str(), motionStates[motionState].c_str(), true); } + + motionState = 0; // reset motion state } void sendObstructionStatus(){ diff --git a/src/ratgdo.h b/src/ratgdo.h index 7e9ee08..d0d3b85 100644 --- a/src/ratgdo.h +++ b/src/ratgdo.h @@ -64,7 +64,7 @@ String lockStates[3] = {"unlocked","locked","unknown"}; String motionStatusTopic = ""; // will be mqttTopicPrefix/deviceName/status/motion uint8_t motionState = 0; -String motionStates[3] = {"clear","detected"}; +String motionStates[2] = {"clear","detected"}; String obstructionStatusTopic = ""; // will be mqttTopicPrefix/deviceName/status/obstruction uint8_t obstructionState = 2; diff --git a/src/rolling_code.cpp b/src/rolling_code.cpp index f851b85..86fdfc5 100644 --- a/src/rolling_code.cpp +++ b/src/rolling_code.cpp @@ -48,44 +48,18 @@ void readRollingCode(byte rxRollingCode[CODE_LENGTH], uint8_t &door, uint8_t &li cmd = ((fixed >> 24) & 0xf00) | (data & 0xff); - // static uint32_t cmdSequence; - - // shift cmd onto cmdSequence - // cmdSequence <<= 8; - // cmdSequence |= cmd; - - // truncate to 3 bytes - // cmdSequence &= 0x00FFFFFF; - nibble = (data >> 8) & 0xf; byte1 = (data >> 16) & 0xff; byte2 = (data >> 24) & 0xff; printRollingCode(rxRollingCode); - // Serial.print(" cmd: "); - // Serial.print(cmd,HEX); - // Serial.print(" rolling: "); - // Serial.print(rolling,HEX); - // Serial.print(" fixed: "); - // Serial.print(fixed,HEX); - // Serial.print(" data: "); - // Serial.print(data,HEX); - - // The sequence of messages are different depending on the length of the obstruction - // short obstruction sequence: 84, 85, 81(clr) -> 84, 85, 81(clr) - // long obstruction sequence: 84, 85, 81(clr), A1, 84, 85, 81(obs) -> 84, 85, 81(obs), A1, 84, 85, 81(clr) - // if(cmd == 0x84 && (cmdSequence & 0xFFFF) != 0xA184){ - // Serial.println("toggle"); - // obstruction ^= 1; - // }else if(cmd == 0x81 && (cmdSequence & 0xFFFFFF) == 0x848581){ - // // do nothing - // }else + if(cmd == 0x81){ door = nibble; light = (byte2 >> 1) & 1; lock = byte2 & 1; motion = 0; // when the status message is read, reset motion state to 0|clear - // obstruction = (byte1 >> 6) & 1; + // obstruction = (byte1 >> 6) & 1; // unreliable due to the time it takes to register an obstruction Serial.print(" | STATUS:"); Serial.print(" door:"); @@ -104,7 +78,7 @@ void readRollingCode(byte rxRollingCode[CODE_LENGTH], uint8_t &door, uint8_t &li Serial.print(light); }else if(cmd == 0x84){ }else if(cmd == 0x285){ - motion ^= 1; // toggle bit + motion = 1; // toggle bit Serial.print(" | MOTION:"); Serial.print(motion); }