Make card write atomic and don't arm unless LED state is off

This commit is contained in:
Tanner Collin 2018-11-30 02:09:17 -07:00
parent 2c9542a2bc
commit ffcfb54aa9

View File

@ -403,7 +403,7 @@ void postState()
if (LOGGING) Serial.println(lockPayload); if (LOGGING) Serial.println(lockPayload);
String action = deserializeLockJson(lockPayload); String action = deserializeLockJson(lockPayload);
if (action == "arm" && lockState == LOCK_OFF) { if (action == "arm" && lockState == LOCK_OFF && LEDState == LED_OFF) {
lockState = LOCK_PREARM; lockState = LOCK_PREARM;
} else if (action == "disarm") { } else if (action == "disarm") {
lockState = LOCK_OFF; lockState = LOCK_OFF;
@ -442,11 +442,13 @@ void getCards()
cardPayload += "$"; // Mark the end cardPayload += "$"; // Mark the end
if (LOGGING) Serial.println(cardPayload); if (LOGGING) Serial.println(cardPayload);
noInterrupts(); // commit() disables interrupts, but we want an atomic EEPROM buffer write
for (int i = 0; i < cardPayload.length(); i++) { for (int i = 0; i < cardPayload.length(); i++) {
if (i >= EEPROM_SIZE) break; if (i >= EEPROM_SIZE) break;
EEPROM.write(i, cardPayload.charAt(i)); EEPROM.write(i, cardPayload.charAt(i));
} }
EEPROM.commit(); EEPROM.commit();
interrupts();
if (LOGGING) Serial.println("[INFO] Finished getting card data."); if (LOGGING) Serial.println("[INFO] Finished getting card data.");
} else { } else {