示例#1
0
void tsCalibrate(void)
{
  tsTouchData_t data;

  /* --------------- Welcome Screen --------------- */
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() / 2, 5);

  /* ----------------- First Dot ------------------ */
  // 10% over and 10% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 10, lcdGetHeight() / 10, 5);
  _tsLCDPoints[0].x = lcdGetWidth() / 10;
  _tsLCDPoints[0].y = lcdGetHeight() / 10;
  _tsTSPoints[0].x = data.xraw;
  _tsTSPoints[0].y = data.yraw;

  /* ---------------- Second Dot ------------------ */
  // 50% over and 90% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() - lcdGetHeight() / 10, 5);
  _tsLCDPoints[1].x = lcdGetWidth() / 2;
  _tsLCDPoints[1].y = lcdGetHeight() - lcdGetHeight() / 10;
  _tsTSPoints[1].x = data.xraw;
  _tsTSPoints[1].y = data.yraw;

  /* ---------------- Third Dot ------------------- */
  // 90% over and 50% down
  data = tsRenderCalibrationScreen(lcdGetWidth() - lcdGetWidth() / 10, lcdGetHeight() / 2, 5);
  _tsLCDPoints[2].x = lcdGetWidth() - lcdGetWidth() / 10;
  _tsLCDPoints[2].y = lcdGetHeight() / 2;
  _tsTSPoints[2].x = data.xraw;
  _tsTSPoints[2].y = data.yraw;

  // Do matrix calculations for calibration and store to EEPROM
  setCalibrationMatrix(&_tsLCDPoints[0], &_tsTSPoints[0], &_tsMatrix);
}
示例#2
0
void tsCalibrate(void)
{
  tsTouchData_t data;

  /* --------------- Welcome Screen --------------- */
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() / 2, 5);
  systickDelay(250);

  /* ----------------- First Dot ------------------ */
  // 10% over and 10% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 10, lcdGetHeight() / 10, 5);
  _tsLCDPoints[0].x = lcdGetWidth() / 10;
  _tsLCDPoints[0].y = lcdGetHeight() / 10;
  _tsTSPoints[0].x = data.xraw;
  _tsTSPoints[0].y = data.yraw;
  printf("Point 1 - LCD X:%04d Y:%04d TS X:%04d Y:%04d \r\n", 
        (int)_tsLCDPoints[0].x, (int)_tsLCDPoints[0].y, (int)_tsTSPoints[0].x, (int)_tsTSPoints[0].y);
  systickDelay(250);

  /* ---------------- Second Dot ------------------ */
  // 50% over and 90% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() - lcdGetHeight() / 10, 5);
  _tsLCDPoints[1].x = lcdGetWidth() / 2;
  _tsLCDPoints[1].y = lcdGetHeight() - lcdGetHeight() / 10;
  _tsTSPoints[1].x = data.xraw;
  _tsTSPoints[1].y = data.yraw;
  printf("Point 2 - LCD X:%04d Y:%04d TS X:%04d Y:%04d \r\n", 
       (int)_tsLCDPoints[1].x, (int)_tsLCDPoints[1].y, (int)_tsTSPoints[1].x, (int)_tsTSPoints[1].y);
  systickDelay(250);

  /* ---------------- Third Dot ------------------- */
  // 90% over and 50% down
  data = tsRenderCalibrationScreen(lcdGetWidth() - lcdGetWidth() / 10, lcdGetHeight() / 2, 5);
  _tsLCDPoints[2].x = lcdGetWidth() - lcdGetWidth() / 10;
  _tsLCDPoints[2].y = lcdGetHeight() / 2;
  _tsTSPoints[2].x = data.xraw;
  _tsTSPoints[2].y = data.yraw;
  printf("Point 3 - LCD X:%04d Y:%04d TS X:%04d Y:%04d \r\n", 
        (int)_tsLCDPoints[2].x, (int)_tsLCDPoints[2].y, (int)_tsTSPoints[2].x, (int)_tsTSPoints[2].y);
  systickDelay(250);

  // Do matrix calculations for calibration and store to EEPROM
  setCalibrationMatrix(&_tsLCDPoints[0], &_tsTSPoints[0], &_tsMatrix);
}
示例#3
0
void tsCalibrate(void)
{
  lcdOrientation_t orientation;
  uint16_t right2, top2, left2, bottom2;
  bool passed = false;

  // Determine screen orientation before starting calibration
  orientation = lcdGetOrientation();

  /* -------------- Welcome Screen --------------- */
  tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() / 2, 5);

  // Delay to avoid multiple touch events
  systickDelay(250);

  /* -------------- CALIBRATE TOP-LEFT --------------- */
  passed = false;
  while (!passed)
  {
    // Read X/Y depending on screen orientation
    tsRenderCalibrationScreen(3, 3, 5);
    _calibration.offsetLeft = orientation == LCD_ORIENTATION_LANDSCAPE ? tsReadY() : tsReadX();
    _calibration.offsetTop = orientation == LCD_ORIENTATION_LANDSCAPE ? tsReadX() : tsReadY();
  
    // Make sure values are in range
    if (_calibration.offsetLeft < TS_CALIBRATION_OUTOFRANGE && _calibration.offsetTop < TS_CALIBRATION_OUTOFRANGE)
      passed = true;
  }

  // Delay to avoid multiple touch events
  systickDelay(250);

  /* -------------- CALIBRATE BOTTOM-RIGHT  --------------- */
  passed = false;
  while (!passed)
  {
    tsRenderCalibrationScreen(lcdGetWidth() - 4, lcdGetHeight() - 4, 5);
  
    // Read X/Y depending on screen orientation
    _calibration.offsetRight = orientation == LCD_ORIENTATION_LANDSCAPE ? TS_ADC_LIMIT - tsReadY() : TS_ADC_LIMIT - tsReadX();
    _calibration.offsetBottom = orientation == LCD_ORIENTATION_LANDSCAPE ? TS_ADC_LIMIT - tsReadX() : TS_ADC_LIMIT - tsReadY();
  
    // Redo test if value is out of range
    if (_calibration.offsetRight < TS_CALIBRATION_OUTOFRANGE && _calibration.offsetBottom < TS_CALIBRATION_OUTOFRANGE)
      passed = true;
  }

  // Delay to avoid multiple touch events
  systickDelay(250);

  /* -------------- CALIBRATE TOP-RIGHT  --------------- */
  passed = false;
  while (!passed)
  {
    tsRenderCalibrationScreen(lcdGetWidth() - 4, 3, 5);
  
    if (orientation == LCD_ORIENTATION_LANDSCAPE)
    {
      right2 = TS_ADC_LIMIT - tsReadY();
      top2 = tsReadX();
    }
    else
    {
      right2 = tsReadX();
      top2 = TS_ADC_LIMIT - tsReadY();
    }
  
    // Redo test if value is out of range
    if (right2 < TS_CALIBRATION_OUTOFRANGE && top2 < TS_CALIBRATION_OUTOFRANGE)
      passed = true;  
  }

  // Average readings
  _calibration.offsetRight = (_calibration.offsetRight + right2) / 2;
  _calibration.offsetTop = (_calibration.offsetTop + top2) / 2;

  // Delay to avoid multiple touch events
  systickDelay(250);

  /* -------------- CALIBRATE BOTTOM-LEFT --------------- */
  passed = false;
  while (!passed)
  {
    tsRenderCalibrationScreen(3, lcdGetHeight() - 4, 5);
  
    if (orientation == LCD_ORIENTATION_LANDSCAPE)
    {
      left2 = tsReadY();
      bottom2 = TS_ADC_LIMIT - tsReadX();
    }
    else
    {
      left2 = TS_ADC_LIMIT - tsReadX();
      bottom2 = tsReadY();
    }
  
    // Redo test if value is out of range
    if (left2 < TS_CALIBRATION_OUTOFRANGE && bottom2 < TS_CALIBRATION_OUTOFRANGE)
      passed = true;
  }

  // Average readings
  _calibration.offsetLeft = (_calibration.offsetLeft + left2) / 2;
  _calibration.offsetBottom = (_calibration.offsetBottom + bottom2) / 2;

  // Delay to avoid multiple touch events
  systickDelay(250);

  _calibration.divisorX = ((TS_ADC_LIMIT - (_calibration.offsetLeft + _calibration.offsetRight)) * 100) / lcdGetWidth();
  _calibration.divisorY = ((TS_ADC_LIMIT - (_calibration.offsetTop + _calibration.offsetBottom)) * 100) / lcdGetHeight();

  /* -------------- Persist Data --------------- */
  // Persist data to EEPROM
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_LEFT, _calibration.offsetLeft);
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_RIGHT, _calibration.offsetRight);
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_TOP, _calibration.offsetTop);
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_BOT, _calibration.offsetBottom);
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_DIVX, _calibration.divisorX);
  eepromWriteU16(CFG_EEPROM_TOUCHSCREEN_OFFSET_DIVY, _calibration.divisorY);
  eepromWriteU8(CFG_EEPROM_TOUCHSCREEN_CALIBRATED, 1);

  // Clear the screen
  drawFill(COLOR_BLACK);
}