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.
****************************************************************************/
// this will pull in the symbolic definitions for events, which we will want
// to post in response to detecting events
#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
#include
#include
#include
#include
#include
#include
<stdint.h>
<stdbool.h>
"inc/hw_memmap.h"
"inc/hw_types.h"
"inc/hw_gpio.h"
"inc/hw_sysctl.h"
"driverlib/gpio.h"
The functions that actually check the serial hardware for characters
and retrieve them are assumed to be in ES_Port.c
Since we always retrieve the keystroke when we detect it, thus clearing the
hardware flag that indicates that a new key is ready this event checker
will only generate events on the arrival of new characters, even though we
do not internally keep track of the last keystroke that we retrieved.
Author
J. Edward Carryer, 08/06/13, 13:48
****************************************************************************/
bool Check4Keystroke(void)
{
if ( IsNewKeyReady() ) // new key waiting?
{
ES_Event ThisEvent;
ThisEvent.EventType = ES_NEW_KEY;
ThisEvent.EventParam = GetNewKey();
ES_Event PostEvent;
// test distribution list functionality by sending the 'L' key out via
// a distribution list.
switch(ThisEvent.EventParam)
{
case '1':
PostEvent.EventType = EV_FLAG_DROPPED;
PostMaster(PostEvent);
printf("Flag dropped (1 Pressed)\r\n");
break;
case '2':
PostEvent.EventType = EV_CAUTION_FLAG;
PostMaster(PostEvent);
printf("Caution Flag (2 Pressed)\r\n");
break;
case '3':
PostEvent.EventType = EV_RACE_OVER_FLAG;
PostMaster(PostEvent);
printf("Race Over (3 Pressed)\r\n");
break;
case 'A':
case 'a':
PostEvent.EventType = EV_TARGET_REACHED;
PostMaster(PostEvent);
printf("Target reached (a Pressed)\r\n");
break;
case 'B':
case 'b':
PostEvent.EventType = EV_TARGET_IN_SIGHT;
PostMaster(PostEvent);
printf("Target in sight (b Pressed)\r\n");
break;
case 'C':
case 'c':
PostEvent.EventType = EV_TARGET_SET;
PostMaster(PostEvent);
printf("Target set (c Pressed)\r\n");
break;
case 'E':
case 'e':
PostEvent.EventType = EV_AIM_READY;
PostMaster(PostEvent);
printf("Aim ready(e Pressed)\r\n");
break;
case 'G':
case 'g':
PostEvent.EventType = EV_SHOT_FIRED;
PostMaster(PostEvent);
printf("Shot fired (g Pressed)\r\n");
break;
default:
break;
return true;
}
}
return false;
//-----------------------------------------------------------------------------------------//CheckTargetTracking
//Takes no parameter, returns true if event occurred, false if no event
bool CheckTargetTracking(void) {
bool ReturnVal = false;
// If we are in RotateToTarget & TargetInSight
if( (QueryTargetTrackingState() == RotateToTarget) && TargetInSight())
{
//post EV_TARGET_IN_SIGN to Master
ES_Event PostEvent = {EV_TARGET_IN_SIGHT,0};
PostMaster(PostEvent);
ReturnVal = true;
}
else if( (QueryTargetTrackingState() == DriveToTarget) && TargetReached())
{
//post EV_TARGET_REACHED to master
ES_Event PostEvent = {EV_TARGET_REACHED,0};
PostMaster(PostEvent);
ReturnVal = true;
}
return ReturnVal;
}
//End CheckTargetTracking
bool CheckIR(void) {
//store last state of IR pin
static uint8_t LastState = BIT3HI;
bool ReturnVal = false;
//if in the shooting state
if( (QueryBallShootingState() == Aim) && (QueryLocationSM() ==
BallShooting) ) {
// Read pin PD3 (IR sensor)
uint8_t CurrentState = HWREG(GPIO_PORTD_BASE+(GPIO_O_DATA +
ALL_BITS)) & BIT3HI;
//if state changed
if(CurrentState != LastState) {
LastState = CurrentState;
}
}
return ReturnVal;