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
abfd51b4
Commit
abfd51b4
authored
Jul 11, 2018
by
Ondřej Kučera
Browse files
fix issue
#3
& minor improvements
parent
770ad4e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
toilet-intruder.ino
View file @
abfd51b4
...
...
@@ -16,10 +16,14 @@ bool alarmStat = false;
bool
authorized
=
false
;
bool
intruder
=
false
;
bool
entering
=
false
;
const
long
enteringDelayConst
=
30000
;
long
enteringDelay
=
30000
;
const
long
enteringDelayConst
=
15000
;
long
enteringDelay
=
15000
;
bool
entered
=
false
;
bool
leaving
=
false
;
const
long
leavingDelayConst
=
10000
;
long
leavingDelay
=
10000
;
long
double
accmillis
;
bool
enteringCountdown
=
fals
e
;
long
double
lastIntruderTim
e
;
SoftwareSerial
bluetooth
(
TX
,
RX
);
MFRC522
rfid
(
SDA_PIN
,
RST_PIN
);
...
...
@@ -55,23 +59,37 @@ void loop() {
checkBluetooth
();
takeAction
();
leavingTimeout
();
// LEAVE AT THE END OF LOOP !!!
enteringTimeout
();
// LEAVE AT THE END OF LOOP !!!
}
void
enteringTimeout
()
{
if
(
!
entering
Countdown
)
{
if
(
!
entering
)
{
return
;
}
if
(
enteringDelay
<=
0
)
{
setE
ntering
(
false
)
;
enter
ingCountdown
=
fals
e
;
e
ntering
=
false
;
enter
ed
=
tru
e
;
enteringDelay
=
enteringDelayConst
;
}
else
{
enteringDelay
-=
millis
()
-
accmillis
;
}
}
void
leavingTimeout
()
{
if
(
!
leaving
)
{
return
;
}
if
(
leavingDelay
<=
0
)
{
leaving
=
false
;
authorized
=
false
;
leavingDelay
=
leavingDelayConst
;
}
else
{
leavingDelay
-=
millis
()
-
accmillis
;
}
}
void
checkBluetooth
()
{
...
...
@@ -126,7 +144,7 @@ void checkRFID() {
(
rfid
.
uid
.
uidByte
[
0
]
==
0xF1
&
rfid
.
uid
.
uidByte
[
1
]
==
0x44
&
rfid
.
uid
.
uidByte
[
2
]
==
0x23
&
rfid
.
uid
.
uidByte
[
3
]
==
0xD9
)
)
{
authorized
=
true
;
setEntering
(
true
)
;
entered
=
false
;
Serial
.
println
(
"authorized"
);
bluetooth
.
println
(
"authorized"
);
}
...
...
@@ -135,19 +153,6 @@ void checkRFID() {
rfid
.
PCD_StopCrypto1
();
}
void
setEntering
(
bool
stat
)
{
if
(
stat
)
{
entering
=
true
;
enteringCountdown
=
true
;
}
else
{
entering
=
false
;
}
}
void
setEnteringFalse
()
{
entering
=
false
;
}
void
checkIntruder
()
{
long
response
,
distance
;
...
...
@@ -162,10 +167,12 @@ void checkIntruder() {
if
(
distance
<
60
&
intruder
==
false
)
{
intruder
=
true
;
lastIntruderTime
=
accmillis
;
Serial
.
println
(
"someone is inside"
);
bluetooth
.
println
(
"someone is inside"
);
}
else
if
(
distance
>
60
&
intruder
==
true
)
{
}
else
if
(
distance
>
60
&
intruder
==
true
&
(
accmillis
-
lastIntruderTime
)
>
4000
)
{
intruder
=
false
;
lastIntruderTime
=
accmillis
;
Serial
.
println
(
"intruder left"
);
bluetooth
.
println
(
"intruder left"
);
}
...
...
@@ -178,14 +185,23 @@ void takeAction() {
SetAlarm
(
true
);
}
//stop alarm if nobody is present
//stop alarm if nobody is present
; respect manual alarm
if
(
alarmStat
&
!
intruder
&
!
alarmOverride
)
{
SetAlarm
(
false
);
}
//fall back to unauthorized status when the authorized person leaves
if
(
authorized
&
!
intruder
&
!
entering
)
{
authorized
=
false
;
//start an entering timeout to let an authorized person get in
if
(
authorized
&
!
entered
&
!
entering
&
!
leaving
)
{
entering
=
true
;
Serial
.
println
(
"entering started"
);
bluetooth
.
println
(
"entering started"
);
}
//start a leaving timeout to let an authorized person leave
if
(
authorized
&
!
intruder
&
entered
&
!
entering
&
!
leaving
)
{
leaving
=
true
;
Serial
.
println
(
"leaving started"
);
bluetooth
.
println
(
"leaving started"
);
}
}
...
...
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