void menuHandlerInit(void){ //In order to ensure the LEDs get cleared i8MainMenuState = X_MENU; setLEDAlternateFuncFlag(TRUE); turnOffAllLEDs(); i8MenuChangeFlag = 0; vTaskDelay(500);//Make sure the LED queue gets cleared setLEDState(u8LEDMainMenuMapping[i8MainMenuState], BLINK); setRedLEDs(MAX_BRIGHTNESS); }
int main ( void ) { enableLEDs(); turnOffAllLEDs(); while(1) { runOS(); PROGRAM_TICKS += 1; } return 0; };
void MenuStateMachine(void){ uint8_t u8ExitWithoutSavingFlag = TRUE; uint8_t u8MemCommand; static uint32_t u32defaultSettingsInitialValue; static uint8_t u8checkForDefaultSettings = FALSE; uint32_t u32TickCount; //Check to see if the encoder moved if(i8MenuChangeFlag != 0 && i8SubMenuState == SUBMENU_NOT_SELECTED){ changeMainMenuState(); resetBlink(); } //Check to see if the encoder switch is held down for 3 seconds. This is //the mechanism for defaulting the menu. if(u8MenuKeyPressFlag == TRUE){ //Start the timer. u32TickCount = xTaskGetTickCount(); u32defaultSettingsInitialValue = u32TickCount; u8checkForDefaultSettings = TRUE; }else{ //If the switch continues to be held down for 3 seconds, default the settings and exit the menu. if(u8checkForDefaultSettings == TRUE){ if(!READ_ENC_SWITCH){//Switch is held down. //Increment the timer u32TickCount = xTaskGetTickCount(); if((u32TickCount - u32defaultSettingsInitialValue) > DEFAULT_SETTINGS_TIME_LENGTH){ defaultSettings(); u8ExitWithoutSavingFlag = FALSE; u8MenuExitFlag = TRUE; u8checkForDefaultSettings = FALSE; } }else{ u8checkForDefaultSettings = FALSE; } } } switch(i8MainMenuState){ case X_MENU: case Y_MENU: case Z_MENU: //Handle the encoder switch press if(u8MenuKeyPressFlag == TRUE){ u8MenuKeyPressFlag = FALSE; //If no submenu has been selected, enter submenu mode if(i8SubMenuState == SUBMENU_NOT_SELECTED){ i8SubMenuState = RANGE; setLEDState(u8LEDMainMenuMapping[i8MainMenuState], ON); setLEDState(u8XYZSubMenuMapping[i8SubMenuState-1], BLINK); } else if(u8ParameterEditModeFlag == FALSE){ //Enter the submenu and modify the parameter u8ParameterEditModeFlag = TRUE; setLEDState(u8XYZSubMenuMapping[i8SubMenuState-1], ON); initializeXYZParameterMode(); } else{ //Lock in the selection and exit the menu. u8ExitWithoutSavingFlag = FALSE; u8MenuExitFlag = TRUE; } } //If it made it this far, then it's changing submenus if(i8MenuChangeFlag != 0){ //If we're not in parameter edit mode if(u8ParameterEditModeFlag == FALSE){ changeXYZSubMenuState(); resetBlink(); } else{ editXYZParameter(i8SubMenuState); } } break; case RECORD_MENU: case OVERDUB_MENU: case PLAYBACK_MENU: //Handle the encoder switch press if(u8MenuKeyPressFlag == TRUE){ u8MenuKeyPressFlag = FALSE; //If no submenu has been selected, enter submenu mode if(i8SubMenuState == SUBMENU_NOT_SELECTED){ i8SubMenuState = SOURCE; setLEDState(u8LEDMainMenuMapping[i8MainMenuState], ON); setLEDState(u8PlaySubMenuMapping[i8SubMenuState-1], BLINK); } else if(u8ParameterEditModeFlag == FALSE){ //Enter the submenu and modify the parameter u8ParameterEditModeFlag = TRUE; setLEDState(u8PlaySubMenuMapping[i8SubMenuState-1], ON); initializeRecParameterMode(i8MainMenuState-RECORD_MENU); } else{ //Locking in the change and exiting the menu. u8ExitWithoutSavingFlag = FALSE; u8MenuExitFlag = TRUE; } } //If it made it this far, then it's changing submenus if(i8MenuChangeFlag != 0){ //If we're not in parameter edit mode if(u8ParameterEditModeFlag == FALSE){ changeRecSubMenuState(); resetBlink(); } else{ editRecParameter(i8MainMenuState-RECORD_MENU); } } break; case LOAD_MENU: case STORE_MENU: //Store a sequence /*The first key press enters the mode. The next one issues a store * command*/ if(u8MenuKeyPressFlag == TRUE){ u8MenuKeyPressFlag = FALSE; if(i8MainMenuState == LOAD_MENU){ if(u8LoadModeFlag == FALSE){ //u8LoadModeFlag = TRUE; /*Set the LEDs on for locations which have a stored sequence. Flash the currently selected LED.*/ u8LoadModeFlag = initializeLoadStoreMode(); if(u8LoadModeFlag == 1){ i8SubMenuState = 1; } } else{ //Load the sequence flashLoadSequence(u8LoadStoreParameter); u8LoadModeFlag = FALSE; u8MenuExitFlag = TRUE; } }else{ if(u8StoreModeFlag == FALSE){ //u8StoreModeFlag = TRUE; u8StoreModeFlag = initializeLoadStoreMode(); if(u8StoreModeFlag == 1){ i8SubMenuState = 1; } } else{ //Store the sequence flashStoreSequence(u8LoadStoreParameter, getLengthOfRecording()); u8StoreModeFlag = FALSE; u8MenuExitFlag = TRUE; } } } //Handle the encoder if(u8StoreModeFlag == TRUE || u8LoadModeFlag == TRUE){ if(i8MenuChangeFlag != 0){ editLoadStoreParameter(); } } else{ i8MenuChangeFlag = 0; } break; case EFFECT_MENU: if(u8MenuKeyPressFlag == TRUE){ u8MenuKeyPressFlag = FALSE; if(u8EffectModeFlag == FALSE){ i8SubMenuState = 1; u8EffectModeFlag = TRUE; setLEDState(u8LEDMainMenuMapping[i8MainMenuState], ON); initializeEffectMode(); } else{ //Set the effect mode u8EffectModeFlag = FALSE; //Locking in the change and exiting the menu. u8ExitWithoutSavingFlag = FALSE; u8MenuExitFlag = TRUE; } } //Handle the encoder if(u8EffectModeFlag == TRUE){ if(i8MenuChangeFlag != 0){ editEffectParameter(); } } else{ i8MenuChangeFlag = 0; } break; case CLOCK_MENU: if(u8MenuKeyPressFlag == TRUE){ u8MenuKeyPressFlag = FALSE; if(i8SubMenuState == SUBMENU_NOT_SELECTED){ u8ClockModeFlag = TRUE; i8SubMenuState = SYNC; setLEDState(u8LEDMainMenuMapping[i8MainMenuState], ON); setLEDState(u8LEDMainMenuMapping[i8SubMenuState-1], BLINK); } else if(u8ParameterEditModeFlag == FALSE){ //Enter the submenu and modify the parameter u8ParameterEditModeFlag = TRUE; setLEDState(u8LEDMainMenuMapping[i8SubMenuState-1], ON); initializeClockMode(); } else{ //Set the effect mode u8ClockModeFlag = FALSE; //Locking in the change and exiting the menu. u8ExitWithoutSavingFlag = FALSE; u8MenuExitFlag = TRUE; } } //If it made it this far, then it's changing submenus if(i8MenuChangeFlag != 0){ //If we're not in parameter edit mode if(u8ParameterEditModeFlag == FALSE){ changeClockSubMenuState(); resetBlink(); } else{ editClockParameter(); } } break; default: break; } /*When we exit the menu, we have to reset the LIVE PLAY INTERACTION stuff or we could end up in a weird state.*/ if(u8MenuExitFlag == TRUE){ /*If the main switch is pressed, then we exit without saving the change and need to reset the parameter.*/ if(u8ExitWithoutSavingFlag == TRUE){ resetMenuParameter(); } else{ //Write the file table with the stored settings. copyCurrentSettingsToFileTable(0); u8MemCommand = WRITE_FLASH_FILE_TABLE; xQueueSend(xMemInstructionQueue, &u8MemCommand, 0); } resetEncoderLiveInteraction();//Encoder turning needs to be reset to not get spurious changes. i8SubMenuState = SUBMENU_NOT_SELECTED; u8MenuExitFlag = FALSE; setLEDAlternateFuncFlag(FALSE);//LEDs back to indicating position turnOffAllLEDs();//Reset the LEDs state setRedLEDs(HALF_BRIGHTNESS); setMenuModeFlag(FALSE);//Master control knows menu is over u8ParameterEditModeFlag = FALSE; u8LoadModeFlag = FALSE; u8StoreModeFlag = FALSE; } }
void runOS() { setLED( PROGRAM_TICKS%32, 1 ); wait( 1000000 ); turnOffAllLEDs(); wait( 1000000 ); }