Refactoring logic of alarm system.

parent 9b5e40c8
......@@ -85,13 +85,26 @@ getPossibleThreatState ()
}
State &
getRealThreatState ()
getRealThreatPartAState ()
{
static State * object = NULL;
if (object == NULL)
{
object = new State (realThreatUpdateOperation);
object = new State (realThreatPartAUpdateOperation);
}
return *object;
}
State &
getRealThreatPartBState ()
{
static State * object = NULL;
if (object == NULL)
{
object = new State (realThreatPartBUpdateOperation);
}
return *object;
......@@ -165,6 +178,8 @@ getMobiles ()
void
disabledEnterOperation ()
{
sirenOff();
printStringWithoutDelay(F("Alarm disabled"));
flushRfid();
......@@ -198,7 +213,7 @@ enabledEnterOperation ()
void
enabledUpdateOperation ()
{
if (pirSensorSensesMotion() || isDoorOpen ())
if (pirSensorSensesMotion() || doorIsOpen ())
{
getFsm().transitionTo(getPossibleThreatState());
}
......@@ -224,12 +239,12 @@ possibleThreatUpdateOperation ()
}
else
{
getFsm().transitionTo(getRealThreatState());
getFsm().transitionTo(getRealThreatPartAState());
}
}
void
realThreatUpdateOperation ()
realThreatPartAUpdateOperation ()
{
sirenOn();
......@@ -239,11 +254,30 @@ realThreatUpdateOperation ()
printStringWithoutDelay(F("Waiting police"));
authenticatedOnDelay(DELAY_TIME_OF_RINGING_SIREN);
if (authenticatedOnDelay(DELAY_TIME_OF_RINGING_SIREN))
{
getFsm().transitionTo(getDisabledState());
}
else
{
getFsm().transitionTo(getRealThreatPartBState());
}
}
sirenOff();
void
realThreatPartBUpdateOperation ()
{
if (doorIsClosed())
{
sirenOff();
getFsm().transitionTo(getEnabledState());
}
getFsm().transitionTo(getDisabledState());
if (isAuthenticated ())
{
getFsm().transitionTo(getDisabledState());
}
}
bool
......@@ -340,11 +374,17 @@ sirenOff ()
}
bool
isDoorOpen ()
doorIsOpen ()
{
return digitalRead(DOOR_SENSOR_PIN) == HIGH;
}
bool
doorIsClosed ()
{
return ! doorIsOpen ();
}
bool
pirSensorSensesMotion ()
{
......
Markdown is supported
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