EventCheckers.c
// Event Checking functions for sample
#include "ES_Configure.h"
#include "ES_General.h"
#include "ES_Events.h"
#include "ES_PostList.h"
#include "EventCheckers.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"
static boolean OC1Expired(void);
//Flags for throwing events
static int midTape;
static int tapeAlign;
static int bump = 1;
static int findbot = 0;
//FAC event checker for receiving bits flag
boolean CheckSPIF(void)
{
boolean ReturnVal = False;
ES_Event currEvent;
if ((SPISR & _S12_SPIF) != 0)
{
currEvent.EventType = SPIFSet;
PostMasterSM(currEvent);
}
return ReturnVal;
}
boolean CheckTimers(void)
{
boolean ReturnVal = False;
ES_Event currEvent;
if(OC1Expired())
{
currEvent.EventType = OC1Exp;
PostMasterSM(currEvent);
}
return ReturnVal;
}
//Rear bumper
boolean CheckSwitch(void)
{
boolean ReturnVal = False;
ES_Event currEvent;
if(PTAD & BIT0HI)
{
if (bump == 1)
{
currEvent.EventType = BumpSwitchHit;
PostMasterSM(currEvent);
bump = 0;
}
}
return ReturnVal;
}
//Used for tape sensing, but never implemented
boolean CheckTape(void)
{
boolean ReturnVal = False;
ES_Event currEvent;
if ((ADS12_ReadADPin(1) < 300) && midTape == 1)
{
// printf("%d\r\n", ADS12_ReadADPin(0));
currEvent.EventParam = 0;
currEvent.EventType = MidTape;
PostMasterSM(currEvent);
midTape = 0;
}
if ((ADS12_ReadADPin(2) < 300) /*&& (ADS12_ReadADPin(3) < 300)*/ && tapeAlign == 1)
{
currEvent.EventParam = 0;
currEvent.EventType = TapeAlign;
PostMasterSM(currEvent);
tapeAlign = 0;
}
return ReturnVal;
}
//Used for checking when FAC sees our bot
boolean CheckBot(void)
{
boolean ReturnVal = False;
ES_Event currEvent;
if(findbot == 1)
{
if(queryShip(15).active == TRUE)
{
currEvent.EventType = botfound;
PostMasterSM(currEvent);
findbot = 0;
}
}
return ReturnVal;
}
static boolean OC1Expired()
{
return ((TIM0_TFLG1 & _S12_C5F) != 0);
}
//Functions used by other state machines to set flags and send events
void requestMidTape(void )
{
midTape = 1;
}
void requestTapeAlign(void )
{
tapeAlign = 1;
}
void requestBump(void )
{
bump = 1;
}
void requestFind(void )
{
findbot = 1;
}
#include "ES_Configure.h"
#include "ES_General.h"
#include "ES_Events.h"
#include "ES_PostList.h"
#include "EventCheckers.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"
static boolean OC1Expired(void);
//Flags for throwing events
static int midTape;
static int tapeAlign;
static int bump = 1;
static int findbot = 0;
//FAC event checker for receiving bits flag
boolean CheckSPIF(void)
{
boolean ReturnVal = False;
ES_Event currEvent;
if ((SPISR & _S12_SPIF) != 0)
{
currEvent.EventType = SPIFSet;
PostMasterSM(currEvent);
}
return ReturnVal;
}
boolean CheckTimers(void)
{
boolean ReturnVal = False;
ES_Event currEvent;
if(OC1Expired())
{
currEvent.EventType = OC1Exp;
PostMasterSM(currEvent);
}
return ReturnVal;
}
//Rear bumper
boolean CheckSwitch(void)
{
boolean ReturnVal = False;
ES_Event currEvent;
if(PTAD & BIT0HI)
{
if (bump == 1)
{
currEvent.EventType = BumpSwitchHit;
PostMasterSM(currEvent);
bump = 0;
}
}
return ReturnVal;
}
//Used for tape sensing, but never implemented
boolean CheckTape(void)
{
boolean ReturnVal = False;
ES_Event currEvent;
if ((ADS12_ReadADPin(1) < 300) && midTape == 1)
{
// printf("%d\r\n", ADS12_ReadADPin(0));
currEvent.EventParam = 0;
currEvent.EventType = MidTape;
PostMasterSM(currEvent);
midTape = 0;
}
if ((ADS12_ReadADPin(2) < 300) /*&& (ADS12_ReadADPin(3) < 300)*/ && tapeAlign == 1)
{
currEvent.EventParam = 0;
currEvent.EventType = TapeAlign;
PostMasterSM(currEvent);
tapeAlign = 0;
}
return ReturnVal;
}
//Used for checking when FAC sees our bot
boolean CheckBot(void)
{
boolean ReturnVal = False;
ES_Event currEvent;
if(findbot == 1)
{
if(queryShip(15).active == TRUE)
{
currEvent.EventType = botfound;
PostMasterSM(currEvent);
findbot = 0;
}
}
return ReturnVal;
}
static boolean OC1Expired()
{
return ((TIM0_TFLG1 & _S12_C5F) != 0);
}
//Functions used by other state machines to set flags and send events
void requestMidTape(void )
{
midTape = 1;
}
void requestTapeAlign(void )
{
tapeAlign = 1;
}
void requestBump(void )
{
bump = 1;
}
void requestFind(void )
{
findbot = 1;
}