better code structure
This commit is contained in:
parent
a8ff7b905f
commit
2ab04fadd8
7 changed files with 49 additions and 34 deletions
|
@ -13,6 +13,7 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
struct User {
|
||||
String cardId;
|
||||
String desc;
|
||||
|
@ -42,4 +43,6 @@ private:
|
|||
int aclSize;
|
||||
};
|
||||
|
||||
extern ACL acl;
|
||||
|
||||
#endif
|
||||
|
|
10
include/local_acl.h
Normal file
10
include/local_acl.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef LOCAL_ACL_H
|
||||
#define LOCAL_ACL_H
|
||||
|
||||
#include "acl.h"
|
||||
#include "settings.h"
|
||||
#include "hardware.h"
|
||||
|
||||
extern void localAcl(String cardID);
|
||||
|
||||
#endif
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
#ifdef LOCAL_ACL
|
||||
#include "acl.h"
|
||||
ACL acl = {
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef TTL_READER
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "secrets.h"
|
||||
#include "hardware.h"
|
||||
#include "buzzer_ctl.h"
|
||||
#include "local_acl.h"
|
||||
|
||||
void tinance2SyncTaskFunction(void *parameter);
|
||||
void tinance2authrequest(String fullCardID, String cardID);
|
||||
|
|
|
@ -121,4 +121,6 @@ void ACL::saveToEEPROM() {
|
|||
acl_preferences.putString((key + "_desc").c_str(), acl[i].desc.c_str());
|
||||
}
|
||||
acl_preferences.end();
|
||||
}
|
||||
}
|
||||
|
||||
ACL acl = {};
|
31
src/local_acl.cpp
Normal file
31
src/local_acl.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "local_acl.h"
|
||||
|
||||
void localAcl(String cardID) {
|
||||
if (acl.validateAccess(String(cardID))) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("LOCAL_AUTH: Access granted!");
|
||||
#endif
|
||||
// Perform actions for authorized access
|
||||
if (settings.getDoorMode() == "LATCH") {
|
||||
if (!settings.getDoorDisabled()) {
|
||||
unlockDoor(false);
|
||||
delay(RELAY_DELAY);
|
||||
lockDoor(false);
|
||||
}
|
||||
}
|
||||
if (settings.getDoorMode() == "TOGGLE") {
|
||||
if (!settings.getDoorDisabled()) {
|
||||
toggleDoor();
|
||||
delay(RELAY_DELAY);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("LOCAL_AUTH: Access denied!");
|
||||
#endif
|
||||
// Perform actions for denied access
|
||||
#ifdef BUZZER
|
||||
denied_beep();
|
||||
#endif
|
||||
}
|
||||
}
|
32
src/main.cpp
32
src/main.cpp
|
@ -8,37 +8,7 @@ const unsigned long wifiRebootTimeout = 20000; // Delay before reboot after disc
|
|||
unsigned int bitCount = 0; // Variable to keep track of the bit count
|
||||
unsigned int maxReaderWaitTime = 9000; // Variable to timeout reader after too long of no data.
|
||||
|
||||
#ifdef LOCAL_ACL
|
||||
void localAcl(String cardID) {
|
||||
if (acl.validateAccess(String(cardID))) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("LOCAL_AUTH: Access granted!");
|
||||
#endif
|
||||
// Perform actions for authorized access
|
||||
if (settings.getDoorMode() == "LATCH") {
|
||||
if (!settings.getDoorDisabled()) {
|
||||
unlockDoor(false);
|
||||
delay(RELAY_DELAY);
|
||||
lockDoor(false);
|
||||
}
|
||||
}
|
||||
if (settings.getDoorMode() == "TOGGLE") {
|
||||
if (!settings.getDoorDisabled()) {
|
||||
toggleDoor();
|
||||
delay(RELAY_DELAY);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("LOCAL_AUTH: Access denied!");
|
||||
#endif
|
||||
// Perform actions for denied access
|
||||
#ifdef BUZZER
|
||||
denied_beep();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef WEB_SERVER
|
||||
|
|
Loading…
Reference in a new issue