Commit 770ad4e2 authored by Ondřej Kučera's avatar Ondřej Kučera
Browse files

fix issue #1

parent 4898c62d
......@@ -49,7 +49,7 @@ void setup() {
void loop() {
accmillis = millis(); // LEAVE AT THE BEGINNING OF LOOP !!!
checkRFID();
checkIntruder();
checkBluetooth();
......@@ -59,15 +59,17 @@ void loop() {
}
void enteringTimeout() {
if (!enteringCountdown){return;}
if (!enteringCountdown) {
return;
}
if (enteringDelay <= 0) {
setEntering(false);
enteringCountdown = false;
enteringDelay = enteringDelayConst;
} else {
enteringDelay -= millis() - accmillis;
}
enteringDelay -= millis() - accmillis;
}
}
......@@ -92,6 +94,8 @@ void checkBluetooth() {
case '3':
SetAuto(false);
break;
case 's':
printStats();
case '\r':
break;
case '\n':
......@@ -101,7 +105,7 @@ void checkBluetooth() {
break;
}
}
delay(50);
}
......@@ -116,17 +120,17 @@ void checkRFID() {
if ( (!rfid.PICC_IsNewCardPresent()) | (!rfid.PICC_ReadCardSerial()) ) {
return;
}
if( (rfid.uid.uidByte[0] == 0x66 & rfid.uid.uidByte[1] == 0xED
& rfid.uid.uidByte[2] == 0xDB & rfid.uid.uidByte[3] == 0x2B) |
(rfid.uid.uidByte[0] == 0xF1 & rfid.uid.uidByte[1] == 0x44
& rfid.uid.uidByte[2] == 0x23 & rfid.uid.uidByte[3] == 0xD9) ) {
if ( (rfid.uid.uidByte[0] == 0x66 & rfid.uid.uidByte[1] == 0xED
& rfid.uid.uidByte[2] == 0xDB & rfid.uid.uidByte[3] == 0x2B) |
(rfid.uid.uidByte[0] == 0xF1 & rfid.uid.uidByte[1] == 0x44
& rfid.uid.uidByte[2] == 0x23 & rfid.uid.uidByte[3] == 0xD9) ) {
authorized = true;
setEntering(true);
Serial.println("authorized");
bluetooth.println("authorized");
}
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
}
......@@ -141,7 +145,7 @@ void setEntering(bool stat) {
}
void setEnteringFalse() {
entering = false;
entering = false;
}
void checkIntruder() {
......@@ -183,7 +187,7 @@ void takeAction() {
if (authorized & !intruder & !entering) {
authorized = false;
}
}
void SetAlarm(bool stat) {
......@@ -193,11 +197,11 @@ void SetAlarm(bool stat) {
Serial.println("alarm started");
bluetooth.println("alarm started");
} else {
alarmStat = false;
digitalWrite(alarm, LOW);
Serial.println("alarm stopped");
bluetooth.println("alarm stopped");
}
alarmStat = false;
digitalWrite(alarm, LOW);
Serial.println("alarm stopped");
bluetooth.println("alarm stopped");
}
}
void SetAuto(bool stat) {
......@@ -206,9 +210,40 @@ void SetAuto(bool stat) {
Serial.println("automatic alarm enabled");
bluetooth.println("automatic alarm enabled");
} else {
autoAlarm = false;
Serial.println("automatic alarm disabled");
bluetooth.println("automatic alarm disabled");
}
autoAlarm = false;
Serial.println("automatic alarm disabled");
bluetooth.println("automatic alarm disabled");
}
}
void printStats() {
//someone inside?
if (intruder) {
if (authorized) {
bluetooth.println("Authorized shitting");
} else bluetooth.println("Unauthorized shitting");
} else {
bluetooth.println("Nobody inside");
}
//auto alarm enabled?
if (autoAlarm) {
bluetooth.println("Auto alarm enabled");
} else {
bluetooth.println("Auto alarm disabled");
}
//alarm triggered?
String alarmType;
if (alarmOverride) {
alarmType = "Manual";
} else {
alarmType = "Automatic";
}
if (alarmStat) {
bluetooth.println(alarmType + "alarm running");
} else {
bluetooth.println("Alarm stopped");
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment