Module GameControlService.c Description This implements the gameplay state for the game control Notes Private definitions SaveColorFreq TurnOnPWMEmitters GameTime AssignedTeam ColorAssigned FreqAssigned EastRecycleColor WestRecycleColor LastEastRecycleColor LastWestRecycleColor bool InitGameControlService(uint8_t Priority) //Save recieved priority // initialize all hardware // initialize collision module // initialize beacon sensors // set up servos // turn on recycling emitter // post the initial transition event ES_Event_t RunGameControlService(ES_Event_t ThisEvent) //Pass NextState to CurrentState //Reads current State //If CurrentState is InitGState //If recieved event is ES_INIT //Read team designation switch value and save to TeamByte //If TeamByte equals 0 //Register as Team North //Save EventParam as 0x10 //Set team servo to Raise USA flag //If TeamByte equals 1 //Register as Team South //Save EventParam as 0x01 //Set team servo to Raise Mexico flag //Post TEAM_SELECT event to Compass Service (event param defined before) //Set next state to WaitingforREG //If CurrentState is WaitingforREG //If recieved event is REG_COMPLETE //Save values from Compass Service (using Getter Functions from CompassService) //Start GameControlTimer for 100ms //Turn off Game indicator LED //Set next state to GameOff //If CurrentState is GameOff //If recieved event is ES_TIMEOUT //Save values from Compass Service (using Getter Functions from CompassService) //Start GameControlTimer for 1s //Set next state to GameOff //If recieved event is GAME_STARTED //Turn on Game indicator LED //Set next state to GameOn //If CurrentState is GameOn //If recieved event is ES_TIMEOUT //Save values from Compass Service (using Getter Functions from CompassService) //Check if assigned colors have changed or not //If colors have changed, post RECYCLING_CHANGE to GameplayMaster SM //Increment GameTime by 1 //Check if(138 - GameTime) < TimeToDump //If so, post START_DUMPING to GameplayMasterSM and GameControlService //Start GameControlTimer for 1000ms //Set next state to GameOn //If recieved event is START_DUMPING //Set next state to TimeToDump //If recieved event is GAME_OVER //Set GameTime to 0 //Post MOTOR_COMMAND event (param STOP) to MotorSM //Turn off game indicator LED //Set next state to GameOff //Save to history current values of East and West Recycle color //If CurrentState is TimeToDump //If recieved event is ES_TIMEOUT //Increment GameTime by 1 //If GameTime is equal to 0 //Post GAME_OVER event to GameControlService and GameplayMasterSM //Save values from Compass Service (using Getter Functions from CompassService) //Check if assigned colors have changed or not //If colors have changed, post RECYCLING_CHANGE to GameplayMaster SM //Start GameControlTimer for 1000ms //Set next state to TimeToDump //If recieved event is GAME_OVER //Set GameTime to 0 //Post MOTOR_COMMAND event (param STOP) to MotorSM //Turn off game indicator LED //Set next state to GameOff //Save to history current values of East and West Recycle color //return ReturnEvent; GameControlState_t QueryGameControl(void) //return CurrentState uint16_t GetOurLandfillFreq(void) //Query GetTeamAssignment //If result equals NORTH //return NorthLandfillFreq //else //return SouthLandfillFreq uint16_t GetOurRecycleBeaconFreq(void) //Obtain ColorAssignment from COMPASS and save to OurColor //if value returned from EastRecycleColor equals OurColor //return EastRecyclingFreq; //else //return WestRecyclingFreq static void TurnOnPWMEmitters(void) //Obtain RecycleBeaconFreq //Set PWM Frequency for RecycleEmitter //Set PWM Duty to 50 percent for RecycleEmitter //Enable PWM line for RecycleEmitter uint16_t RecycleOpenFreq; RecycleOpenFreq = GetOurRecycleBeaconFreq(); //Set Initial PWM Frequency PWM_SetFrequency(RecycleOpenFreq, RecycleEmitter); //Turn off PWM frequency PWM_SetDuty(50, RecycleEmitter); //Enable PWM line HWREG(PWM1_BASE + PWM_O_ENABLE) |= PWM_ENABLE_PWM0EN;