//********************************************************************************************* // verifySequence_disable() // disables the verify sequence state machine, erases the simon buttons // disables the button handler state machine //********************************************************************************************* void verifySequence_disable() { simonbuttonHandler_disable(); simonDisplay_eraseAllButtons(); verify_enable = false; }
// Standard tick function. void verifySequence_tick(){ // state actions switch (verifyState){ case init_st: break; case enable_button_st: // enabble the buttonHandler state machine buttonHandler_enable(); break; case wait_for_release_st: // Increment timout value while waiting for the display to be relased timeOut++; break; case verify_region_st: // disable the buttonhandler state machine buttonHandler_disable(); // if the user tapped the wrong sequence, raise the errorFlag if (globals_getSequenceValue(index) != buttonHandler_getRegionNumber()){ userErrorFlag = 1; } break; case increment_st: break; case done_st: break; } // state transitions switch (verifyState){ case init_st: // wait for the state machine to be enabled if (verifyEnableFlag) { // reset all flags and counters index = 0; completeFlag = 0; timeOutFlag = 0; userErrorFlag = 0; timeOut = 0; verifyState = enable_button_st; } break; case enable_button_st: verifyState = wait_for_release_st; break; case wait_for_release_st: // if the timout value is reached if (timeOut == TIME_OUT_VALUE){ // raise the timeOutFlag timeOutFlag = 1; // raise the completeFlag completeFlag = 1; // erase all the buttons simonDisplay_eraseAllButtons(); // and go to done verifyState = done_st; } // if the display is currently touched, reset the counter. // I didn't want it to timeout if the user is holding the buton. else if (display_isTouched()){ timeOut = 0; } // otherwise if the display was released else if (buttonHandler_releaseDetected()){ // go check the region pressed against the reion in the sequence verifyState = verify_region_st; } break; case verify_region_st: verifyState = increment_st; break; case increment_st: // if we're at the end of the sequence if (index == (globals_getSequenceIterationLength())){ // raise completeFlag to indicate it's over completeFlag = 1; // erase all the buttons simonDisplay_eraseAllButtons(); // go to done verifyState = done_st; } // if the user made an error else if (userErrorFlag){ // raise completeFlag completeFlag = 1; // erase the buttons simonDisplay_eraseAllButtons(); // go to done verifyState = done_st; } else { // otherwise increase the index and verify the next button // in the sequence index++; verifyState = enable_button_st; } break; case done_st: // if the enable flag goes low if (!verifyEnableFlag) { // go to init verifyState = init_st; } break; } }