/**************************************************************************** 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 Note the use of static variables in sample event checker to detect ONLY transitions. History When Who What/Why -------------- --- -------- 08/06/13 13:36 jec initial version ****************************************************************************/ // 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 our own prototypes to insure consistency between header & // actual functionsdefinition #include "EventCheckers.h" #include "Pins.h" #include <stdio.h> /**************************************************************************** Function Check4Keystroke Parameters None Returns bool: true if a new key was detected & posted Description checks to see if a new key from the keyboard is detected and, if so, retrieves the key and posts an ES_NewKey event to TestHarnessService1 Notes 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 ****************************************************************************/ //Drive: bool CheckFrontBumperHit(void){ static unsigned char LastPinState = 0; unsigned char CurrentPinState; bool ReturnVal = false; CurrentPinState = PORT_BUMPER & PIN_FRONT_BUMPER; // check for pin high and different from last time if ( (CurrentPinState != LastPinState) && (CurrentPinState == PIN_FRONT_BUMPER) ) { // event detected, so post detected event ES_Event ThisEvent; ThisEvent.EventType = EV_FRONT_WALL_REACHED; ThisEvent.EventParam = 1; PostMasterSM(ThisEvent); // this could be any SM post function or EF_PostAll ReturnVal = true; printf("Front Bumper Hit!!! \n\r"); } LastPinState = CurrentPinState; return ReturnVal; } bool CheckBackBumperHit(void){ static unsigned char LastPinState = 0; unsigned char CurrentPinState; bool ReturnVal = false; CurrentPinState = PORT_BUMPER & PIN_BACK_BUMPER; // check for pin high and different from last time if ( (CurrentPinState != LastPinState) && (CurrentPinState == PIN_BACK_BUMPER) ) { // event detected, so post detected event ES_Event ThisEvent; ThisEvent.EventType = EV_BACK_WALL_REACHED; ThisEvent.EventParam = 1; PostMasterSM(ThisEvent); // this could be any SM post function or EF_PostAll ReturnVal = true; printf("Back Bumper Hit!!! \n\r"); } LastPinState = CurrentPinState; return ReturnVal; } bool CheckForTape(void){ return false; } //Shoot: bool CheckForBeacon(void){ return false; } bool Check4Keystroke(void) { if ( IsNewKeyReady() ) // new key waiting? { ES_Event ThisEvent; ThisEvent.EventType = ES_NEW_KEY; ThisEvent.EventParam = GetNewKey(); // test distribution list functionality by sending the 'L' key out via // a distribution list. PostMasterSM( ThisEvent ); return true; } return false; }