/****************************************************************************
Module
ButtonEventChecker.c
Revision
1.0.1
Description
This is a template file for implementing a simple service under the
Gen2 Events and Services Framework.
Notes
History
When Who What/Why
-------------- --- --------
01/16/12 09:58 jec began conversion from TemplateFSM.c
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this state machine as well as any machines at the
next lower level in the hierarchy that are sub-machines to this machine
*/
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ButtonEventChecker.h"
#include "GameFSM.h"
#include "ButtonModule.h"
#include "dbprintf.h"
/*----------------------------- Module Defines ----------------------------*/
/*---------------------------- Module Functions ---------------------------*/
/* prototypes for private functions for this service.They should be functions
relevant to the behavior of this service
*/
/*---------------------------- Module Variables ---------------------------*/
// with the introduction of Gen2, we need a module level Priority variable
static uint32_t LastButtonState;
static uint32_t LastTickCount;
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
InitTemplateService
Parameters
uint8_t : the priorty of this service
Returns
bool, false if error in initialization, true otherwise
Description
Saves away the priority, and does any
other required initialization for this service
Notes
Author
J. Edward Carryer, 01/16/12, 10:00
****************************************************************************/
void InitButtonEventChecker(void)
{
//Initializes Button Checker
LastButtonState = PORTBbits.RB2;
LastTickCount = ES_Timer_GetTime();
}
bool Check4Button(void)
{
bool ReturnVal = false;
uint32_t CurrentButtonState = PORTBbits.RB2;
ES_Event_t ThisEvent;
// uint32_t CurrentTickCount = ES_Timer_GetTime();
if(QueryGameFSM() == Wait4Input)
{
//DB_printf("Checking for Button...\r\n");
if(CurrentButtonState != LastButtonState)
{
if(CurrentButtonState == 0)
{
DB_printf("Button Down\r\n");
ThisEvent.EventType = BUTTON_DOWN;
ReturnVal = true;
PostButtonModule(ThisEvent);
}
}
}
LastButtonState = CurrentButtonState;
return ReturnVal;
}
/***************************************************************************
private functions
***************************************************************************/
/*------------------------------- Footnotes -------------------------------*/
/*------------------------------ End of file ------------------------------*/