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 } }
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(); } }
// 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. }
void TicTacToeDisplay_touchScreenComputeBoardRowColumn(uint8_t* row, uint8_t* column) { int16_t x; int16_t y; uint8_t z; display_clearOldTouchData(); display_getTouchedPoint(&x,&y,&z); if( x < ONE_THIRD_WIDTH) { TTT_Display_setRow(0); *column = 0; } else if (x > TWO_THIRD_WIDTH) { // TTT_Display_setRow(1); *column = 2; } else { // TTT_Display_setRow(2); *column = 1; } if(y < ONE_THIRD_HEIGHT) { //TTT_Display_setColumn(0); *row = 0; } else if (y > TWO_THIRD_HEIGHT) { // TTT_Display_setColumn(1); *row = 2; } else { // TTT_Display_setColumn(2); *row = 1; } }
//looks at the touch data, and computes which row its in. void wamControl_touchScreenComputeBoardRowColumn(uint8_t* row, uint8_t* column) { display_clearOldTouchData(); display_getTouchedPoint(&WAMC_touchCursorX, &WAMC_touchCursorY, &WAMC_touchPressure); //need to relay this info to the Cursors //------------------------------------------------------------ //COMPUTE COLUMN if (WAMC_touchCursorX < WAMC_VERTICAL_LINE_0) //IS IT IN COLUMN 0 { *column = WAMC_COLUMN_0; } else if(WAMC_touchCursorX <= WAMC_VERTICAL_LINE_1) //is it in COLUMN 1 { *column = WAMC_COLUMN_1; } else if(WAMC_touchCursorX >= WAMC_VERTICAL_LINE_1) //is it in COLUMN 2 { *column = WAMC_COLUMN_2; } //------------------------------------------------------------ //COMPUTE ROW if (WAMC_touchCursorY < WAMC_HORIZONTAL_LINE_0) //IS IT IN ROW 0 { *row = WAMC_ROW_0; } else if(WAMC_touchCursorY <= WAMC_HORIZONTAL_LINE_1) //is it in ROW 1 { *row = WAMC_ROW_1; } else if(WAMC_touchCursorY >= WAMC_HORIZONTAL_LINE_1) //is it in ROW 2 { *row = WAMC_ROW_2; } }
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; } }
// 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" ); } } } }