Esempio n. 1
0
void TicTacToeDisplay_runTest()
{
	display_init();
		TicTacToeDisplay_init();

	char number = buttons_read();
	char read = number & HEX_F;
	char s_read = switches_read();
	display_clearOldTouchData();

	bool go = true;
	while(go)
	{
		s_read = switches_read();
		number = buttons_read();
		read = number & HEX_F;
		utils_msDelay(50);


	if(display_isTouched())
	{
		utils_msDelay(50);
		display_clearOldTouchData();

		if(display_isTouched())
			TicTacToeDisplay_touchScreenComputeBoardRowColumn(&row, &column);

		if(s_read == 0x1)
		{
		TicTacToeDisplay_drawO(row, column);display_clearOldTouchData();
		}

		else
		{
		TicTacToeDisplay_drawX(row, column);display_clearOldTouchData();
		}


		display_clearOldTouchData();


	}
	if((read & 0x1) == HEX_ONE)
	{
		TicTacToeDisplay_init();
	}

	 if((read & 0x2) == 0x02)
	{
		TicTacToeDisplay_complete();
		go = false;
	}



	display_clearOldTouchData();


	}
}
Esempio n. 2
0
// I used a busy-wait delay (utils_msDelay) that uses a for-loop and just blocks until the time has passed.
// When you implement the game, you CANNOT use this function as we discussed in class. Implement the delay
// using the non-blocking state-machine approach discussed in class.
void simonDisplay_runTest(uint16_t touchCount) {
  display_init();  // Always initialize the display.
  char str[MAX_STR];   // Enough for some simple printing.
  uint8_t regionNumber;
  uint16_t touches = 0;
  // Write an informational message and wait for the user to touch the LCD.
  display_fillScreen(DISPLAY_BLACK);        // clear the screen.
  display_setCursor(0, display_height()/2); //
  display_setTextSize(TEXT_SIZE);
  display_setTextColor(DISPLAY_RED, DISPLAY_BLACK);
  sprintf(str, "Touch and release to start the Simon demo.");
  display_println(str);
  display_println();
  sprintf(str, "Demo will terminate after %d touches.", touchCount);
  display_println(str);
  while (!display_isTouched());       // Wait here until the screen is touched.
  while (display_isTouched());        // Now wait until the touch is released.
  display_fillScreen(DISPLAY_BLACK);  // Clear the screen.
  simonDisplay_drawAllButtons();      // Draw all of the buttons.
  bool touched = false;  	      // Keep track of when the pad is touched.
  int16_t x, y;  		      // Use these to keep track of coordinates.
  uint8_t z;      		      // This is the relative touch pressure.
  while (touches < touchCount) {  // Run the loop according to the number of touches passed in.
    if (!display_isTouched() && touched) {         // user has stopped touching the pad.
      simonDisplay_drawSquare(regionNumber, true); // Erase the square.
      simonDisplay_drawButton(regionNumber);	   // DISPLAY_REDraw the button.
      touched = false;															// Released the touch, set touched to false.
    } else if (display_isTouched() && !touched) {   // User started touching the pad.
      touched = true;                               // Just touched the pad, set touched = true.
      touches++;  																	// Keep track of the number of touches.
      display_clearOldTouchData();  // Get rid of data from previous touches.
      // Must wait this many milliseconds for the chip to do analog processing.
      utils_msDelay(TOUCH_PANEL_ANALOG_PROCESSING_DELAY_IN_MS);
      display_getTouchedPoint(&x, &y, &z);                  // After the wait, get the touched point.
      regionNumber = simonDisplay_computeRegionNumber(x, y);// Compute the region number.
      simonDisplay_drawSquare(regionNumber, false);	    // Draw the square (erase = false).
    }
  }
  // Done with the demo, write an informational message to the user.
  display_fillScreen(DISPLAY_BLACK);        // clear the screen.
  display_setCursor(0, display_height()/2); // Place the cursor in the middle of the screen.
  display_setTextSize(2);                   // Make it readable.
  display_setTextColor(DISPLAY_RED, DISPLAY_BLACK);  // red is foreground color, black is background color.
  sprintf(str, "Simon demo terminated");    // Format a string using sprintf.
  display_println(str);                     // Print it to the LCD.
  sprintf(str, "after %d touches.", touchCount);  // Format the rest of the string.
  display_println(str);  // Print it to the LCD.
}
Esempio n. 3
0
void ticTacToeDisplay_runTest()
{
    while(1) //until button 1 is pressed
    {
        while(buttons_read() != (TICTACTOEDISPLAY_BTN0_ON))//until button 0 is pressed
        {
            if(buttons_read() == (TICTACTOEDISPLAY_BTN1_ON))//button has been pressed
            {
                display_setTextSize(TICTACTOEDISPLAY_TEXT_SIZE);  // this sets the text size
                display_setCursor(TICTACTOEDISPLAY_HALF_WIDTH-TICTACTOEDISPLAY_ONE_THIRD_WIDTH, //position x coordinate of cursor
                        TICTACTOEDISPLAY_HALF_HEIGHT - TICTACTOEDISPLAY_ONE_SIXTH_HEIGHT);//position y coordinate of cursor
                display_println("Game Over!");//print to the lcd
                return;//return out of both loops immediately
            }

            if(display_isTouched())
            {
                display_clearOldTouchData(); // Throws away all previous touch data.
                uint8_t row, column;
                ticTacToeDisplay_touchScreenComputeBoardRowColumn(&row, &column);//compute location of square
                if(switches_read() == TICTACTOEDISPLAY_SWITCH0_ON)//SW0 is up
                {
                    ticTacToeDisplay_drawO(row, column);//draw O character
                }
                if(switches_read() == TICTACTOEDISPLAY_SWITCH0_OFF)//SW0 is down
                {
                    ticTacToeDisplay_drawX(row, column);//draw X character
                }
            }
        }
        ticTacToeDisplay_init();//clear the screen
    }
}
Esempio n. 4
0
// Test function that can be called from main() to demonstrate milestone 1.
// Invoking this function should provide the same behavior as shown in the Milestone 1 video.
void wamDisplay_runMilestone1_test()
{
    wamDisplay_point_t steve;
    steve.x = 1;
    steve.y = 1;

    while(1)
    {
        wamDisplay_drawSplashScreen();
        while(!display_isTouched()); //wait for touch
        wamDisplay_drawMoleBoard();
        wamDisplay_drawScoreScreen();
        while(!display_isTouched());//wait for touch
        wamDisplay_drawMole(&steve);
        while(!display_isTouched());
        wamDisplay_eraseMole(&steve);
        while(!display_isTouched());
        wamDisplay_drawGameOverScreen(); //show score
        while(!display_isTouched()); //wait for touch
    }
}
Esempio n. 5
0
//*********************************************************************************************
// verifySequence_tick()
// verify sequence state machine
//*********************************************************************************************
void verifySequence_tick()
{
	switch(verify_state)
	{

    //verify_init
    //Resets all error cases and sets all timers to zero
    //Gets the current sequence length
    //enables the button handler
	case verify_init:
		verify_isTimeOutError = V_DISABLED;
		verify_isUserInputError = V_DISABLED;
		verify_completed = V_DISABLED;
		timer_waiting = INIT_ZERO;
		verifyValue = INIT_ZERO;
            
		verify_current_sequence_length = globals_getSequenceIterationLength();

		if(verify_enable)
		{
			simonbuttonHandler_enable();
			verify_state = verify_waiting;
		}
		break;

            
    //verify_waiting
    //provides the user with time to touch the screen
    //if the user does not touch before TIMER_EXPIRED_VALUE, verify_isTimeOutError occurs
    //disables the button handler after waiting is over
	case verify_waiting:
        timer_waiting++;
        if(timer_waiting == TIMER_EXPIRED_VALUE)
        {
            verify_isTimeOutError = V_ENABLED;
            simonbuttonHandler_disable();

            verify_state = verify_complete;
        }

        if(display_isTouched())
        {
            if(!simonbuttonHandler_releaseDetected() && timer_waiting < TIMER_EXPIRED_VALUE)
            {
                verify_state = verify_wait_release;
            }
        }
        break;

            
    //verify_wait_release
    //waits for the user to release the touch screen and disables the button handler
	case verify_wait_release:

        if(simonbuttonHandler_releaseDetected())
        {
            simonRegion = simonbuttonHandler_getRegionNumber();
            timer_waiting = INIT_ZERO;
            simonbuttonHandler_disable();
               
            verify_state = verify_validate;
        }
        break;


    //verify_validate
    //compares the verifyValue to the sequence value to see if the sequence is over
    //if they are not the same, user input error has occurred
    case verify_validate:

        if(simonRegion == globals_getSequenceValue(verifyValue))
        {
            verifyValue++;
            if(verifyValue == verify_current_sequence_length)
            {
                verifyValue = INIT_ZERO;
                verify_state = verify_complete;
            }
                
            else
            {
                timer_waiting = INIT_ZERO;
                verify_state = verify_waiting;
                simonbuttonHandler_enable();
            }
        }
            
        else
        {
            verify_isUserInputError = V_ENABLED;
            verify_state = verify_complete;
        }
        break;


    //verify_complete
    //signifies the state machine has completed
    //restarts if and only if the state machine is enabled
    case verify_complete:

        verify_completed = V_ENABLED;
        timer_waiting = INIT_ZERO;

        if(verify_enable)
        {
            verify_state = verify_init;
        }
        break;


	default:
            verify_state = verify_init;
            break;
	}
}
Esempio n. 6
0
void verifySequence_tick() {
  static uint16_t index = 0;
  static uint16_t timeOutTimer = 0; // counter to track whether a timeout occurs

  /////////////////////////////////
  // Perform state action first. //
  /////////////////////////////////
  switch (verifySequence_state) {
    case init_st:
      isTimeOutError = false;
      isUserInputError = false;
      index = 0;
      timeOutTimer = 0;
      break;
    case wait_for_timeout_st:
      timeOutTimer++;
      buttonHandler_enable();
      break;
    case wait_for_release_st:
      break;
    case verification_st:
      break;

    case complete_st:

      break;
    default:
      printf("Default case hit in verifySequence tick.\n");
      break;
  }

  ////////////////////////////////
  // Perform state update next. //
  ////////////////////////////////
  switch (verifySequence_state) {
    case init_st:
      if (enabled) {
        buttonHandler_enable();
        verifySequence_state = wait_for_timeout_st;
      }
      else {
        verifySequence_state = init_st;
      }
      break;
    case wait_for_timeout_st:
      if(display_isTouched()) {
        timeOutTimer = 0;
        verifySequence_state = wait_for_release_st;
      }
      // If the use waits too long before doing anything
      else if (timeOutTimer >= WAIT_TIMEOUT)
      {
        //printf("userTouchTimer: %d", userTouchTimer);
        isTimeOutError = true;
        timeOutTimer = 0;
        verifySequence_state = complete_st;
      }
      else {
        verifySequence_state = wait_for_timeout_st;
      }
      break;
    case wait_for_release_st:
      if (buttonHandler_releaseDetected())
      {
        buttonHandler_disable();
        verifySequence_state = verification_st;
      }
      else {
        verifySequence_state = wait_for_release_st;
      }
      break;
    case verification_st:
      uint8_t tempSequenceValue, tempRegionNumber;
      tempSequenceValue = globals_getSequenceValue(index);
      tempRegionNumber = buttonHandler_getRegionNumber();

      if(tempSequenceValue == tempRegionNumber) { //user touched the correct square
        // If that was the last square
        if (globals_getSequenceIterationLength() == (index + 1)) { //because index starts at 0 and length at 1
          verifySequence_state = complete_st;
        }
        else {
          index++;
          verifySequence_state = wait_for_timeout_st;
        }
      }
      else {
        isUserInputError = true;
        //printf("USER INPUT ERROR");
        verifySequence_state = complete_st;
      }
      break;
    case complete_st:
      if (!enabled) {
        verifySequence_state = init_st;
      }
      else {
        verifySequence_state = complete_st;
      }
      break;
    default:
      printf("Default case hit in verifySequence tick.\n");
      break;
  }
}
Esempio n. 7
0
    void simonControl_tick()
    {
        SC_debugStatePrint();


        /// //ACTIONS***********************************************************************
        switch(SC_State)
        {
        case SC_init_st:
            //do nothing
            break;
        case SC_instructions_st:
            display_setTextColor(DISPLAY_WHITE);
            display_setCursor(SC_INSTRUCTION_CURSORX,SC_INSTRUCTION_CURSORY);
            display_setTextSize(SC_INSTRUCTION_TEXTSIZE);
            display_println(SC_INSTRUCTIONS);
            break;
        case SC_wait_first_touch_st:
            // do nothing
            break;
        case SC_get_sequence_st:
            SC_currentScore = 0; //reset
            SC_setSequence();
            break;
        case SC_flash_sequence_st:
            //do nothing
            break;
        case SC_verify_sequence_st:
            //do nothing
            break;
        case SC_error_st:
            errorTimer++;
            if (verifySequence_isTimeOutError()) // user didn't press
            {
                display_setTextSize(SC_TEXTSIZE);
                display_println(ERROR_MESSAGE_TIMEOUT);
            }
            else if (verifySequence_isUserInputError()) //pressed wrong input
            {
                display_setTextSize(SC_TEXTSIZE);
                display_println(ERROR_MESSAGE_INPUT);
            }
            verifySequence_disable(); //set this here so we can read these flags. disable resets the error flags
            break;
        case SC_print_score_st:
            sprintf(maxScoreString, SC_HIGHSCORE_MESSAGE, SC_maxScore);
            display_setTextSize(SC_TEXTSIZE); //decrease text size
            display_println(maxScoreString);
            //reset scores, index, and sequence
            SC_currentIndex = 1; //reset to 1. since this is sequence length, when we setSequence, don't put to zero
            SC_maxScore = 0; //reset
            errorTimer = 0; //reset timer
            lvlMessageTimer = 0;
            break;
        case SC_level_complete_st:
            lvlMessageTimer++;
            if(printFlag) //set a flag so it doesn't keep being printed
            {
                display_println(SC_LVL_MESSAGE);
                printFlag = false; //switch flag
            }
            break;
        default:
            printf(SC_ERROR_MESSAGE); //invalid state
            break;
        }


        //TRANSITIONS***********************************************************************
        switch(SC_State)
        {
        case SC_init_st:
            SC_State = SC_instructions_st; //just go to instructions
            break;
        case SC_instructions_st:
            SC_State = SC_wait_first_touch_st; //go wait after drawing.
            break;
        case SC_wait_first_touch_st:
            if (display_isTouched()) //if touched, move ahead
            {
                SC_State = SC_get_sequence_st;
                display_fillScreen(DISPLAY_BLACK); //clear screen of instructions
            }
            break;
        case SC_get_sequence_st:
            SC_State = SC_flash_sequence_st;
            flashSequence_enable();
            break;
        case SC_flash_sequence_st:
            if (flashSequence_completed())
            {
                SC_State = SC_verify_sequence_st; //go to verify
                flashSequence_disable(); //disable flash machine
                simonDisplay_drawAllButtons(); //draw the buttons upon exit
                verifySequence_enable();
            }
            break;
        case SC_verify_sequence_st:
            if (verifySequence_isComplete()) //done verifying
            {
                //if there a time out error or wrong input error
                if (verifySequence_isTimeOutError() || verifySequence_isUserInputError()) //no errors
                {
                    SC_State = SC_error_st;
                    display_fillScreen(DISPLAY_BLACK); //clear buttons off screen
                }
                //level complete
                else if (globals_getSequenceIterationLength() == SC_sequence_length)
                {
                    SC_sequence_length++;
                    SC_State = SC_level_complete_st;
                    verifySequence_disable();
                    display_fillScreen(DISPLAY_BLACK); //clear buttons off screen
                    SC_currentIndex = 1; //reset
                    SC_maxScore = SC_currentScore;
                }
                else
                {
                    SC_State = SC_flash_sequence_st;
                    flashSequence_enable();
                    SC_currentIndex++; //how many to flash?
                    globals_setSequenceIterationLength(SC_currentIndex); //udate how many to falsh
                    verifySequence_disable();
                    display_fillScreen(DISPLAY_BLACK); //clear buttons off screen
                    SC_currentScore++;
                    if (SC_currentScore > SC_maxScore) //before first level is complete, maxScore doesn't get set
                    {
                        SC_maxScore = SC_currentScore; //this mostly before first level is complete
                    }
                }
            }
            break;
        case SC_error_st:
            if (errorTimer >= SC_ERROR_EXPIRE)
            {
                SC_State = SC_print_score_st; //print highest score
                display_fillScreen(DISPLAY_BLACK);
            }

            break;
        case SC_print_score_st:
            SC_State = SC_instructions_st;
            SC_maxScore = 0; //reset the maxScore!
            sequenceSeed++; //change the seed
            break;
        case SC_level_complete_st:
            if (lvlMessageTimer > SC_LVL_MESSAGE_EXPIRE) //timed out
            {
                SC_State = SC_print_score_st;
            }
            else if (display_isTouched())
            {
                SC_State = SC_instructions_st;
                display_fillScreen(DISPLAY_BLACK); // clear screen
                sequenceSeed++; //change the seed
                printFlag = true; //rest print flag
            }
            break;
        default:
            printf(SC_ERROR_MESSAGE);
            break;
        }

    }
Esempio n. 8
0
void ticTacToeControl_tick() //actions and transitions of state machine
{
    debugStatePrint(); //print state for debugging

    switch (TTT_State) //state machine actions
    {
    case TTT_init_st: //inital entry state
        readTimer = 0; //initialize read timer
        firstTouchTimer = 0; //set to zero
        adTimer = 0; //set to zerio
        break;
    case TTT_draw_instructions_st:
        //draw print the instructions
        display_setTextSize(TEXT_SIZE); //how big
        display_setTextColor(DISPLAY_WHITE);//set the color
        display_setCursor(INSTRUCTIONS_LOCATION_X, INSTRUCTIONS_LOCATION_Y);
        display_println(INSTRUCTIONS);//print instructions
        break;
    case TTT_let_user_read_st:
        readTimer++; //increase read timer
        break;
    case TTT_wait_first_touch_st:
        firstTouchTimer++; //increment first touch wait timer
        break;
    case TTT_wait_for_settle_st:
        adTimer++; //increment timer for settling
        break;
    case TTT_computer_play_st:
        if (playerX) //computer is O
        {
            minimax_computeNextMove(&currentBoard, false, &controlTouchRow, &controlTouchColumn); //its always computing computers move, so just set the bool to false
            ticTacToeDisplay_drawO(controlTouchRow, controlTouchColumn);
            //mark that board space
            currentBoard.squares[controlTouchRow][controlTouchColumn] = MINIMAX_OPPONENT_SQUARE;
        }

        else //computer went first, is X
        {
            minimax_computeNextMove(&currentBoard, false, &controlTouchRow, &controlTouchColumn); //its always computing computers move, so just set the bool to false
            ticTacToeDisplay_drawX(controlTouchRow, controlTouchColumn);
            //mark that board space
            currentBoard.squares[controlTouchRow][controlTouchColumn] = MINIMAX_OPPONENT_SQUARE;
        }

        break;
    case TTT_user_play_st:
        //read button value here, and check in transitions
        newBTNValue = buttons_read();

        invalidMoveFlag = false; // reset the flag

        //reset wait for settle timer
        adTimer = 0;

        if (playerX) //player went first, is X
        {
            ticTacToeDisplay_touchScreenComputeBoardRowColumn(&controlTouchRow, &controlTouchColumn);
            if(currentBoard.squares[controlTouchRow][controlTouchColumn] == MINIMAX_EMPTY_SQUARE) //check square is empty
            {
                ticTacToeDisplay_drawX(controlTouchRow, controlTouchColumn); //draw the x
                //mark that board space
                currentBoard.squares[controlTouchRow][controlTouchColumn] = MINIMAX_PLAYER_SQUARE; //mark move in board
            }
            else
                invalidMoveFlag = true; //player tried to go in occupied square
        }

        else //player is O
        {
            ticTacToeDisplay_touchScreenComputeBoardRowColumn(&controlTouchRow, &controlTouchColumn);
            if(currentBoard.squares[controlTouchRow][controlTouchColumn] == MINIMAX_EMPTY_SQUARE) //check square is empty
            {
                ticTacToeDisplay_drawO(controlTouchRow, controlTouchColumn); //draw the O
                //mark that board space
                currentBoard.squares[controlTouchRow][controlTouchColumn] = MINIMAX_PLAYER_SQUARE; //mark move in board
            }
            else
                invalidMoveFlag = true; //player tried to go in occupied square
        }
        break;
    case TTT_wait_touch_st:
    //just wait
    case TTT_end_st:
        //read button value here, and check in transitions
        //only reset at end game
        newBTNValue = buttons_read();

    default:
        break;
    }



    //////////////////////////////////////////////////////////////////////////////////////////////////



    switch (TTT_State) //state machine transitions
    {
    case TTT_init_st: //inital entry state
        TTT_State = TTT_draw_instructions_st; //move to instructions state
        break;
    case TTT_draw_instructions_st:
        TTT_State = TTT_let_user_read_st; //go straight to reading after instructions are drawn
        break;
    case TTT_let_user_read_st:
        if (readTimer == TTT_READ_EXPIRED)
        {
            TTT_State = TTT_wait_first_touch_st; //wait for touching
            ticTacToeDisplay_reset();//draw empty board. mealey action
        }
        break;
    case TTT_wait_first_touch_st:
    {
        if (firstTouchTimer == TTT_FIRST_TOUCH_EXPIRED) //if the wait is expired
        {
            //computer goes first. computer is X
            TTT_State = TTT_computer_play_st;
            playerX = false;
        }
        else if (display_isTouched()) //human touched a spot
        {
            //human goes first. is X
            TTT_State = TTT_wait_for_settle_st;
            playerX = true;
        }
    }
    break;
    case TTT_wait_for_settle_st:
        if (adTimer == ADTIMER_EXPIRE) //gave touch screen time to settle
        {
            TTT_State = TTT_user_play_st; //go to user play
        }
        break;
    case TTT_computer_play_st:
        // if board full, go to end game
        if (ticTacToeControl_checkEndGame(&currentBoard, false)) //pass in the board, does matter what the bool is, just need an endgame score
            TTT_State = TTT_end_st;
        else
            TTT_State = TTT_wait_touch_st; //go to place to wait for player to touch
        break;
    case TTT_user_play_st:
        if (ticTacToeControl_checkEndGame(&currentBoard, true)) //pass in the board, does matter what the bool is, just need an endgame score
            TTT_State = TTT_end_st;

        else if(invalidMoveFlag) //player tried to go in occupied space
        {
            TTT_State = TTT_wait_touch_st; //wait for another touch
        }

        else
            TTT_State = TTT_computer_play_st; //go to computer move


        break;
    case TTT_wait_touch_st:
        if (ticTacToeControl_checkEndGame(&currentBoard, playerX)) //pass in the board, does matter what the bool is, just need an endgame score
            TTT_State = TTT_end_st;
        else if (display_isTouched()) //done waiting
        {
            TTT_State = TTT_wait_for_settle_st; //go settle state
        }
        break;
    case TTT_end_st:
        ticTacToeControl_checkResetBTN(); //check if button has been pressed,
        break;
    default:
        printf("ERROR: missed transition\n\r");
        break;
    }
}
void clockControl_tick() {

	/*
	 * Below is the implementation of our state machine ClkStates.
	 * Note that there is an added state called touch_start_st.  This
	 * is added in addition to the init state to await the initial
	 * touch of the display before incrementing.
	 *
	 * Another functionality that I added was in the waiting_for_touch_st.
	 * A counter i increments to 100 before calling the advanceTimeOneSecond()
	 * function.  This allows the timer to increment every second.
	 *
	 * See the lab 4 description for an illustration of the state machine
	 */

	switch(ClkState) {


		// All states are explicitly shown in the case statements
		// Assigning ClkState indicates a state change
		case(init_st):
				ClkState = touch_start_st;
			break;
		case(touch_start_st):		//Added state waits for first touch

				// Transitions when display is touched
				if (display_isTouched()) {
					ClkState = waiting_for_touch_st;
				}

			break;
		case(waiting_for_touch_st):
				// All timers reset to zero, and i increments
				adTimer = 0;
				autoTimer = 0;
				rateTimer = 0;
				i++;

				// This added if statement waits 1 second to increment using counter i
				if ( i == CLKCTRL_IMAX) {
					clockDisplay_advanceTimeOneSecond();
					i=0;
				}

				// Transitions when display is touched
				if(display_isTouched()) {
					display_clearOldTouchData();
					ClkState = ad_timer_running_st;
				}

			break;
		case(ad_timer_running_st):
				// adTimer incremented as Moore action
				adTimer = adTimer + CLKCTRL_EXPIRED_VALUE;

				// If user continues holding display, transiton auto increment state
				if (display_isTouched() && adTimer == CLKCTRL_EXPIRED_VALUE) {
					ClkState = auto_timer_running_st;
				}

				// If display tapped, one increment/decrement will occur as Mealy
				else if (!display_isTouched() && adTimer == CLKCTRL_EXPIRED_VALUE) {
					clockDisplay_performIncDec();
					ClkState = waiting_for_touch_st;
				}

			break;
		case(auto_timer_running_st):
				// autoTimer incremented
				autoTimer = autoTimer + CLKCTRL_AUTOTIMER_INC;

				// Increment ceases as display released
				if (!display_isTouched()) {
					clockDisplay_performIncDec();
					ClkState = waiting_for_touch_st;
				}

				// Waits for .5 seconds before auto inc/dec state transitions
				else if (display_isTouched() && autoTimer == CLKCTRL_EXPIRED_VALUE) {
					clockDisplay_performIncDec();
					ClkState = rate_timer_running_st;
				}

			break;
		case(rate_timer_running_st):
				// Controls the auto increment timing to 10x a second
				rateTimer = rateTimer + CLKCTRL_AUTOTIMER_INC ;

				// Stops increment as display is released
				if (!display_isTouched()) {
					clockDisplay_performIncDec();
					ClkState = waiting_for_touch_st;
				}

				// Loop that continues increment
				else if (display_isTouched() && rateTimer == CLKCTRL_EXPIRED_VALUE) {
					ClkState = rate_timer_expired_st;
				}

			break;
		case(rate_timer_expired_st):
				// rateTimer reset to control transition rate
				rateTimer = 0;

				// Loop that continues increment
				if (display_isTouched()) {
					clockDisplay_performIncDec();
					ClkState = rate_timer_running_st;
				}

				// Stops increment as display is released
				else if (!display_isTouched()) {
					ClkState = waiting_for_touch_st;
				}

			break;
		default:

			break;


	}
}
// Test function that verifies the inc/dec function of each clock element and the touch feature
void clockDisplay_runTest() {

	for (uint32_t i = 0 ; i < CLOCKDISPLAY_ROLL_CONST1 ; i++) {
		utils_msDelay(CLOCKDISPLAY_RUNTEST_CONST);
		clockDisplay_IncSec();
	}

	for (uint32_t i = 0 ; i < CLOCKDISPLAY_ROLL_CONST1 ; i++) {
		utils_msDelay(CLOCKDISPLAY_RUNTEST_CONST);
		clockDisplay_IncMin();
	}

	for (uint32_t i = 0 ; i < CLOCKDISPLAY_ROLL_CONST1 ; i++) {
		utils_msDelay(CLOCKDISPLAY_RUNTEST_CONST);
		clockDisplay_IncHr();
	}

	clockDisplay_Clr_Time();
	clockDisplay_updateTimeDisplay(true);


	for (uint32_t i = 0 ; i < CLOCKDISPLAY_ROLL_CONST1 ; i++) {
		utils_msDelay(CLOCKDISPLAY_RUNTEST_CONST);
		clockDisplay_DecSec();
	}

	for (uint32_t i = 0 ; i < CLOCKDISPLAY_ROLL_CONST1 ; i++) {
		utils_msDelay(CLOCKDISPLAY_RUNTEST_CONST);
		clockDisplay_DecMin();
	}

	for (uint32_t i = 0 ; i < CLOCKDISPLAY_ROLL_CONST1 ; i++) {
		utils_msDelay(CLOCKDISPLAY_RUNTEST_CONST);
		clockDisplay_DecHr();
	}

	clockDisplay_Clr_Time();
	clockDisplay_updateTimeDisplay(true);

	for (uint32_t i = 0 ; i < CLOCKDISPLAY_RUNTEST_CONST ; i++) {
		utils_msDelay(CLOCKDISPLAY_RUNTEST_CONST);
		clockDisplay_advanceTimeOneSecond();
	}

	int16_t x = 0;
	int16_t y = 0;
	uint8_t z = 0;
	uint8_t counter = 0;
	printf("touchscreen test:");
	while(1) {
		utils_msDelay(CLOCKDISPLAY_RUNTEST_CONST);
		clockDisplay_performIncDec();
		display_getTouchedPoint(&x,&y,&z);


		if (display_isTouched()) {
			printf("Coordinates (%u ,",x);
			printf(" %u)",y);
			printf("with pressure %u \n\r",z);
			counter++;
		}
		if (counter == CLOCKDISPLAY_ROLL_CONST2) {
			counter = 0;
		}
		x= 0;
		y= 0;
		z = 0;
	}
}
Esempio n. 11
0
    // Standard tick function.
    void wamControl_tick()
    {
        WAM_debugStatePrint(); //print out current state for debugging

        //ACTIONS ******************************************************
        switch(WAM_State)
        {
        case WAM_init_st:
            //do nothing
            break;
        case WAM_update_mole_tick_st:
            wamDisplay_updateAllMoleTickCounts();
            break;
        case WAM_activate_mole_st:
            wamDisplay_activateRandomMole();
            break;
        case WAM_settle_st:
            wamControl_settleTimer++; //increment the timer
            break;
        case WAM_whack_st:
            //compue touch point the rows and columns
            wamControl_touchScreenComputeBoardRowColumn(&touchRow, &touchColumn);
            //make a point, and assign it values
            wamDisplay_point_t whackSpot;
            whackSpot.x = touchColumn;
            whackSpot.y = touchRow;
            wamDisplay_whackMole(&whackSpot); //check for hit scuess
            break;
        }

        //TRANSITIONS **************************************************

        switch(WAM_State)
        {
        case WAM_init_st:
            WAM_State = WAM_activate_mole_st; //always go here first
            break;
        case WAM_update_mole_tick_st:
            if (wamDisplay_getActiveMoleCount() < wamControl_getMaxActiveMoles()) //if not max moles activated
            {
                WAM_State = WAM_activate_mole_st;
            }
            if (display_isTouched()) //touch has priority, so have it last
            {
                WAM_State = WAM_settle_st;
            }
            break;
        case WAM_activate_mole_st:
            WAM_State = WAM_update_mole_tick_st;
            break;
        case WAM_settle_st:
            if (wamControl_settleTimer >= SETTLE_TIMER_EXPIRE)
            {
                WAM_State = WAM_whack_st;
                wamControl_settleTimer = 0; //reset the timer
            }
            break;
        case WAM_whack_st:
            WAM_State = WAM_update_mole_tick_st;
            break;
        default:
            printf(WAM_STATE_ERROR);
            break;
        }
    }
Esempio n. 12
0
// 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;
    }
}
// After a touch has been detected and after the proper delay, this sets the row and column arguments
// according to where the user touched the board.
void ticTacToeDisplay_touchScreenComputeBoardRowColumn(uint8_t* row, uint8_t* column) {
	int16_t x = 0;
	int16_t y = 0;
	uint8_t z = 0;
	uint8_t rowval;
	uint8_t columnval;
	if(display_isTouched()) {
		display_clearOldTouchData();
		utils_msDelay(50);
		display_getTouchedPoint(&x, &y, &z);
		*row = 0;
		*column = 0;
		// column 0
		if (x <= display_width()/3) {


			//row 0
			if (y <=  display_height()/3) {
				rowval = 0;
				columnval = 0;
				if (ticTacToeDisplay_SW()) {
					ticTacToeDisplay_drawO(rowval, columnval);
				}
				else {
					ticTacToeDisplay_drawX(rowval, columnval);
				}
				printf("row 0 column 0 \n\r" );
			}
			//row 1
			else if (y <= 2* display_height()/3) {
				rowval = 1;
				columnval = 0;
				if (ticTacToeDisplay_SW()) {
					ticTacToeDisplay_drawO(rowval, columnval);
				}
				else {
					ticTacToeDisplay_drawX(rowval, columnval);
				}
				printf("row 1 column 0 \n\r" );
			}
			//row 2
			else {
				rowval = 2;
				columnval = 0;
				if (ticTacToeDisplay_SW()) {
					ticTacToeDisplay_drawO(rowval, columnval);
				}
				else {
					ticTacToeDisplay_drawX(rowval, columnval);
				}
				printf("row 2 column 0 \n\r" );

			}

		}
		// column 1
		else if (x <= 2*(display_width()/3) ) {

			//row 0
			if (y <=  display_height()/3) {
				rowval = 0;
				columnval = 1;
				if (ticTacToeDisplay_SW()) {
					ticTacToeDisplay_drawO(rowval, columnval);
				}
				else {
					ticTacToeDisplay_drawX(rowval, columnval);
				}
				printf("row 0 column 0 \n\r" );
			}
			//row 1
			else if (y <= 2* display_height()/3) {
				rowval = 1;
				columnval = 1;
				if (ticTacToeDisplay_SW()) {
					ticTacToeDisplay_drawO(rowval, columnval);
				}
				else {
					ticTacToeDisplay_drawX(rowval, columnval);
				}
				printf("row 1 column 0 \n\r" );
			}
			//row 2
			else {
				rowval = 2;
				columnval = 1;
				if (ticTacToeDisplay_SW()) {
					ticTacToeDisplay_drawO(rowval, columnval);
				}
				else {
					ticTacToeDisplay_drawX(rowval, columnval);
				}
				printf("row 2 column 0 \n\r" );

			}
		}

		// column 2
		else {

			//row 0
			if (y <=  display_height()/3) {
				rowval = 0;
				columnval = 2;
				if (ticTacToeDisplay_SW()) {
					ticTacToeDisplay_drawO(rowval, columnval);
				}
				else {
					ticTacToeDisplay_drawX(rowval, columnval);
				}
				printf("row 0 column 0 \n\r" );
			}
			//row 1
			else if (y <= 2* display_height()/3) {
				rowval = 1;
				columnval = 2;
				if (ticTacToeDisplay_SW()) {
					ticTacToeDisplay_drawO(rowval, columnval);
				}
				else {
					ticTacToeDisplay_drawX(rowval, columnval);
				}
				printf("row 1 column 0 \n\r" );
			}
			//row 2
			else {
				rowval = 2;
				columnval = 2;
				if (ticTacToeDisplay_SW()) {
					ticTacToeDisplay_drawO(rowval, columnval);
				}
				else {
					ticTacToeDisplay_drawX(rowval, columnval);
				}
				printf("row 2 column 0 \n\r" );

			}
		}
	}
}