basic controller
This commit is contained in:
parent
7e9d7e96ea
commit
cc5c44c8e2
5 changed files with 106 additions and 69 deletions
1
README
1
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
|
||||
|
||||
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
#ifndef ACL_H
|
||||
#define ACL_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <initializer_list>
|
||||
#include <EEPROM.h>
|
||||
|
||||
#include <Preferences.h>
|
||||
|
||||
#ifdef WEB_SERVER
|
||||
#ifdef WEB_SERIAL_DEBUG
|
||||
#include <WebSerial.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct User {
|
||||
String cardId;
|
||||
String desc;
|
||||
};
|
||||
|
||||
class ACL {
|
||||
public:
|
||||
ACL();
|
||||
ACL(std::initializer_list<User> 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
|
14
include/disable.h
Normal file
14
include/disable.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#include "hardware.h"
|
||||
#include <Arduino.h>
|
||||
#include "settings.h"
|
||||
|
||||
Settings settings;
|
||||
|
||||
#ifdef BUZZER
|
||||
#include "buzzer_ctl.h"
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
|
107
src/main.cpp
107
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue