Skip to content

Instantly share code, notes, and snippets.

@dheeptuck
Created June 19, 2019 18:18
Show Gist options
  • Save dheeptuck/aa114c991c6903bae45f483f3336ec62 to your computer and use it in GitHub Desktop.
Save dheeptuck/aa114c991c6903bae45f483f3336ec62 to your computer and use it in GitHub Desktop.
void StateMachineHandler()
{
int idx = 0;
if(EVT_NO_EVENT != eCurrentEvent)
{
for(;idx < sizeof(stStm)/sizeof(stStmRow); idx++)
{
if( (stStm[idx].pSrcState == stCurrentState) &&
(stStm[idx].eEvt == eCurrentEvent))
{
/// Clear event
eCurrentEvent = EVT_NO_EVENT;
/// Notify the state that the exit is imminent;
bIsStateAboutToExit = true;
stCurrentState();
/// Move to new state
stCurrentState = stStm[idx].pDestState;
/// Flag that this is the first entry to the state
bIsStateFirstEntry = true;
}
}
}
if(NULL != stCurrentState)
{
/// Run the state
stCurrentState();
/// Unfllag first entry
bIsStateFirstEntry = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment