|

楼主 |
发表于 2021-4-21 16:18:00
|
显示全部楼层
bool bsp_tp_cal (void)
{
int xsize, ysize;
int16_t adcx, adcy;
touch_err_t tp_err;
int x_cal[TOUCH_CAL_POINTS], y_cal[TOUCH_CAL_POINTS];
uint8_t i;
xsize = LCD_GetXSize ();
ysize = LCD_GetYSize ();
_init_cal_pos ();
GUI_SetPenSize (3);
// get touch input
for (i = 0; i < TOUCH_CAL_POINTS;i++) {
_tp_drv.flush ();
_tp_scan.enable = 1;
GUI_Clear ();
GUI_DispStringAt ("Please touch the point", 20, ysize / 2 - 60);
GUI_DrawCircle (_x_ref, _y_ref, 4);
GUI_X_Delay (1000);
// waiting touch pressed
while (1) {
GUI_X_Delay (500);
_buf_out (&adcx, &adcy, &tp_err);
if (TOUCH_ERR_NONE == tp_err) {
_tp_drv.flush ();
break;
}
}
// ignore previous data
while (1) {
GUI_X_Delay (500);
_buf_out (&adcx, &adcy, &tp_err);
if (TOUCH_ERR_NONE == tp_err) {
break;
}
}
_x_adc = (int)adcx;
_y_adc = (int)adcy;
GUI_DispStringAt ("The reading ADC", 10, ysize / 2 + 60);
GUI_DispStringAt ("X: ", 10, ysize / 2 + 100);
GUI_DispDec (_x_adc, 4);
GUI_DispStringAt ("Y: ", 10, ysize / 2 + 100 + 40);
GUI_DispDec (_y_adc, 4);
GUI_X_Delay (2000);
// waiting touch released
while (1) {
GUI_X_Delay (100);
_buf_out (&adcx, &adcy, &tp_err);
if (TOUCH_ERR_ERROR == tp_err)
break;
}
_tp_scan.enable = 0;
_tp_drv.flush ();
GUI_X_Delay (3000);
GUI_Clear ();
GUI_DispStringHCenterAt ("Touch done, release the point", xsize / 2, ysize / 2 - 60);
GUI_X_Delay (5000);
GUI_Clear ();
}
if (GUI_TOUCH_CalcCoefficients (TOUCH_CAL_POINTS, &_x_ref[0], &_y_ref[0], &_x_adc[0], &_y_adc[0], xsize, ysize))
return false;
// verify calibration data
for (i = 0; i < TOUCH_CAL_POINTS; i++) {
x_cal = _x_adc;
y_cal = _y_adc;
}
if (false == bsp_tp_cal_verify (&x_cal[0], &y_cal[0]))
return false;
GUI_X_Delay (1000);
GUI_ClearKeyBuffer ();
GUI_Clear ();
//
GUI_DispStringHCenterAt ("Touch panel calibration success...", xsize / 2, ysize / 2);
GUI_X_Delay (3000);
//
_tp_drv.flush ();
_tp_scan.enable = 1;
_tp_drv.state_cal = 0;
return true;
}
|
|