/****************************************************************************
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 gets us the prototype for ES_PostAll
#include "ES_Framework.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 "PIC32_AD_Lib.h"
#include "dbprintf.h"
bool CheckJoystickEvents(void)
{
ES_Event_t ThisEvent;
bool ReturnVal = false;
if(QueryGameFSM() == Wait4Input){
//DB_printf("Check Joy\r\n");
uint16_t CENTER_VALUE = 512;
uint16_t THRESHOLD = 400;
uint16_t CENTER_THRESHOLD = 100;
uint16_t joystickX;
uint16_t joystickY;
uint32_t joystickVals[2];
static uint8_t directionRead;
ADC_MultiRead(joystickVals);
joystickX = joystickVals[0];
joystickY = joystickVals[1];
if((joystickX < CENTER_VALUE + CENTER_THRESHOLD) && (joystickX > CENTER_VALUE - CENTER_THRESHOLD) && (joystickY < CENTER_VALUE + CENTER_THRESHOLD) && (joystickY > CENTER_VALUE - CENTER_THRESHOLD)){
directionRead = 0;
}
if(directionRead == 0){
if(joystickY < (CENTER_VALUE - THRESHOLD)){
ThisEvent.EventType = JOYSTICK_UP;
ThisEvent.EventParam = joystickY;
ReturnVal = true;
ES_PostAll(ThisEvent);
directionRead = 1;
DB_printf("Up\r\n");
}else if(joystickY > (CENTER_VALUE + THRESHOLD)){
ThisEvent.EventType = JOYSTICK_DOWN;
ThisEvent.EventParam = joystickY;
ReturnVal = true;
ES_PostAll(ThisEvent);
directionRead = 1;
DB_printf("Down\r\n");
}
if(joystickX < (CENTER_VALUE - THRESHOLD)){
ThisEvent.EventType = JOYSTICK_LEFT;
ThisEvent.EventParam = joystickX;
ReturnVal = true;
ES_PostAll(ThisEvent);
directionRead = 1;
DB_printf("Left\r\n");
}else if(joystickX > (CENTER_VALUE + THRESHOLD)){
ThisEvent.EventType = JOYSTICK_RIGHT;
ThisEvent.EventParam = joystickX;
ReturnVal = true;
ES_PostAll(ThisEvent);
directionRead = 1;
DB_printf("Right\r\n");
}
}
}
return ReturnVal;
}