/*----------------------------- Include Files -----------------------------*/
/* include header files for the framework and this service
*/
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_DeferRecall.h"
#include "ES_ShortTimer.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h" // Define PART_TM4C123GH6PM in project
#include "driverlib/gpio.h"
#include "ES_Port.h"
#include "termio.h"
#include "VibratingMotor.h"
#include "LEDService.h"
/*----------------------------- Module Defines ----------------------------*/
#define ONE_SEC 976
#define THIRTY_SEC (30*ONE_SEC)
#define TEN_SEC (10*ONE_SEC)
/*---------------------------- 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 uint8_t MyPriority;
static uint8_t AreWeInTorch = 0;
// add a deferral queue for up to 3 pending deferrals +1 to allow for overhead
static ES_Event DeferralQueue[3+1];
/*------------------------------ Module Code ------------------------------*/
bool InitializeVibratingMotor ( uint8_t Priority )
{
MyPriority = Priority; //Initialize the MyPriority variable with the passed in
parameter.
if ((HWREG(SYSCTL_RCGCGPIO) & BIT2HI) == 0) { //if clock has not been enabled, then
enable it
HWREG(SYSCTL_RCGCGPIO) |= BIT2HI;
while ((HWREG(SYSCTL_PRGPIO) & BIT2HI) != BIT2HI){
}
}
HWREG(GPIO_PORTC_BASE+GPIO_O_DEN) |= (BIT4HI);
HWREG(GPIO_PORTC_BASE+GPIO_O_DIR) |= (BIT4HI);
HWREG(GPIO_PORTC_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT4LO;
return true;
}
bool PostVibratingMotor( ES_Event ThisEvent )
{
return ES_PostToService( MyPriority, ThisEvent);
}
ES_Event VibratingMotor( ES_Event ThisEvent ){
ES_Event ReturnEvent;
ReturnEvent.EventType = ES_NO_EVENT; // assume no errors
if (ThisEvent.EventType == ES_BUTTON3_PRESSED){
AreWeInTorch = 1;
ES_Timer_InitTimer(VIBRATINGMOTOR_TIMER, THIRTY_SEC);
}
else if ((ThisEvent.EventType == ES_PROX_DETECTED) && (AreWeInTorch == 1)){
HWREG(GPIO_PORTC_BASE+(GPIO_O_DATA+ALL_BITS)) |= BIT4HI;
ES_Timer_InitTimer(VIBRATINGMOTOR_TIMER, TEN_SEC);
AreWeInTorch = 0;
}
if((ThisEvent.EventType == ES_TIMEOUT) && (ThisEvent.EventParam ==
VIBRATINGMOTOR_TIMER)){
HWREG(GPIO_PORTC_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT4LO;
AreWeInTorch = 0;
}
return ReturnEvent;
}