From cc5c44c8e27fbe95bc44eb7aa8ca088bb0d84fd0 Mon Sep 17 00:00:00 2001 From: Matthew Frost Date: Mon, 30 Oct 2023 19:30:30 +0100 Subject: [PATCH] basic controller --- README | 1 + include/ACL.h | 45 ------------------- include/disable.h | 14 ++++++ src/hardware.cpp | 8 ---- src/main.cpp | 107 +++++++++++++++++++++++++++++++++++++++------- 5 files changed, 106 insertions(+), 69 deletions(-) delete mode 100644 include/ACL.h create mode 100644 include/disable.h diff --git a/README b/README index 476ae7d..8c69c98 100644 --- a/README +++ b/README @@ -8,6 +8,7 @@ This project is designed to work over serial with an external computer that deci -DBOARD1 : Used to set Pins for BOARD1 config -DBOARD2 : Used to set Pins for BOARD2 config -DRELAY1 : Enable the First Relay +-RELAY1_REVERSED : If the open and closed state of relay one are reversed. -DRELAY2 : Not implemented yet diff --git a/include/ACL.h b/include/ACL.h deleted file mode 100644 index 2d875cc..0000000 --- a/include/ACL.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef ACL_H -#define ACL_H - -#include -#include -#include - -#include - -#ifdef WEB_SERVER - #ifdef WEB_SERIAL_DEBUG - #include - #endif -#endif - -struct User { - String cardId; - String desc; -}; - -class ACL { -public: - ACL(); - ACL(std::initializer_list userList); - ~ACL(); - - - void addUser(const String& cardId, const String& desc); - void updateUser(const String& cardId, const String& newCardId, const String& newdesc); - bool removeUser(const String& cardId); - bool validateAccess(const String& cardId); - int getACLSize() const; - - // Additional EEPROM functions - void saveToEEPROM(); - void loadFromEEPROM(); - - const User* getACL() const { return acl; } // Getter for acl - -private: - User* acl; - int aclSize; -}; - -#endif diff --git a/include/disable.h b/include/disable.h new file mode 100644 index 0000000..6ca764a --- /dev/null +++ b/include/disable.h @@ -0,0 +1,14 @@ +#ifndef MAIN_H + #define MAIN_H + + #include "hardware.h" + #include + #include "settings.h" + + Settings settings; + + #ifdef BUZZER + #include "buzzer_ctl.h" + #endif + +#endif \ No newline at end of file diff --git a/src/hardware.cpp b/src/hardware.cpp index 376ec28..cf3c622 100644 --- a/src/hardware.cpp +++ b/src/hardware.cpp @@ -24,10 +24,6 @@ void unlockDoor(bool silent) { #ifdef LEDCTL_PIN digitalWrite(LEDCTL_PIN,LOW); #endif - - #ifdef WEB_SERIAL_DEBUG - WebSerial.println("door unlocked"); - #endif } void lockDoor() { @@ -45,10 +41,6 @@ void lockDoor() { #ifdef LEDCTL_PIN digitalWrite(LEDCTL_PIN,HIGH); #endif - - #ifdef WEB_SERIAL_DEBUG - WebSerial.println("door locked"); - #endif } diff --git a/src/main.cpp b/src/main.cpp index 3043496..1808d6a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,14 +9,72 @@ unsigned int maxReaderWaitTime = 9000; // Variable to timeout reader after too void commandLockDoor() { // Add code to lock the door here (e.g., activate a relay, if applicable) - Serial.println("DOOR_STATUS: locked"); + ; + if (!settings.DoorDisabled()) { + lockDoor(); + } else { + Serial.println("LOG_MSG=Door Disabled Ignoring Command"); + } + Serial.println("DOOR_LOCK_STATUS=" + stateDoor() ); } void commandUnlockDoor() { // Add code to unlock the door here (e.g., deactivate a relay, if applicable) - Serial.println("DOOR_STATUS: unlocked"); + if (!settings.DoorDisabled()) { + unlockDoor(false); + delay(RELAY_DELAY); + lockDoor(); + } else { + Serial.println("LOG_MSG=Door Disabled Ignoring Command"); + } + Serial.println("DOOR_LOCK_STATUS=" + stateDoor()); } +void commandToggleDoor() { + // Add code to lock the door here (e.g., activate a relay, if applicable) + ; + if (!settings.DoorDisabled()) { + toggleDoor(); + delay(RELAY_DELAY); + } else { + Serial.println("LOG_MSG=Door Disabled Ignoring Command"); + } + Serial.println("DOOR_LOCK_STATUS=" + stateDoor() ); +} + + + +void commandLockStateDoor() { + // Add code to get door state + Serial.println("DOOR_LOCK_STATUS=" + stateDoor()); +} + +void commandDisableDoor() { + // Add code to get door state + settings.setDisableDoor(1); + unlockDoor(1); + Serial.println("DOOR_DISABLED_STATUS=" + String(settings.DoorDisabled())); +} + +void commandEnableDoor() { + // Add code to get door state + settings.setDisableDoor(0); + lockDoor(); + Serial.println("DOOR_DISABLED_STATUS=" + String(settings.DoorDisabled())); +} + +void commandDisabledState() { + // Add code to get door state + settings.setDisableDoor(0); + unlockDoor(true); + Serial.println("DOOR_DISABLED_STATUS=" + String(settings.DoorDisabled())); +} + + + + + + void handleInterrupt(int bitValue) { static unsigned long lastInterruptTime = 0; unsigned long interruptTime = micros(); @@ -45,8 +103,8 @@ void handleData1Interrupt() { void setup() { Serial.begin(9600); - - + settings.loadFromEEPROM(); + pinMode(DATA0_PIN, INPUT_PULLUP); pinMode(DATA1_PIN, INPUT_PULLUP); @@ -62,8 +120,16 @@ void setup() { attachInterrupt(digitalPinToInterrupt(DATA1_PIN), handleData1Interrupt, FALLING); #ifdef RELAY1 - Serial.println("Enabling Relay: Locking Door"); - lockDoor(); + if (!settings.DoorDisabled()) { + Serial.println("LOG_MSG=Door Enabled"); + Serial.println("LOG_MSG=Locking Door"); + lockDoor(); + } else { + Serial.println("LOG_MSG=Door Disabled"); + Serial.println("LOG_MSG=Unlocking Door"); + unlockDoor(true); + } + #endif #ifdef RELAY2 @@ -93,25 +159,26 @@ void loop() { uint64_t cardID = (cardData >> 1) & 0xFFFF; #ifdef DEBUG - Serial.print("Facility ID (Decimal): "); + Serial.print("DEBUG_MSG=Facility ID (Decimal): "); Serial.println(facilityID); - Serial.print("Facility ID (Binary): "); + Serial.print("DEBUG_MSG=Facility ID (Binary): "); Serial.println(facilityID, BIN); - Serial.print("Card ID (Decimal): "); + Serial.print("DEBUG_MSG=Card ID (Decimal): "); Serial.println(cardID); - Serial.print("Card ID (Binary): "); + Serial.print("DEBUG_MSG=Card ID (Binary): "); Serial.println(cardID, BIN); - Serial.print("Card Data (Binary): "); + Serial.print("DEBUG_MSG=Card Data (Binary): "); Serial.println(cardData, BIN); - Serial.print("Total Bits Received: "); + Serial.print("DEBUG_MSG=Total Bits Received: "); Serial.println(bitCount); #endif String fullCardID = String(facilityID)+":"+String(cardID); - Serial.print("FULL_CARD_ID: "); - Serial.println(fullCardID); + Serial.println("FULL_CARD_ID=" + fullCardID); + + Serial.println(settings.DoorDisabled() ? "DOOR_DISABLED_STATUS=1" : "DOOR_DISABLED_STATUS=0"); cardData = 0; // Reset the card data @@ -126,8 +193,6 @@ void loop() { } - - // Check for commands from the serial interface if (Serial.available() > 0) { String command = Serial.readString(); @@ -137,6 +202,16 @@ void loop() { commandUnlockDoor(); } else if (command.equals("lock")) { commandLockDoor(); + } else if (command.equals("toggle")) { + commandToggleDoor(); + } else if (command.equals("lock_status")) { + commandLockStateDoor(); + } else if (command.equals("enable")) { + commandEnableDoor(); + } else if (command.equals("disable")) { + commandDisableDoor(); + }else if (command.equals("disabled_status")) { + commandDisabledState(); } }