tinance2-doorbot/src/hardware.cpp

92 lines
1.8 KiB
C++
Raw Normal View History

2023-06-12 17:17:28 +00:00
#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
2023-06-21 21:18:55 +00:00
#ifdef RELAY1
#ifdef RELAY1_REVERSED
controlRelay(RELAY1_PIN,true);
#else
controlRelay(RELAY1_PIN,false);
#endif
2023-06-12 17:17:28 +00:00
#endif
#ifdef SERIAL_DEBUG
Serial.println("door unlocked");
#endif
2023-06-12 17:57:43 +00:00
#ifdef LEDCTL_PIN
digitalWrite(LEDCTL_PIN,LOW);
#endif
2023-06-12 17:17:28 +00:00
#ifdef WEB_SERIAL_DEBUG
WebSerial.println("door unlocked");
#endif
}
2023-12-27 21:41:33 +00:00
void lockDoor(bool silent) {
#ifdef BUZZER
if (!silent) {
short_beep();
}
#endif
2023-06-12 17:17:28 +00:00
#ifdef RELAY1
2023-06-21 21:18:55 +00:00
#ifdef RELAY1_REVERSED
controlRelay(RELAY1_PIN,false);
#else
controlRelay(RELAY1_PIN,true);
#endif
2023-06-12 17:17:28 +00:00
#endif
#ifdef SERIAL_DEBUG
Serial.println("door locked");
#endif
2023-06-12 17:57:43 +00:00
#ifdef LEDCTL_PIN
digitalWrite(LEDCTL_PIN,HIGH);
#endif
2023-06-12 17:17:28 +00:00
#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
2023-06-21 21:18:55 +00:00
#ifdef RELAY1_REVERSED
if (relayState == HIGH) {
2023-12-27 21:41:33 +00:00
lockDoor(false);
2023-06-21 21:18:55 +00:00
} else {
unlockDoor(false);
}
#else
if (relayState == LOW) {
2023-12-27 21:41:33 +00:00
lockDoor(false);
2023-06-21 21:18:55 +00:00
} else {
unlockDoor(false);
}
#endif
2023-06-12 17:17:28 +00:00
#endif
}
2023-06-13 15:09:48 +00:00
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
}