diff --git a/src/hardware.cpp b/src/hardware.cpp index c2a9a5d..376ec28 100644 --- a/src/hardware.cpp +++ b/src/hardware.cpp @@ -10,12 +10,12 @@ void unlockDoor(bool silent) { granted_beep(); } #endif - #ifdef RELAY1 - #ifdef RELAY1_REVERSED - controlRelay(RELAY1_PIN,true); - #else - controlRelay(RELAY1_PIN,false); - #endif + #ifdef RELAY1 + #ifdef RELAY1_REVERSED + controlRelay(RELAY1_PIN,true); + #else + controlRelay(RELAY1_PIN,false); + #endif #endif #ifdef SERIAL_DEBUG Serial.println("door unlocked"); @@ -32,14 +32,11 @@ void unlockDoor(bool silent) { void lockDoor() { #ifdef RELAY1 - - - #ifdef RELAY1_REVERSED - controlRelay(RELAY1_PIN,false); - #else - controlRelay(RELAY1_PIN,true); - #endif - + #ifdef RELAY1_REVERSED + controlRelay(RELAY1_PIN,false); + #else + controlRelay(RELAY1_PIN,true); + #endif #endif #ifdef SERIAL_DEBUG Serial.println("door locked"); @@ -59,11 +56,19 @@ void toggleDoor() { #ifdef RELAY1 int relayState = digitalRead(RELAY1_PIN); // Toggle the relay based on the current state - if (relayState == LOW) { - lockDoor(); - } else { - unlockDoor(false); - } + #ifdef RELAY1_REVERSED + if (relayState == HIGH) { + lockDoor(); + } else { + unlockDoor(false); + } + #else + if (relayState == LOW) { + lockDoor(); + } else { + unlockDoor(false); + } + #endif #endif }