#include "hardware.h" #include "buzzer_ctl.h" void controlRelay(int relayPin, bool on) { digitalWrite(relayPin, on ? HIGH : LOW); // Turn the relay on or off } void unlockDoor(bool silent) { #ifdef BUZZER if (!silent) { granted_beep(); } #endif #ifdef RELAY1 #ifdef RELAY1_REVERSED controlRelay(RELAY1_PIN,true); #else controlRelay(RELAY1_PIN,false); #endif #endif #ifdef SERIAL_DEBUG Serial.println("door unlocked"); #endif #ifdef LEDCTL_PIN digitalWrite(LEDCTL_PIN,LOW); #endif #ifdef WEB_SERIAL_DEBUG WebSerial.println("door unlocked"); #endif } void lockDoor() { #ifdef RELAY1 #ifdef RELAY1_REVERSED controlRelay(RELAY1_PIN,false); #else controlRelay(RELAY1_PIN,true); #endif #endif #ifdef SERIAL_DEBUG Serial.println("door locked"); #endif #ifdef LEDCTL_PIN digitalWrite(LEDCTL_PIN,HIGH); #endif #ifdef WEB_SERIAL_DEBUG WebSerial.println("door locked"); #endif } void toggleDoor() { #ifdef RELAY1 int relayState = digitalRead(RELAY1_PIN); // Toggle the relay based on the current state #ifdef RELAY1_REVERSED if (relayState == HIGH) { lockDoor(); } else { unlockDoor(false); } #else if (relayState == LOW) { lockDoor(); } else { unlockDoor(false); } #endif #endif } String stateDoor() { #ifdef RELAY1 int relayState = digitalRead(RELAY1_PIN); // Toggle the relay based on the current state if (relayState == LOW) { return "Unlocked"; } else { return "Locked"; } #endif }