Sie sind auf Seite 1von 4

DDM Module (a service that implements a state machine)

Module Variables: CurrentState, MyPriority, NumOfHits = 0


Module Functions controlLaser
Defines - HIT as 1, MISS_60S as 2, LASER_ON as 1, LASER_OFF as 2
InitializeDDM
Takes a priority number, returns true.
Initialize the MyPriority variable with the passed in parameter.
Set CurrentState to be InitDDM
Post Event ES_Init to DDM queue
End of InitializeDDM
RunDDM (implements the state machine for DDM)
The EventType field of ThisEvent will be one of: ES_INIT, TargetHit, TargetMiss, ES_TIMEOUT,
WheelRotationStarted, and WheelRotationStopped
Returns ES_NO_EVENT
Local Variables: NextState
Set NextState to CurrentState
Based on the state of the CurrentState variable choose one of the following blocks of code:
CurrentState is InitDDM
If ThisEvent is ES_Init
Set NextState to Armed
Start Fear LED strip
Send high signal to Ed
End if
End InitDDM block
CurrentState is Armed
If ThisEvent is WheelRotationStarted
Start disarming Timer (last for 60 sec) which posts to DDM
Set NextState to Disarming
Set NumOfHits to 0
Post EnteringDisarmingState to BlinkingLED and Servo2 modules
Switch off fear LED
Switch on All LEDs where the bomb wires are
Start Laser pointer using controlLaser function
Send high signal to Ed
End if
End Armed block
CurrentState is Disarming
If ThisEvent is WheelRotationStopped
Set NextState to NoPower
Switch all LEDs off (strip+11)
Switch off Laser Pointer using controlLaser function
Send high signal to Ed

End if
If ThisEvent is ES_TIMEOUT from disarming timer
Set NextState to Dead
Switch all LEDs off (strip+11)
Switch off Laser Pointer using controlLaser function
Post ExitingDisamingState to BlinkingLED and Servo2 modules with parameter
MISS_60S to show not disarmed
Start dead Timer (which lasts for 3 sec) which posts to DDM and Servo2
Send high signal to Ed
End if
If ThisEvent is TargetMiss
Set NextState to Dead
Switch all LEDs off (strip+11)
Switch off Laser Pointer using controlLaser function
Post ExitingDisamingState to BlinkingLED and Servo2 modules with parameter
MISS_60S to show not disarmed
Start dead Timer (which lasts for 3 sec) which posts to DDM and Servo2
Send high signal to Ed
End if
If ThisEvent is TargetHit
NumOfHits=NumOfHits+1;
If NumOfHits equal to 2
Set NextState to Disarmed
Switch off all 11 LEDs
Switch off Laser Pointer using controlLaser function
Start Joy LED strip
Start disarmed Timer (which lasts for 30 sec) which posts to DDM and
Servo2
Post ExitingDisamingState to BlinkingLED and Servo2 modules with
parameter HIT to show all targets hit successfully
Send low signal to Ed
End if
Else
Set NextState to Disarming
Switch off target LED (wire cut)
Send high signal to Ed
End else
End if
End Disarming block
CurrentState is NoPower
If ThisEvent is WheelRotationStarted
Set NextState to Disarming
Set NumOfHits to 0
Switch on all LEDs on hero A's side

Start Laser pointer using controlLaser function


Send high signal to Ed
End if
If ThisEvent is ES_TIMEOUT from disarming timer
Set NextState to Dead
Switch all LEDs off (strip+11)
Switch off Laser Pointer using controlLaser function
Start dead Timer (which lasts for 3 sec) which posts to DDM and Servo2
Post ExitingDisamingState to BlinkingLED and Servo2 modules with parameter
MISS_60S to show not disarmed
Send high signal to Ed
End if
End NoPower block
CurrentState is Disarmed
If ThisEvent is ES_TIMEOUT from disarmed timer
Set NextState to Armed
Set NumOfHits to 0
Start Fear LED strip
Send high signal to Ed
End if
End Disarmed block
CurrentState is Dead
If ThisEvent is ES_TIMEOUT from dead timer
Set NextState to Armed
Set NumOfHits to 0;
Start Fear LED strip
Send high signal to Ed
End if
End Dead block
Set NextState to CurrentState
Return ES_NO_EVENT
End of RunDDM
QueryDDM Function
Takes no parameter, returns DDMState_t
Public function to query the state of the this state machine
Returns CurrentState
End of QueryDDM
controlLaser Function
Takes integer laserStatus as input, returns nothing
If laserStatus is LASER_ON
Switch laser pointer ON
End if
Else if laserStatus is LASER_OFF

Switch laser pointer OFF


End if
End of controlLaser block

Das könnte Ihnen auch gefallen