Change LED patterns to be more intuitive

master
Tanner Collin 5 years ago
parent ffcfb54aa9
commit 31a0112f9b
  1. 61
      firmware/firmware.ino

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

Loading…
Cancel
Save