Professional Documents
Culture Documents
Module
TemplateService.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
*/
// This module
#include "LEDService.h"
// Hardware
#include <xc.h>
//SPI Stuff
#include "PIC32_SPI_HAL.h"
#include "DM_Display.h"
//Font stuff
#include "bitdefs.h"
#include "FontStuff.h"
#include <string.h>
/*----------------------------- Module Defines ----------------------------*/
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
****************************************************************************/
bool InitLEDService(uint8_t Priority)
{
ES_Event_t ThisEvent;
MyPriority = Priority;
CurrentState = InitLEDState;
puts ("\rStarting LED Service\r");
DB_printf ("Press any key to post key-stroke events to LED Service\r\n");
DB_printf ("Press any key to add character to display\r\n");
ES_InitDeferralQueueWith(DeferralQueue, ARRAY_SIZE(DeferralQueue));
// post the initial transition event
ThisEvent.EventType = ES_INIT;
if (ES_PostToService(MyPriority, ThisEvent) == true)
{
return true;
}
else
{
return false;
}
}
/****************************************************************************
Function
PostTemplateService
Parameters
EF_Event_t ThisEvent ,the event to post to the queue
Returns
bool false if the Enqueue operation failed, true otherwise
Description
Posts an event to this state machine's queue
Notes
Author
J. Edward Carryer, 10/23/11, 19:25
****************************************************************************/
bool PostLEDService(ES_Event_t ThisEvent)
{
return ES_PostToService(MyPriority, ThisEvent);
}
/****************************************************************************
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
****************************************************************************/
ES_Event_t RunLEDService(ES_Event_t ThisEvent)
{
ES_Event_t ReturnEvent;
ReturnEvent.EventType = ES_NO_EVENT; // assume no errors
switch (CurrentState)
{
case InitLEDState:
{
if (ThisEvent.EventType == ES_INIT)
{
while (false == DM_TakeInitDisplayStep());
puts ("LED Service:");
DB_printf ("\rES_INIT received in LED Service\r\n");
CurrentState = Waiting;
} //end if
} //end InitPState case
break;
case Waiting:
{
switch (ThisEvent.EventType)
{
// case ES_NEW_KEY:
// {
// printf("ES_NEW_KEY received with -> %c <- in Service 1\r\n",
// (char)ThisEvent.EventParam);
// DM_ScrollDisplayBuffer(4);
// DM_AddChar2DisplayBuffer(ThisEvent.EventParam);
// CurrentState = Writing;
// ThisEvent.EventType = ES_SEND;
// PostLEDService(ThisEvent);
// } //end New key case
// break;
break;
case ES_UPDATE_COL:
{
uint8_t WhichRow;
uint32_t shift[8];
data = (data << 1) | 0b01; //Creates a right to left progression
for (WhichRow = 0; WhichRow <= 7; WhichRow++)
{
shift[WhichRow] = (data & bullet[WhichRow]) << (31 -
ThisEvent.EventParam);
}
for (WhichRow = 0; WhichRow <= 7; WhichRow++)
{
DM_PutDataIntoBufferRow(shift[WhichRow], WhichRow);
}
CurrentState = Writing;
ThisEvent.EventType = ES_SEND;
PostLEDService(ThisEvent);
}
break;
case ES_BEGIN:
{
uint8_t WhichRow;
for (WhichRow = 0; WhichRow <= 7; WhichRow++)
{
DM_PutDataIntoBufferRow(0, WhichRow);
}
CurrentState = Writing;
ThisEvent.EventType = ES_SEND;
PostLEDService(ThisEvent);
case ES_ACTIVITY_TIMEOUT:
{
data = 0x00; //Reset display
ES_Timer_InitTimer(SCROLL_TIMER, 1000); //Reset Scroll Timer
messageIndex = 0;
sprintf(scoreChar, "%d", score); //Convert score to char array
printf("%c",scoreChar); //double checking
strcat(endMessage,scoreChar);
}
break;
case ES_ADD_SCORE:
{
score = score + ThisEvent.EventParam;
}
break;
case ES_TIMEOUT:
{
uint8_t messageSize = strlen(endMessage);
}
break;
default:
{}
break;
} //end Event switch
} //end Waiting case
break;
case Writing:
{
switch (ThisEvent.EventType)
{
case ES_SEND:
{
if (false == DM_TakeDisplayUpdateStep())
{
PostLEDService(ThisEvent);
}
else
{
CurrentState = Waiting;
ES_RecallEvents(MyPriority, DeferralQueue);
}
} //end Send case
break;
case ES_NEW_KEY:
{
ES_DeferEvent(DeferralQueue, ThisEvent);
}
break;
case ES_UPDATE_COL:
{
ES_DeferEvent(DeferralQueue, ThisEvent);
}
break;
case ES_ADD_SCORE:
{
ES_DeferEvent(DeferralQueue, ThisEvent);
}
break;
default:
;
} //end Event switch
} //end Writing case
break;
default:
;
} //end State switch
return ReturnEvent;
}
/***************************************************************************
private functions
***************************************************************************/