コード例 #1
0
ファイル: TicTacToeDisplay.c プロジェクト: brianlwatson/ZYBO
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();


	}
}
コード例 #2
0
void hitLedTimer_runTest() {
	printf("\r\n-----HitLed Timer Test-----\r\n");
	hitLedTimer_init();

	  // We want to use the interval timers.
	  intervalTimer_initAll();
	  intervalTimer_resetAll();
	  intervalTimer_testAll();
	  printf("Laser Tag Test Program\n\r");
	  // Find out how many timer ticks per second.
	  u32 privateTimerTicksPerSecond = interrupts_getPrivateTimerTicksPerSecond();
	  printf("private timer ticks per second: %ld\n\r", privateTimerTicksPerSecond);
	  // Initialize the GPIO LED driver and print out an error message if it fails (argument = true).
	  // The LD4 LED provides a heart-beat that visually verifies that interrupts are running.
	  leds_init(true);
	  // Init all interrupts (but does not enable the interrupts at the devices).
	  // Prints an error message if an internal failure occurs because the argument = true.
	  interrupts_initAll(true);
	  // Enables the main interrupt on the time.
	  interrupts_enableTimerGlobalInts();
	  // Start the private ARM timer running.
	  interrupts_startArmPrivateTimer();
	  printf("This program will run for %d seconds and print out statistics at the end of the run.\n\r",
		 TOTAL_SECONDS);
	  printf("Starting timer interrupts.\n\r");
	  // Enable global interrupt of System Monitor. The system monitor contains the ADC. Mainly to detect EOC interrupts.
	  interrupts_enableSysMonGlobalInts();
	  // Start a duration timer and compare its timing against the time computed by the timerIsr().
	  // Assume that ENABLE_INTERVAL_TIMER_0_IN_TIMER_ISR is defined in interrupts.h so that time spent in timer-isr is measured.

	  int countInterruptsViaInterruptsIsrFlag = 0;
	  // Enable interrupts at the ARM.
	  interrupts_enableArmInts();
	  intervalTimer_start(1);
	  // Wait until TOTAL seconds have expired. globalTimerTickCount is incremented by timer isr.
	  while (interrupts_isrInvocationCount() < (TOTAL_SECONDS * privateTimerTicksPerSecond)) {
	    if (interrupts_isrFlagGlobal) {				// If this is true, an interrupt has occured (at least one).
	      countInterruptsViaInterruptsIsrFlag++;	// Note that you saw it.
	      interrupts_isrFlagGlobal = 0;			// Reset the shared flag.
	      // Place non-timing critical code here.
		  hitLedTimer_start();
	      while(hitLedTimer_running()) {}
	      utils_msDelay(300);
	    }
	  }
	  interrupts_disableArmInts();	// Disable ARM interrupts.
	  intervalTimer_stop(1);			// Stop the interval timer.
	  double runningSeconds, isrRunningSeconds;
	  intervalTimer_getTotalDurationInSeconds(1, &runningSeconds);
	  printf("Total run time as measured by interval timer in seconds: %g.\n\r", runningSeconds);
	  intervalTimer_getTotalDurationInSeconds(0, &isrRunningSeconds);
	  printf("Measured run time in timerIsr (using interval timer): %g.\n\r", isrRunningSeconds);
	  printf("Detected interrupts via global flag: %d\n\r", countInterruptsViaInterruptsIsrFlag);
	  printf("During %d seconds, an average of %7.3f ADC samples were collected per second.\n\r",
		 TOTAL_SECONDS, (float) isr_getTotalAdcSampleCount() / (float) TOTAL_SECONDS);
	  printf("\r\n-----End HitLed Timer Test-----\r\n");
}
コード例 #3
0
ファイル: simonDisplay.c プロジェクト: wg88719/zybo_samples
// 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.
}
コード例 #4
0
//*********************************************************************************************
// verifySequence_runTest()
// Tests the verifySequence state machine.
// It prints instructions to the touch-screen. The user responds by tapping the
// correct colors to match the sequence.
// Users can test the error conditions by waiting too long to tap a color or
// by tapping an incorrect color.
//*********************************************************************************************
void verifySequence_runTest()
{
    display_init();  // Always must do this.
    buttons_init();  // Need to use the push-button package so user can quit.
    int16_t sequenceLength = ONE;  // Start out with a sequence length of 1.
    verifySequence_printInstructions(sequenceLength, false);  // Tell the user what to do.
    utils_msDelay(MESSAGE_WAIT_MS);  // Give them a few seconds to read the instructions.
    simonDisplay_drawAllButtons()    // Now, draw the buttons.
    // Set the test sequence and it's length.
    globals_setSequence(verifySequence_testSequence, MAX_TEST_SEQUENCE_LENGTH);
    globals_setSequenceIterationLength(sequenceLength);
    // Enable the verifySequence state machine.
    verifySequence_enable();           // Everything is interlocked, so first enable the machine.
    while (!(buttons_read() & BTN0))// Need to hold button until it quits as you might be stuck in a delay.
    {
        // verifySequence uses the buttonHandler state machine so you need to "tick" both of them.
        verifySequence_tick();  // Advance the verifySequence state machine.
        simonbuttonHandler_tick();   // Advance the buttonHandler state machine.
        utils_msDelay(ONE_MS);       // Wait 1 ms.
        // If the verifySequence state machine has finished, check the result, otherwise just keep ticking both machines.
    if (verifySequence_isComplete())
    {
      if (verifySequence_isTimeOutError())
      {                      // Was the user too slow?
        verifySequence_printInfoMessage(user_time_out_e);         // Yes, tell the user that they were too slow.
      }
      else if (verifySequence_isUserInputError())
      {             // Did the user tap the wrong color?
        verifySequence_printInfoMessage(user_wrong_sequence_e);   // Yes, tell them so.
      }
      else
      {
        verifySequence_printInfoMessage(user_correct_sequence_e); // User was correct if you get here.
      }
      utils_msDelay(MESSAGE_WAIT_MS);                            // Allow the user to read the message.
      sequenceLength = incrementSequenceLength(sequenceLength);  // Increment the sequence.
      globals_setSequenceIterationLength(sequenceLength);  // Set the length for the verifySequence state machine.
      verifySequence_printInstructions(sequenceLength, V_ENABLED);    // Print the instructions.
      utils_msDelay(MESSAGE_WAIT_MS);                            // Let the user read the instructions.
      verifySequence_drawButtons();                              // Draw the buttons.
      verifySequence_disable();                                  // Interlock: first step of handshake.
      verifySequence_tick();                                     // Advance the verifySequence machine.
      utils_msDelay(ONE_MS);                                          // Wait for 1 ms.
      verifySequence_enable();                                   // Interlock: second step of handshake.
      utils_msDelay(ONE_MS);                                          // Wait 1 ms.
    }
  }
  verifySequence_printInfoMessage(user_quit_e);  // Quitting, print out an informational message.
}
コード例 #5
0
// 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;
	}
}
コード例 #6
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" );

			}
		}
	}
}