示例#1
0
// handler routine for timer1 to read the touch screen
void myTouchInt()
{
	static bool inTouch = false;
	if ((!inTouch)&&(myTouch.dataAvailable()))
	{
		inTouch = true;
		myTouch.read();
		xt = myTouch.getX();
		yt = myTouch.getY();
		ixt = xt; iyt = yt;
		myScreen.ETouch.TrigOn(xt,yt);
	}
	if ((inTouch)&&(myTouch.dataAvailable()))
	{
		myTouch.read();
		ixt = myTouch.getX();
		iyt = myTouch.getY();
		if ((ixt != xt)||(iyt != yt))
		myScreen.ESlide.TrigOn(ixt,iyt);
	}
	if ((inTouch)&&(!myTouch.dataAvailable()))
	{
		inTouch = false;
		myScreen.EunTouch.TrigOn(xt,yt);
	}
	myScreen.E100msecond.TrigOn();
}
void ECCalibrateScreen::SwaitForTouch()
{
  while (myTouch.dataAvailable() == true)
  {
	  myTouch.read();
  }
  while (myTouch.dataAvailable() == false) {}
  while (myTouch.dataAvailable() == true)
  {
	  myTouch.read();
  }
}
示例#3
0
// Draw a spot and wait until the user touches it, returning the touch coordinates in tx and ty.
// The alternative X and Y locations are so that the caller can allow for the touch panel being possibly inverted.
void DoTouchCalib(PixelNumber x, PixelNumber y, PixelNumber altX, PixelNumber altY, bool wantY, uint16_t& rawRslt)
{
	const PixelNumber touchCircleRadius = 8;
	const PixelNumber touchCalibMaxError = 40;
	
	lcd.setColor(touchSpotColour);
	lcd.fillCircle(x, y, touchCircleRadius);
	
	for (;;)
	{
		uint16_t tx, ty, rawX, rawY;
		if (touch.read(tx, ty, &rawX, &rawY))
		{
			if (   (abs((int)tx - (int)x) <= touchCalibMaxError || abs((int)tx - (int)altX) <= touchCalibMaxError)
				&& (abs((int)ty - (int)y) <= touchCalibMaxError || abs((int)ty - (int)altY) <= touchCalibMaxError)
			   ) 
			{
				TouchBeep();
				rawRslt = (wantY) ? rawY : rawX;
				break;
			}
		}
	}
	
	lcd.setColor(defaultBackColour);
	lcd.fillCircle(x, y, touchCircleRadius);
}