From 78c2a99d30ea7260dc1b1b473514167be00d8fe8 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 7 Dec 2018 21:39:18 -0700 Subject: [PATCH] Add 10 second timeout to armed state --- firmware/firmware.ino | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/firmware/firmware.ino b/firmware/firmware.ino index d76c871..9924c8c 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -41,6 +41,7 @@ typedef struct __attribute__((packed)) cardData { #define LED_PIN_OFF !LED_PIN_ON #define DELAY_TIME 10 +#define LOCK_ARMED_TIMEOUT 1000 #define COMM_LOCK_IDLE_TIME 50 #define COMM_CARD_IDLE_TIME 1000 #define LED_ARMED_BLINK_TIME 50 @@ -247,6 +248,10 @@ void relayOff() { digitalWrite(RELAY_PIN, RELAY_OPEN); } void processLockState() { + static uint16_t lockArmedTimeoutCount; + + if (lockState != LOCK_ARMED) lockArmedTimeoutCount = 0; + switch (lockState) { case LOCK_OFF: if (LEDState != LED_ERROR) LEDState = LED_OFF; @@ -266,6 +271,7 @@ void processLockState() if (LEDState != LED_ERROR) LEDState = LED_ARMED; relayOff(); + lockArmedTimeoutCount++; if (redButton()) { if (LOGGING) Serial.println("[INFO] Unarming interlock."); @@ -274,6 +280,11 @@ void processLockState() if (LOGGING) Serial.println("[INFO] On button pressed."); lockState = LOCK_ON_PRESSED; } + + if (lockArmedTimeoutCount > LOCK_ARMED_TIMEOUT) { + if (LOGGING) Serial.println("[INFO] Arming timed out, disarming."); + lockState = LOCK_OFF; + } break; case LOCK_ON_PRESSED: if (redButton()) {