Getting Started

(lily) #1

Chapter 10: C Structures


d to
{


else if (input != KEY_NULL) // If not, and input not NULL

the StateMachine function to examine the
// MENU_NEXTSTATE array to find the nextstate
nextstate = StateMachine(state, input);
}


// Now we know what the next state is
if (nextstate != state) // Do only if the state has changed
{
state = nextstate; // The state changed, so reset it


// Read the MENU_STATE array until we find the entry
// matching the current state
for (i=0; pgm_read_byte(&menu_state[i].state); i++)
{
// If we find the entry
if (pgm_read_byte(&menu_state[i].state) == state)
{
// We load the state variables from that entry
statetext =(PGM_P)pgm_read_word(&menu_state[i].pText);
pStateFunc
=(PGM_VOID_P)pgm_read_word(&menu_state[i].pFunc);
// And we exit the loop
break;
}
// If we found an entry for the pStateFunc, we now loop
back
// to the top were we run it.
}
}
} //End Main loop


return 0;
}


Of course, the actual Butterfly main() function does a lot of other stuff, but this
should help you understand the menu state machine part.


if (pStateFunc) // If a state function is pointe


// When a state function is pointed to, we must call it
// and get the results as the nextstate variable
nextstate = pStateFunc(input);
}


{
// We call

Free download pdf