Visualblastsm
Visualblastsm
VisualBlastSM
This state machine controls the visual blast for the welcoming mode and turning
it off
States:
VisualBlastOff
SelectingPipeLed
GlowingPipeLed
Intaking Events:
VISUAL_BLAST_ON
VISUAL_BLAST_OFF
GLOW_RANDOM_PIPE (from itself)
ES_TIMEOUT (from VisualBlast_PipeTimer)
Posting Events:
GLOW_RANDOM_PIPE (to itself)
*/
/* include header files for this state machine as well as any machines at the
next lower level in the hierarchy that are sub-machines to this machine
*/
#include "VisualBlastSM.h"
#include "SR_HillAndMotor.h"
#include "GameSM.h"
// Hardware
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
Parameters
uint8_t : 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 for this service
Notes
Author
****************************************************************************/
bool InitVisualBlastSM(uint8_t Priority)
{
MyPriority = Priority;
printf("\r \n Initializing VisualSM");
ES_Event_t ThisEvent;
ThisEvent.EventType = ES_INIT;
if (ES_PostToService(MyPriority, ThisEvent) == true)
{
return true;
}
else
{
return false;
}
}
/****************************************************************************
Function
PostVisualBlastSM
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
Notes
Author
****************************************************************************/
bool PostVisualBlastSM(ES_Event_t ThisEvent)
{
return ES_PostToService(MyPriority, ThisEvent);
}
/****************************************************************************
Function
RunVisualBlastSM
Parameters
ES_Event_t : the event from its service queue to process in this State
Machine
Types of ES_Event_t: VISUAL_BLAST_OFF, VISUAL_BLAST_ON, GLOW_RANDOM_PIPE,
ES_TIMEOUT
Returns
ES_Event_t, ES_NO_EVENT if no error ES_ERROR otherwise
Description
add your description here
Notes
Author
****************************************************************************/
switch (CurrentState)
{
case PseudoState_VisualBlastSM: // If current state is initial
Psedudo State
{
if (ThisEvent.EventType == ES_INIT) // only respond to ES_Init
{
// this is where you would put any actions associated with the
case VisualBlastOff:
{
if (ThisEvent.EventType == VISUAL_BLAST_ON)
{
//post GLOW_RANDOM_PIPE to this service
ES_Event_t PostingEvent;
PostingEvent.EventType = GLOW_RANDOM_PIPE;
PostVisualBlastSM(PostingEvent);
//switch off the last hill led and glow the current random hill led
ControlHillLed( 0);
random_hill_led = rand() % 3 + 4;
ControlHillLed( random_hill_led);
CurrentState = SelectingPipeLed;
}
}
break;
case SelectingPipeLed:
{
if (ThisEvent.EventType == GLOW_RANDOM_PIPE)
{
//select a random pipe
random_glow_pipe_index = rand() % 5 + 1; //pipes from 1-5
//glow a random hill led after switching off the last one
ControlHillLed( 0);
random_hill_led = rand() % 3 + 4;
ControlHillLed( random_hill_led);
case GlowingPipeLed:
{
if (ThisEvent.EventType == ES_TIMEOUT)
{
//actions
/****************************************************************************
Function
ControlHillLed
Parameters
No Parameters
Returns
Nothing
Description
Controls the hill led lighting at random for the welcoming mode.
Sending 0 switches off all the leds
Notes
Author
****************************************************************************/