0% found this document useful (0 votes)
49 views2 pages

Vibratingmotor

This document contains code for a vibrating motor service that initializes a vibrating motor and responds to button presses and proximity detections by turning the motor on or off. It includes header files for the service framework and vibrating motor code, defines constants for timer durations, prototypes private functions, and declares module level variables including a priority variable and deferral queue. The module code initializes the vibrating motor, posts events to the service framework, and contains the main service function that handles events and controls the motor by setting GPIO pins and timers.

Uploaded by

api-384495602
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views2 pages

Vibratingmotor

This document contains code for a vibrating motor service that initializes a vibrating motor and responds to button presses and proximity detections by turning the motor on or off. It includes header files for the service framework and vibrating motor code, defines constants for timer durations, prototypes private functions, and declares module level variables including a priority variable and deferral queue. The module code initializes the vibrating motor, posts events to the service framework, and contains the main service function that handles events and controls the motor by setting GPIO pins and timers.

Uploaded by

api-384495602
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/*----------------------------- 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;
}

You might also like