Académique Documents
Professionnel Documents
Culture Documents
Module
WeatherService.c
Revision
1.0.1
Description
This is the first service for the Lights Service under the
Gen2 Events and Services Framework. (a simple service)
Notes
History
When
Who
-------------- --11/15/16 21:12 lbh
What/Why
-------ME218A Project
****************************************************************************/
/*----------------------------- 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 "LightsService.h"
#include "PWM10Tiva.h"
#include "string.h"
#include
#include
#include
#include
#include
#include
#include
"inc/hw_memmap.h"
"inc/hw_types.h"
"inc/hw_gpio.h"
"inc/hw_sysctl.h"
"driverlib/sysctl.h"
"driverlib/pin_map.h"
"driverlib/gpio.h"
Description
Posts an event to this state machine's queue
Notes
Author
Latifah Hamzah, 16 Nov 2016
****************************************************************************/
bool PostWeatherService( ES_Event ThisEvent )
{
return ES_PostToService(MyPriority, ThisEvent);
}
/****************************************************************************
Function
RunWeatherService
Parameters
ES_Event : the event to process
Returns
ES_Event, ES_NO_EVENT if no error ES_ERROR otherwise
Description
add your description here
Notes
Author
Latifah Hamzah, 16 Nov 2016
****************************************************************************/
ES_Event RunWeatherService(ES_Event ThisEvent){
//EventType is one of: ES_RESET, ES_OPEN, ES_WIND, ES_WELCOME
//Parameter will be the strength of the wind. Other parameters ignored / not
used.
ES_Event ReturnEvent;
ReturnEvent.EventType = ES_NO_EVENT; // assume no errors
//number of lightning flashes that have occurred, initialised to zero
static uint8_t LightningFlash = 0;
//if this event is a wind event
if (ThisEvent.EventType == ES_WIND) {
//
sets fraction of light dimming as a function of wind parameter
WeatherModulator = (255-ThisEvent.EventParam)/ThisEvent.EventParam;
}
//if this event is a lightning event
if (ThisEvent.EventType == ES_LIGHTNING) {
//
while there have not been the requisite number of lightning flashes
while (LightningFlash <= TotalLightningFlashes){
//
if lightning pin is low
if ((HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) &=
LightningPin) == 0){
//
set lightning on timer as a function of number of lightning
flash
ES_Timer_InitTimer(LightningTimer, LightningFlash*10);
//
turn lightning on
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) |=
LightningPin;
//
increment lightningcount
LightningFlash ++;
}
else { //if lightning pin is high
//
set lightning off timer as a function of number of lightning
flash
//
~LightningPin;
ES_Timer_InitTimer(LightningTimer, LightningFlash*100);
turn lightning off
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) &=
}
}
return ReturnEvent;
}