Esempio n. 1
0
void ticTacToeDisplay_touchScreenComputeBoardRowColumn(uint8_t *row, uint8_t* column)
{
    int16_t x, y; //two variables used in getting location of touch
    uint8_t z; //returns pressure of touch
    display_getTouchedPoint(&x, &y, &z); // Returns the x-y coordinate point and the pressure (z).

    //Column 0
    if(x < TICTACTOEDISPLAY_ONE_THIRD_WIDTH)
    {
        *column = TICTACTOEDISPLAY_COLUMN_LEFT;//assign column pointer to 0
        if(y < TICTACTOEDISPLAY_ONE_THIRD_HEIGHT) //Row 0
        {
            *row = TICTACTOEDISPLAY_ROW_TOP;//assign row pointer to 0
        }
        else if(y < TICTACTOEDISPLAY_TWO_THIRD_HEIGHT && y >  TICTACTOEDISPLAY_ONE_THIRD_HEIGHT)//Row 1
        {
            *row = TICTACTOEDISPLAY_ROW_MIDDLE;//assign row pointer to 1
        }
        else if(y < TICTACTOEDISPLAY_PIXEL_HEIGHT && y >  TICTACTOEDISPLAY_TWO_THIRD_HEIGHT)//Row 2
        {
            *row = TICTACTOEDISPLAY_ROW_BOTTOM;//assign row pointer to 2
        }
    }

    //Column 1
    else if(x < TICTACTOEDISPLAY_TWO_THIRD_WIDTH && x > TICTACTOEDISPLAY_ONE_THIRD_WIDTH)
    {
        *column = TICTACTOEDISPLAY_COLUMN_MIDDLE;//assign column pointer to 1
        if(y < TICTACTOEDISPLAY_ONE_THIRD_HEIGHT)//Row 0
        {
            *row = TICTACTOEDISPLAY_ROW_TOP;//assign row pointer to 0
        }
        else if(y < TICTACTOEDISPLAY_TWO_THIRD_HEIGHT && y >  TICTACTOEDISPLAY_ONE_THIRD_HEIGHT)//Row 1
        {
            *row = TICTACTOEDISPLAY_ROW_MIDDLE;//assign row pointer to 1
        }
        else if(y < TICTACTOEDISPLAY_PIXEL_HEIGHT && y >  TICTACTOEDISPLAY_TWO_THIRD_HEIGHT)//Row 2
        {
            *row = TICTACTOEDISPLAY_ROW_BOTTOM;//assign row pointer to 2
        }
    }

    //Column 2
    else if(x < TICTACTOEDISPLAY_PIXEL_WIDTH && x > TICTACTOEDISPLAY_TWO_THIRD_WIDTH)
    {
        *column = TICTACTOEDISPLAY_COLUMN_RIGHT;//assign column pointer to 2
        if(y < TICTACTOEDISPLAY_ONE_THIRD_HEIGHT)//Row 0
        {
            *row = TICTACTOEDISPLAY_ROW_TOP;//assign row pointer to 0
        }
        else if(y < TICTACTOEDISPLAY_TWO_THIRD_HEIGHT && y >  TICTACTOEDISPLAY_ONE_THIRD_HEIGHT)//Row 1
        {
            *row = TICTACTOEDISPLAY_ROW_MIDDLE;//assign row pointer to 1
        }
        else if(y < TICTACTOEDISPLAY_PIXEL_HEIGHT && y >  TICTACTOEDISPLAY_TWO_THIRD_HEIGHT)//Row 2
        {
            *row = TICTACTOEDISPLAY_ROW_BOTTOM;//assign row pointer to 2
        }
    }
}
// Returns the coordinates of last touched area
uint8_t clockDisplay_touchedArea() {
	int16_t x = 0;
	int16_t y = 0;
	uint8_t z = 0;
	display_getTouchedPoint(&x,&y,&z);

		display_getTouchedPoint(&x,&y,&z);

		if (y <= 115) {
				if (x <= (int32_t) X0) {
					clockDisplay_IncHr();
				}
				else if ( x >= (int32_t) X1) {
					clockDisplay_IncSec();
				}
				else {
					clockDisplay_IncMin();
				}

		}
		else {
				if (x <= (int32_t) X0) {
					clockDisplay_DecHr();
				}
				else if ( x <= (int32_t) X1) {
					clockDisplay_DecMin();
				}
				else {
					clockDisplay_DecSec();
				}
		}
	x = 0;
	y = 0;
	z = 0;
	return 0;
}
Esempio n. 3
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. 4
0
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;
	 }


}
Esempio n. 5
0
    //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;
        }
    }
// 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;
	}
}
// 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" );

			}
		}
	}
}