Change LED patterns to be more intuitive
This commit is contained in:
parent
ffcfb54aa9
commit
31a0112f9b
|
@ -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();
|
greenLEDOff();
|
||||||
redLEDOff();
|
redLEDOn();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case LED_ARMED:
|
case LED_ARMED:
|
||||||
greenLEDOn();
|
LEDArmedBlinkCount++;
|
||||||
redLEDOff();
|
|
||||||
|
|
||||||
|
if (LEDArmedBlinkCount < LED_ARMED_BLINK_TIME) {
|
||||||
|
greenLEDOn();
|
||||||
|
redLEDOn();
|
||||||
|
} else if (LEDArmedBlinkCount < LED_ARMED_BLINK_TIME * 2) {
|
||||||
|
greenLEDOff();
|
||||||
|
redLEDOn();
|
||||||
|
} else {
|
||||||
|
LEDArmedBlinkCount = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case LED_ON:
|
case LED_ON:
|
||||||
greenLEDOff();
|
greenLEDOn();
|
||||||
redLEDOn();
|
redLEDOn();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case LED_DELAYED:
|
case LED_ERROR:
|
||||||
LEDDelayedIdleCount = 0;
|
LEDErrorBlinkCount++;
|
||||||
|
|
||||||
LEDState = LED_DELAYED_IDLE;
|
if (LEDErrorBlinkCount < LED_ERROR_BLINK_TIME) {
|
||||||
break;
|
|
||||||
case LED_DELAYED_IDLE:
|
|
||||||
LEDDelayedIdleCount++;
|
|
||||||
|
|
||||||
if (LEDDelayedIdleCount < LED_DELAYED_IDLE_TIME) {
|
|
||||||
greenLEDOff();
|
|
||||||
redLEDOn();
|
|
||||||
} else if (LEDDelayedIdleCount < LED_DELAYED_IDLE_TIME * 2) {
|
|
||||||
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:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user