Change LED patterns to be more intuitive

This commit is contained in:
Tanner Collin 2018-12-01 17:08:12 -07:00
parent ffcfb54aa9
commit 31a0112f9b

View File

@ -43,7 +43,8 @@ typedef struct __attribute__((packed)) cardData {
#define DELAY_TIME 10 #define DELAY_TIME 10
#define COMM_LOCK_IDLE_TIME 50 #define COMM_LOCK_IDLE_TIME 50
#define COMM_CARD_IDLE_TIME 1000 #define COMM_CARD_IDLE_TIME 1000
#define LED_DELAYED_IDLE_TIME 50 #define LED_ARMED_BLINK_TIME 50
#define LED_ERROR_BLINK_TIME 50
#define EEPROM_SIZE 4095 #define EEPROM_SIZE 4095
@ -59,8 +60,7 @@ enum LEDStates
LED_OFF, LED_OFF,
LED_ARMED, LED_ARMED,
LED_ON, LED_ON,
LED_DELAYED, LED_ERROR,
LED_DELAYED_IDLE,
} LEDState = LED_OFF; } LEDState = LED_OFF;
enum lockStates enum lockStates
@ -199,7 +199,7 @@ void checkCard()
} }
} else { } else {
if (LOGGING) Serial.println("[INFO] Card not authorized on machine."); if (LOGGING) Serial.println("[INFO] Card not authorized on machine.");
LEDState = LED_DELAYED; LEDState = LED_ERROR;
} }
} }
} }
@ -249,7 +249,7 @@ void processLockState()
{ {
switch (lockState) { switch (lockState) {
case LOCK_OFF: case LOCK_OFF:
if (LEDState < LED_DELAYED) LEDState = LED_OFF; if (LEDState != LED_ERROR) LEDState = LED_OFF;
relayOff(); relayOff();
break; break;
@ -259,11 +259,11 @@ void processLockState()
lockState = LOCK_ARMED; lockState = LOCK_ARMED;
} else { } else {
lockState = LOCK_OFF; lockState = LOCK_OFF;
LEDState = LED_DELAYED; LEDState = LED_ERROR;
} }
break; break;
case LOCK_ARMED: case LOCK_ARMED:
if (LEDState < LED_DELAYED) LEDState = LED_ARMED; if (LEDState != LED_ERROR) LEDState = LED_ARMED;
relayOff(); relayOff();
@ -285,7 +285,7 @@ void processLockState()
} }
break; break;
case LOCK_ON: case LOCK_ON:
if (LEDState < LED_DELAYED) LEDState = LED_ON; if (LEDState != LED_ERROR) LEDState = LED_ON;
relayOn(); relayOn();
@ -308,44 +308,50 @@ void redLEDOff() { digitalWrite(RED_LED_PIN, LED_PIN_OFF); }
void processLEDState() void processLEDState()
{ {
static uint16_t LEDDelayedIdleCount = 0; static uint16_t LEDArmedBlinkCount, LEDErrorBlinkCount;
if (LEDState != LED_ARMED) LEDArmedBlinkCount = 0;
if (LEDState != LED_ERROR) LEDErrorBlinkCount = 0;
switch (LEDState) { switch (LEDState) {
case LED_OFF: case LED_OFF:
greenLEDOff();
redLEDOff();
break;
case LED_ARMED:
greenLEDOn();
redLEDOff();
break;
case LED_ON:
greenLEDOff(); greenLEDOff();
redLEDOn(); redLEDOn();
break; break;
case LED_DELAYED: case LED_ARMED:
LEDDelayedIdleCount = 0; LEDArmedBlinkCount++;
LEDState = LED_DELAYED_IDLE; if (LEDArmedBlinkCount < LED_ARMED_BLINK_TIME) {
break; greenLEDOn();
case LED_DELAYED_IDLE: redLEDOn();
LEDDelayedIdleCount++; } else if (LEDArmedBlinkCount < LED_ARMED_BLINK_TIME * 2) {
if (LEDDelayedIdleCount < LED_DELAYED_IDLE_TIME) {
greenLEDOff(); greenLEDOff();
redLEDOn(); redLEDOn();
} else if (LEDDelayedIdleCount < LED_DELAYED_IDLE_TIME * 2) { } else {
LEDArmedBlinkCount = 0;
}
break;
case LED_ON:
greenLEDOn();
redLEDOn();
break;
case LED_ERROR:
LEDErrorBlinkCount++;
if (LEDErrorBlinkCount < LED_ERROR_BLINK_TIME) {
greenLEDOff(); greenLEDOff();
redLEDOff(); redLEDOff();
} else if (LEDErrorBlinkCount < LED_ERROR_BLINK_TIME * 2) {
greenLEDOff();
redLEDOn();
} else { } else {
LEDState = LED_OFF; LEDState = LED_OFF;
} }
break; break;
default: default:
if (LOGGING) Serial.println("[ERROR] Invalid lock state."); if (LOGGING) Serial.println("[ERROR] Invalid LED state.");
LEDState = LED_OFF; LEDState = LED_OFF;
break; break;
} }
@ -463,8 +469,7 @@ void getCards()
void processCommState() void processCommState()
{ {
static uint16_t commLockIdleCount = 0; static uint16_t commLockIdleCount, commCardIdleCount;
static uint16_t commCardIdleCount = 0;
switch (commState) { switch (commState) {
case COMM_INIT: case COMM_INIT:
@ -490,8 +495,6 @@ void processCommState()
commLockIdleCount = 0; commLockIdleCount = 0;
commState = COMM_IDLE; commState = COMM_IDLE;
Serial.printf("******free heap size: %u\n", ESP.getFreeHeap());
} }
break; break;
case COMM_CARD: case COMM_CARD: