Controlsm
Controlsm
Controlsm
CONTROL_STATE_MACHINE
This state machine controls the game at a higher level, like start, end, quit.
The game dynamics take place in the InGame state machine
States:
PseudoState
Welcoming
Setup
ReadingDifficulty
Resetting
InGame
Ending
*/
InitControlSM
Parameters
the priorty of this service
Returns
bool, false if error in initialization, true otherwise
Description
Saves away the priority, and does any other required initialization
Function
Initialize the shift register controlling the hill LEDs and motor movements
using the static
function for the same
Initialize the PWM outputs according to the pin diagram. PB6 is used for the
brightness of the analog input, PB7 is used for the Servomotor, and PB4 will be
PWM for Mario control motor
Set PWM Output Frequency for group 0, setting frequency to 50 HZ for group 0 and
initial position
Set PWM Output Frequency for group 1, setting frequency to 200 HZ for group 1
and guarantying 0 HZ
Post ES_INIT to this state machine. Return true if successful, false in case of
any error.
PostControlSM
Parameters
ES_Event_t ThisEvent ,the event to post to the queue
Returns
bool false if the Enqueue operation failed, true otherwise
Description
Posts an event to this state machine's queue
Function:
Call ES_PostToService passing the priority through MyPriority and the assigned
event
RunControlSM
Parameters
ES_Event_t : the event from its service queue to process in this State
Machine
Returns
ES_NO_EVENT if no error ES_ERROR otherwise
Function
Switch CurrentState
If PseudoState_Control:
If event ES_INIT:
Do a visual blast
Switch on the Start button LED
Make current state - Welcoming
If Welcoming:
If event is LEAF_ACTIVATED:
Start the inactive timer
Stop the visual blast of welcoming mode
Switch on the start button LED
Start pulsing difficulty LED by taking the first analog read
If ReadingDifficulty:
If event is ANALOG_READ_COMPLETE:
Pulse difficulty LED according to the chosen difficulty
Make current state as Setup
If InGame:
If event is LEAF_RESET:
Post reset event
Make current state - Resetting
If event is ES_TIMEOUT (Inactive timer):
Post inactive reset event
Make current state - Resetting
If event is MARIO_END:
Stop the Mario
Start the flag to move up
Play the game end sound according to the score achieved
Stamp the LEAF
Make current state — Ending
If Resetting:
If event is MARIO_START_AND_FLAG_DOWN
Start the welcoming visual blast
Make current state as Welcoming
If Ending:
If the FLAG is up:
Stop the FLAG motor
Move Mario to the start
Make current state as MovingMarioBack
If MovingMarioBack:
If event is MARIO_START (Mario reached start):
Post reset
Switch on leaf led
Make current state as Resetting
return ReturnEvent