/****************************************************************************
Module
CoinSlotChecker.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 "CoinSlotChecker.h"
#include "GameFSM.h"
#include "dbprintf.h"
#include "PIC32_AD_Lib.h"
/*----------------------------- Module Defines ----------------------------*/
static uint32_t LastCoinSlotState;
static uint32_t CoinSlotResult[1];
static uint32_t Coins;
static uint32_t LastTickCount;
#define ONE_SEC 1000
#define HALF_SEC (ONE_SEC / 2)
#define TWO_SEC (ONE_SEC * 2)
#define FIVE_SEC (ONE_SEC * 5)
#define TWENTY_SEC (ONE_SEC * 20)
/*---------------------------- Module Functions ---------------------------*/
/* prototypes for private functions for this service.They should be functions
relevant to the behavior of this service
*/
/*------------------------------ 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 InitCoinSlotChecker(void)
{
LastCoinSlotState = PORTBbits.RB4;
Coins = 0;
}
/****************************************************************************
Function
RunTemplateService
Parameters
ES_Event_t : the event to process
Returns
ES_Event, ES_NO_EVENT if no error ES_ERROR otherwise
Description
add your description here
Notes
Author
J. Edward Carryer, 01/15/12, 15:23
****************************************************************************/
bool Check4Coin(void)
{
bool ReturnVal = false;
if(QueryGameFSM() == Idle)
{
uint32_t CurrentCoinSlotState = PORTBbits.RB4;
ES_Event_t ThisEvent;
uint32_t CurrentTickCount = ES_Timer_GetTime();
if (CurrentCoinSlotState == 0 && Coins < 1)
{
//DB_printf("Coin Inserted\r\n");
ReturnVal= true;
Coins++;
LastTickCount = ES_Timer_GetTime();
ThisEvent.EventType = COIN_INSERT;
PostGameFSM(ThisEvent);
}
else if(CurrentTickCount - LastTickCount > 300)
{
Coins = 0;
}
LastCoinSlotState = CurrentCoinSlotState;
}
return ReturnVal;
}
/***************************************************************************
private functions
***************************************************************************/
/*------------------------------- Footnotes -------------------------------*/
/*------------------------------ End of file ------------------------------*/