📄 tsttouchscreen.c
字号:
if (timeout-- == 0) {
retVal = ERRORCODEX(ERR_L_TS, 0x80, 2, ERR_T_TIMEOUT);
goto error;
}
DM_WaitMs(7); // +3ms for the pen detect.
} while (1);
meanX = 0; meanY = 0;
for (z=0; z<50; z++) {
PostDisplayProgress(ERR_L_TS, 0x80, 5);
retVal = TS_GetRaw(&x, &y);
PostDisplayProgress(ERR_L_TS, 0x80, 6);
if (retVal != ERR_NONE) goto error;
//printf("X=%04X Y=%04X\r\n", x, y);
retVal = TS_GetPenStatus();
if (retVal != TS_PENDOWN) goto watchPen;
DM_WaitMs(1); // +6ms for conversions, +3ms for pen detect.
meanX += x; meanY += y;
px[z] = x; py[z] = y;
}
meanX /= POINTS;
meanY /= POINTS;
if(debug_mode)
{
printf("X=%04X Y=%04X\r\n", meanX, meanY);
printf("meanX-touchpointx = %x, meanY-touchpointy = %x\r\n", meanX-touchpointx, meanY-touchpointy);
printf("UCB1400MAX/25 = %x\r\n", UCB1400MAX/25);
#ifdef take_samples
x_tally += meanX;
y_tally += meanY;
sample_count++;
printf("X average = %04X, Y average = %04X, Samples = %d\r\n",
x_tally/sample_count, y_tally/sample_count, sample_count);
#endif
}
#ifdef take_samples
} while(1);
#endif
#if 0 //hzh
if (
meanX-touchpointx > UCB1400MAX/23 || // Check within +-4% of 1/2 scale.
meanX-touchpointx < -UCB1400MAX/23 ||
meanY-touchpointy > UCB1400MAX/23||
meanY-touchpointy < -UCB1400MAX/23
) {
retVal = ERRORCODEX(ERR_L_TS, 0x80, 5, ERR_T_BADRANGE);
if(debug_mode)
{
printf("bad position on screen!\r\n");
printf("X position should be between %x and %x\r\n", touchpointx - (UCB1400MAX/25), touchpointx + (UCB1400MAX/25));
printf("Y position should be between %x and %x\r\n", touchpointy - (UCB1400MAX/25), touchpointy + (UCB1400MAX/25));
}
goto error;
}
#endif
for (z=0; z<50; z++) {
if(debug_mode)
{
printf("dX=%i dY=%i\r\n", px[z]-meanX, py[z]-meanY);
}
if (
px[z]-meanX > 8 || // Check within 7 counts (measured 3).
px[z]-meanX < -8 ||
py[z]-meanY > 8 ||
py[z]-meanY < -8
) {
retVal = ERRORCODEX(ERR_L_TS, 0x80, 6, ERR_T_BADRANGE);
if(debug_mode)
{
printf("bad mean value! Noisy screen!\r\n");
printf("Highest absolute value allowed is 7.\r\n");
printf("Backlight should be off during this test!\r\n");
printf("Backlight turns off and on automatically!\r\n");
}
goto error;
}
}
PostDisplayProgress(ERR_L_TS, 0x80, 7);
// retVal = TS_HWShutdown();
PostDisplayProgress(ERR_L_TS, 0x80, 8);
if (retVal != ERR_NONE) goto error;
//printf(" Success!\r\n");
// Sound the bell
//printf("\a");
printf("x=0x%x, y=0x%x\r\n", meanX, meanY); //hzh
touchcount--;
//printf("touchcount = %d\r\n",touchcount);
}while(touchcount);
printf(" Success!\r\n");
return 0;
error:
XllpUtilityOutputError(retVal);
for(i=0; i<5; i++)
{
printf("\a");
DM_WaitMs(200);
}
return 1;
}
/*
*******************************************************************************
*
* FUNCTION: TstTouchscreenAd
*
* DESCRIPTION: Test the SSP connected AD7873 Touchscreen Controller.
*
* INPUT PARAMETERS: None.
*
* RETURNS: Number of errors.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS:
*
* CALLED BY: POST
*
* PROTOTYPE: UINT TstTouchscreenAd(void)
*
*******************************************************************************
*/
UINT TstTouchscreenAd(void)
{
ErrorT retVal;
UINT16 x, y, z;
UINT16 timeout=WAITFORTOUCH, timeout2;
INT16 px[50], py[50];
INT32 meanX, meanY;
PostDisplayProgress(ERR_L_TS, 0x80, 0);
printf(" Testing AD7873 Touch Screen\r\n");
retVal = TSad_HWSetup();
if (retVal != ERR_NONE) goto error;
printf(" User! Set the four touchscreen switches set to \"AD7873\".\r\n");
GetUserResponse(YES);
printf(" User! Touch the center of the screen after you continue.\r\n");
GetUserResponse(YES);
XsLcdClear();
XsLcdCreateDefaultPicture();
do {
retVal = TSad_GetPenStatus();
if (retVal == TS_PENDOWN) {
if (timeout == WAITFORTOUCH) {
retVal = ERRORCODEX(ERR_L_SSPTOUCH, 0x80, 2, ERR_T_UNEXPECTED);
goto error;
} else if (timeout2-- == 0) break;
} else {
watchPen:
timeout2 = DEBOUNCE;
}
if (timeout-- == 0) {
retVal = ERRORCODEX(ERR_L_SSPTOUCH, 0x80, 2, ERR_T_TIMEOUT);
goto error;
}
DM_WaitMs(7); // +3ms for the pen detect.
} while (1);
meanX = 0; meanY = 0;
for (z=0; z<50; z++) {
PostDisplayProgress(ERR_L_SSPTOUCH, 0x80, 5);
// turn off the backlight
XsPwmWriteDuty(0, 0x0);
retVal = TSad_GetRaw(&x, &y);
// turn on the backlight
XsPwmWriteDuty(0, 0x3FF);
PostDisplayProgress(ERR_L_SSPTOUCH, 0x80, 6);
if (retVal != ERR_NONE) goto error;
//printf("X=%04X Y=%04X\r\n", x, y);
retVal = TSad_GetPenStatus();
if (retVal != TSAD_PENDOWN) goto watchPen;
DM_WaitMs(1); // +6ms for conversions, +3ms for pen detect.
meanX += x; meanY += y;
px[z] = x; py[z] = y;
}
meanX /= POINTS;
meanY /= POINTS;
//printf("X=%04X Y=%04X\r\n", meanX, meanY);
if (
meanX-0x880 > AD7873MAX/25 || // Check within +-8% of 1/2 scale.
meanX-0x880 < -AD7873MAX/25 || // (measured 0x880, 0x800)
meanY-0x800 > AD7873MAX/25||
meanY-0x800 < -AD7873MAX/25
) {
retVal = ERRORCODEX(ERR_L_SSPTOUCH, 0x80, 5, ERR_T_BADRANGE);
goto error;
}
for (z=0; z<50; z++) {
//printf("dX=%i dY=%i\r\n", px[z]-meanX, py[z]-meanY);
if (
px[z]-meanX > 24 || // Check within 24 counts (measured 12).
px[z]-meanX < -24 ||
py[z]-meanY > 24 ||
py[z]-meanY < -24
) {
retVal = ERRORCODEX(ERR_L_SSPTOUCH, 0x80, 6, ERR_T_BADRANGE);
goto error;
}
}
PostDisplayProgress(ERR_L_SSPTOUCH, 0x80, 7);
retVal = TSad_HWShutdown();
PostDisplayProgress(ERR_L_SSPTOUCH, 0x80, 8);
if (retVal != ERR_NONE) goto error;
printf(" Success!\r\n");
return 0;
error:
XllpUtilityOutputError(retVal);
return 1;
}
/************* Global Kludge Functions *************/
/*
*******************************************************************************
*
* FUNCTION: KTstTouchscreen
*
* DESCRIPTION: Kludge for legacy code.
*
* INPUT PARAMETERS: void *arg - Ignored.
* CHAR *param - Ignored.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: TstTouchscreen()
*
* CALLED BY: Command List.
*
* PROTOTYPE: void KTstTouchscreen(PVOID arg, PCHAR param);
*
*******************************************************************************
*/
void KTstTouchscreen(PVOID arg, PCHAR param)
{
TstTouchscreen();
}
/*
*******************************************************************************
*
* FUNCTION: KTstTouchscreenAd
*
* DESCRIPTION: Kludge for legacy code.
*
* INPUT PARAMETERS: void *arg - Ignored.
* CHAR *param - Ignored.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: TstTouchscreenAd()
*
* CALLED BY: Command List.
*
* PROTOTYPE: void KTstTouchscreenAd(PVOID arg, PCHAR param);
*
*******************************************************************************
*/
void KTstTouchscreenAd(PVOID arg, PCHAR param)
{
TstTouchscreenAd();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -