/**************************************************************************** Module GameplayHSM.c Revision 2.0.1 Description This is the Gameplay module for ME 218B project for Team 3. Implements a hierarchical state machine under the Gen2 Events and Services Framework. Notes Private Definitions BackAwayTime GameplayState_t MyPriority bool InitGameplayMasterSM(uint8_t Priority) --------------------------------- // save our priority // start with the conveyor motor stopped // Start the Master State machine ES_Event_t RunGameplayMasterSM(ES_Event_t CurrentEvent) --------------------- // default to normal entry to new state // based on our current state: // if current state is Idle // execute During function for Idle state // process any events // based on the event type: // if the game has started // we want to move to GameTasks state // mark that we are taking a transition // if current state is GameTasks // execute During function for GameTasks state // process any events // based on the event type: // if the game has ended // we want to move to Idle state // mark that we are taking a transition // if we are making a state transition // execute exit function for current state // modify state variable // execute entry function for new state (this defaults to ES_ENTRY) // in the absence of an error the top level state machine should // always return ES_NO_EVENT, which we initialized at the top of function void StartGameplayMasterSM(ES_Event_t CurrentEvent) ------------------------- // initialize the CurrentState variable to start in Idle state // now we need to let the Run function init the lower level state machines // use LocalEvent to keep the compiler from complaining about unused var GameplayState_t QueryGameplayHSM(void) -------------------------------------- // return CurrentState variable static ES_Event_t DuringIdleState(ES_Event_t Event) ------------------------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // stop conveyor belt // no lower state machines to start // process ES_EXIT event // no lower state machines to give the chance to clean up // start conveyor belt // process other events // this state machine doesn't have a lower state machine to run // return either Event, if you don't want to allow the lower level machine // to remap the current event, or ReturnEvent if you do want to allow it. static ES_Event_t DuringGameTasksState(ES_Event_t Event) -------------------- // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events // no actions for entering this state // start the lower level machine that runs in this state // process ES_EXIT event // on exit, give the lower levels a chance to clean up first // no actions for exiting this state // process other events // run the lower level state machine // return either Event, if you don't want to allow the lower level machine // to remap the current event, or ReturnEvent if you do want to allow it. static void StopConveyor(void) ---------------------------------------------- // set the conveyor output pin low static void StartConveyor(void) --------------------------------------------- // set the conveyor output pin high /***************************************************************************/