Professional Documents
Culture Documents
Module
EventCheckers.c
Revision
1.0.1
Description
This is the sample for writing event checkers along with the event
checkers used in the basic framework test harness.
Notes
Check4Direction, Check4Start ?????
History
When
Who
What/Why
----------------------02/11/2015
13:55
Sky
Initial version
****************************************************************************/
// this will pull in the symbolic definitions for events, which we will want
// to post in response to detecting events
#include <stdint.h>
#include
#include
#include
#include
#include
#include
#include
"inc/hw_memmap.h"
"inc/hw_gpio.h"
"inc/hw_pwm.h"
"inc/hw_sysctl.h"
"inc/hw_types.h"
"bitdefs.h"
<stdio.h>
#include "ES_Configure.h"
// this will get us the structure definition for events, which we will need
// in order to post events in response to detecting events
#include "ES_Events.h"
// if you want to use distribution lists then you need those function
// definitions too.
#include "ES_PostList.h"
// This include will pull in all of the headers from the service modules
// providing the prototypes for all of the post functions
#include "ES_ServiceHeaders.h"
// this test harness for the framework references the serial routines that
// are defined in ES_Port.c
#include "ES_Port.h"
// include our own prototypes to insure consistency between header &
// actual functionsdefinition
#include "EventCheckers.h"
#include "MasterMachine.h"
#include "GameStateMachine.h"
#include "SPIStateMachine.h"
#include "RaceStateMachine.h"
#include "Scan.h"
#include "Calculation.h"
#include "InputCaptureShoot.h"
#include <math.h>
#define TOL4POS 10
#define TOL4ORI 20
#define LEFT 0
#define
#define
#define
#define
RIGHT 1
SHOOT 0
OBSTACLE 1
MASTER 2
********************************************************************/
bool Check4Region(void)
{
bool ReturnVal = false;
static uint8_t LastRegion = 19;
//if the game is running, check the current region
if (isStart)
{
uint8_t CurrentRegion;
//Call FindRegion to calculate and find the current region
CurrentRegion = FindRegion();
//if the region of our Kart has changed
if (CurrentRegion != LastRegion)
{
printf("CurrentRegion = %d \n\r", CurrentRegion);
ES_Event ThisEvent;
//switch the CurrentRegion and post corresponding event
to Master Machine
switch (CurrentRegion)
{
case 1
:
ThisEvent.EventT
ype = ES_InRegion1;
break;
case 2
: ThisEvent.EventType =
case 3
case 4
: ThisEvent.EventType =
case 5
: ThisEvent.EventType =
case 6
: ThisEvent.EventType =
case 7
: ThisEvent.EventType =
case 8
: ThisEvent.EventType =
case 9
: ThisEvent.EventType =
case 10
: ThisEvent.EventType =
ES_InRegion2;
break;
ThisEvent.EventT
ype = ES_InRegion3;
break;
ES_InRegion4;
break;
ES_InRegion5;
break;
ES_InRegion6;
break;
ES_InRegion7;
break;
ES_InRegion8;
break;
ES_InRegion9;
break;
ES_InRegion10;
break;
case 11
ThisEvent.EventT
break;
ype = ES_InRegion11;
break;
default
}
ReturnVal = true;
LastRegion = CurrentRegion;
PostToMasterSM(ThisEvent);
}
}
return ReturnVal;
}
/********************************************************************
FUNCTION Check4Position
ARGUMENTS: no arguments
RETURN: true if our Kart arrived at the Target Position
DESCRIPTION: check if the kart has arrived at the target position
********************************************************************/
bool Check4Position(void)
{
bool ReturnVal = false;
//if the game is running, check the position of our kart
if (isStart)
{
//Query the state of Race state machine
RaceState tempState = QueryRaceState();
//if we are in the state of Race_ToShoot or Race_Region6
if ((tempState == Race_ToShoot)||(tempState == Race_Region6))
{
static Target LastTarget = {0, 0};
static Target CurrentTarget;
KartStatusType Kart;
//switch self to get the coordinates of our kart
switch (self)
{
case 1
:
Kart = QueryKart
1Status();
break;
case 2
Kart = QueryKart
case 3
Kart = QueryKart
2Status();
break;
3Status();
break;
default
:
break;
}
//query the current target position
CurrentTarget = QueryTarget();
//if the target is different from last target
if ((CurrentTarget.x != LastTarget.x) ||
(CurrentTarget.y != LastTarget.y))
{
void SetisAligned(void)
{
isAligned = true;
}
void ResetisAligned(void)
{
isAligned = false;
}