Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ondřej Kučera
toilet-intruder
Commits
770ad4e2
Commit
770ad4e2
authored
Jul 11, 2018
by
Ondřej Kučera
Browse files
fix issue
#1
parent
4898c62d
Changes
1
Hide whitespace changes
Inline
Side-by-side
toilet-intruder.ino
View file @
770ad4e2
...
...
@@ -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"
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment