Esempio n. 1
0
void tsRenderCalibrationScreen(uint16_t x, uint16_t y, uint16_t radius)
{

  drawFill(COLOR_WHITE);
  tsCalibCenterText(TS_LINE1, 50, COLOR_DARKGRAY);
  tsCalibCenterText(TS_LINE2, 65, COLOR_DARKGRAY);
  tsCalibCenterText(TS_LINE3, 80, COLOR_DARKGRAY);
  drawCircle(x, y, radius, COLOR_RED);
  drawCircle(x, y, radius + 2, COLOR_MEDIUMGRAY);

  // Wait for touch
  uint32_t z1, z2;
  z1 = z2 = 0;
  while (z2 < CFG_TFTLCD_TS_THRESHOLD) 
    tsReadZ(&z1, &z2);
}
Esempio n. 2
0
tsTouchError_t tsRead(tsTouchData_t* data) {
  uint32_t x1, y1;

  // Assign pressure levels regardless of touch state
  tsReadZ(&data->z1, &data->z2);

  data->xraw = 0;
  data->yraw = 0;
  data->xlcd = 0;
  data->ylcd = 0;

  // Abort if the screen is not being touched (0 levels reported)
  if (data->z1 < _tsThreshhold) {
    data->valid = false;
    return TS_ERROR_NONE;
  }

  nopDelay(CFG_TFTLCD_TS_DELAYBETWEENSAMPLES);

  // Get two X/Y readings and compare results
  x1 = tsReadX();
  y1 = tsReadY();

  // X/Y seems to be valid and reading has been confirmed twice
  data->xraw = x1;
  data->yraw = y1;

  // Convert x/y values to pixel location with matrix multiply
  tsPoint_t location, touch;
  touch.x = x1;
  touch.y = y1;

  getDisplayPoint(&location, &touch, &_tsMatrix);
  data->xlcd = location.x;
  data->ylcd = location.y;
  data->valid = true;

  return TS_ERROR_NONE;
}
Esempio n. 3
0
tsTouchError_t tsWaitForEvent(tsTouchData_t* data, uint32_t timeoutMS)
{
  if (!_tsInitialised) tsInit();

  uint32_t z1, z2;
  uint32_t xRaw1, xRaw2, yRaw1, yRaw2;
  z1 = z2 = 0;

  // Handle timeout if delay > 0 milliseconds
  if (timeoutMS)
  {
    uint32_t startTick = systickGetTicks();
    // Systick rollover may occur while waiting for timeout
    if (startTick > 0xFFFFFFFF - timeoutMS)
    {
      // Wait for timeout or touch event
      while (z2 < CFG_TFTLCD_TS_THRESHOLD)
      {
        // Throw alert if timeout delay has been passed
        if ((systickGetTicks() < startTick) && (systickGetTicks() >= (timeoutMS - (0xFFFFFFFF - startTick))))
        {
          return TS_ERROR_TIMEOUT;
        }      
        tsReadZ(&z1, &z2);
      }
    }
    // No systick rollover will occur ... calculate timeout the simple way
    else
    {
      // Wait in infinite loop
      while (z2 < CFG_TFTLCD_TS_THRESHOLD)
      {
        // Throw timeout if delay has been passed
        if ((systickGetTicks() - startTick) > timeoutMS)
        {
          return TS_ERROR_TIMEOUT;
        }
        tsReadZ(&z1, &z2);
      }
    }
  }
  // No timeout requested ... wait forever
  else
  {
    while (z2 < CFG_TFTLCD_TS_THRESHOLD)
    {
      tsReadZ(&z1, &z2);
    }
  }

  // Get raw conversion results
  // Each value is read twice and compared to avoid erroneous readings
  xRaw1 = tsReadY();    // X and Y are reversed
  xRaw2 = tsReadY();    // X and Y are reversed
  yRaw1 = tsReadX();    // X and Y are reverse
  yRaw2 = tsReadX();    // X and Y are reverse

  // If both read attempts aren't identical, return mismatch error
  if ((xRaw1 != xRaw2) || (yRaw1 != yRaw2))
  {
    return TS_ERROR_XYMISMATCH;
  }

  // Normalise X
  data->x = ((xRaw1 - _calibration.offsetLeft > TS_ADC_LIMIT ? 0 : xRaw1 - _calibration.offsetLeft) * 100) / _calibration.divisorX;
  if (data->x > lcdGetWidth() - 1) data->x = lcdGetWidth() - 1;

  // Normalise Y
  data->y = ((yRaw1 - _calibration.offsetTop > TS_ADC_LIMIT ? 0 : yRaw1 - _calibration.offsetTop) * 100) / _calibration.divisorY;
  if (data->y > lcdGetHeight() - 1) data->y = lcdGetHeight() - 1;

  // Indicate correct reading
  return TS_ERROR_NONE;
}
Esempio n. 4
0
tsTouchError_t tsRead(tsTouchData_t* data, uint8_t calibrating)
{
  uint32_t x1, x2, y1, y2, z1, z2;

  // Assign pressure levels regardless of touch state
  tsReadZ(&z1, &z2);
  data->z1 = z1;
  data->z2 = z2;
  data->xraw = 0;
  data->yraw = 0;
  data->xlcd = 0;
  data->ylcd = 0;

  // Abort if the screen is not being touched (0 levels reported)
  if (z1 < _tsThreshhold)
  {
    data->valid = false;
    return TS_ERROR_NONE;
  }

  // Get two X/Y readings and compare results
  x1 = tsReadX();
  x2 = tsReadX();
  y1 = tsReadY();
  y2 = tsReadY();

  // Throw an error if both readings aren't identical
  if (x1 != x2 || y1 != y2)
  {
    data->valid = false;
    data->xraw = x1;
    data->yraw = y1;
    return TS_ERROR_XYMISMATCH;
  }

  // X/Y seems to be valid and reading has been confirmed twice
  data->xraw = x1;
  data->yraw = y1;

  // Convert x/y values to pixel location with matrix multiply
  tsPoint_t location, touch;
  touch.x = x1;
  touch.y = y1;
  // Only calculate the relative LCD value if this isn't for calibration
  if (!calibrating)
  {
    getDisplayPoint( &location, &touch, &_tsMatrix) ;
    data->xlcd = location.x;
    data->ylcd = location.y;
  }
  else
  {
    // Assign some false values, but only xraw and yraw are
    // used for calibration
    data->xlcd = 0;
    data->ylcd = 0;
  }
  data->valid = true;

  return TS_ERROR_NONE;
}