A Mode State Machine
//----- PRIVATE DEFINES -----
private const int UM_STARTUP = 0;
private const int UM_IDLE = 1;
//----- PRIVATE OBJECTS -----
private int CurrentMode = -1;
private int CurrentModeLast = -1;
//------------------------------
//----- CHECK FOR NEW MODE -----
//------------------------------
ThisIsNewState = false;
if (CurrentModeLast != CurrentMode)
{
CurrentModeLast = CurrentMode;
ThisIsNewState = true;
}
//------------------------------------
//------------------------------------
//----- PROCESS THE CURRENT MODE -----
//------------------------------------
//------------------------------------
switch (CurrentMode)
{
case UM_STARTUP:
//-------------------
//-------------------
//----- STARTUP -----
//-------------------
//-------------------
if (ThisIsNewState)
{
//----- JUST ENTERED THIS MODE -----
}
//------------------------
//----- PROCESS MODE -----
//------------------------
break;
case UM_IDLE:
//-------------------------------
//-------------------------------
//----- IDLE - DEFAULT MODE -----
//-------------------------------
//-------------------------------
if (ThisIsNewState)
{
//----- JUST ENTERED THIS MODE -----
}
//------------------------
//----- PROCESS MODE -----
//------------------------
break;
} //switch (CurrentMode)
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.