diff --git a/firmware/core/peripheral.cpp b/firmware/core/peripheral.cpp index 12ac46b..5147d69 100644 --- a/firmware/core/peripheral.cpp +++ b/firmware/core/peripheral.cpp @@ -9,6 +9,7 @@ digitalWrite(lockMagnetPin, HIGH);//lock door digitalWrite(lockDetectPin, HIGH);//enable pull-up + delay(400); lastDectVal = digitalRead(lockDetectPin); lastDectTime = millis(); } @@ -17,6 +18,7 @@ { if (state == DoorLocked) { digitalWrite(lockMagnetPin, LOW); + preparedTimer = millis(); state = DoorPreparedOpen; Serial.println("DoorPreparedOpen"); } @@ -46,7 +48,7 @@ } break; case DoorPreparedOpen: - if (detect()) { + if (millis() - preparedTimer > DoorOpenTimeOut) { digitalWrite(lockMagnetPin, HIGH); state = DoorOpened; Serial.println("DoorOpened"); diff --git a/firmware/core/peripheral.h b/firmware/core/peripheral.h index 30f6ad4..18d9500 100644 --- a/firmware/core/peripheral.h +++ b/firmware/core/peripheral.h @@ -9,6 +9,7 @@ #define DetectorSwitchDelay 80 #define LongPressThreshold 3000 +#define DoorOpenTimeOut 5000 class Door { @@ -17,6 +18,7 @@ DoorLocked, DoorPreparedOpen, DoorOpened }; DoorStateDef state; + unsigned long preparedTimer; unsigned long lastDectTime; unsigned char lastDectVal; bool detect(); //return true if lock detected door opened