ucos II+ucGUI+s3c2410+LCD+觸摸屏整合
char acText[] = Press here;
GUI_RECT Rect;
int FontSizeY, Align;
FontSizeY = GUI_GetFontSizeY();
GUI_Clear();
GUI_SetColor(GUI_BLACK);
_DispStringCentered(Runtime calibration,n
please touch the screenn
at the center of the ring.); /* Ask user to press the touch */
/* Calculate the rectangle for the string */
Rect.y0 = LogY - FontSizeY;
Rect.y1 = LogY + FontSizeY;
if (LogX LCD_GetXSize() / 2) {
Rect.x0 = LogX + 15;
Rect.x1 = LCD_GetXSize();
Align = GUI_TA_LEFT;
} else {
Rect.x0 = 0;
Rect.x1 = LogX - 15;
Align = GUI_TA_RIGHT;
}
/* Show the text nearby the ring */
GUI_DispStringInRect(acText, Rect, Align | GUI_TA_TOP);
GUI_DispStringInRect(pString, Rect, Align | GUI_TA_BOTTOM);
/* Draw the ring */
GUI_FillCircle(LogX, LogY, 10);
GUI_SetColor(GUI_WHITE);
GUI_FillCircle(LogX, LogY, 5);
GUI_SetColor(GUI_BLACK);
/* Wait until touch is pressed */
_WaitForPressedState(1);
*pPhysX = GUI_TOUCH_GetxPhys();
*pPhysY = GUI_TOUCH_GetyPhys();
/* Wait until touch is released */
_WaitForPressedState(0);
}
static void _Explain(void) {
_DispStringCentered(This sample shows hown
a touch screen can ben
calibrated at run time.n
Please press the touchn
screen to continue...);
GUI_DispStringHCenterAt(TOUCH_Calibrate, LCD_GetXSize() / 2, 5);
_WaitForPressedState(1);
_WaitForPressedState(0);
}
void CalibrateTask(void* pdata) {//觸摸屏校準任務入口
int aPhysX[2], aPhysY[2], aLogX[2], aLogY[2], i;
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
GUI_SetColor(GUI_BLACK);
GUI_SetFont(GUI_Font13B_ASCII);
_Explain();
/* Set the logical values */
aLogX[0] = 15;
aLogY[0] = 15;
aLogX[1] = LCD_GetXSize() - 20;
aLogY[1] = LCD_GetYSize() - 20;
/* Get the physical values of the AD converter for 2 positions */
for (i = 0; i 2; i++) {
_GetPhysValues(aLogX[i], aLogY[i], aPhysX[i], aPhysY[i], _acPos[i]);
}
/* Use the physical values to calibrate the touch screen */
GUI_TOUCH_Calibrate(0, aLogX[0], aLogX[1], aPhysX[0], aPhysX[1]); /* Calibrate X-axis */
GUI_TOUCH_Calibrate(1, aLogY[0], aLogY[1], aPhysY[0], aPhysY[1]); /* Calibrate Y-axis */
{ /* calculate and display values for configuration file */
int calX0, calX1;
int calY0, calY1;
GUI_Clear();
GUI_TOUCH_GetCalData(GUI_COORD_X, calX0, calX1);
GUI_TOUCH_GetCalData(GUI_COORD_Y, calY0, calY1);
GUI_DispStringAt(calX0: , 0, 0); GUI_DispDec(calX0, 4); GUI_DispNextLine();
GUI_DispString (calX1: ); GUI_DispDec(calX1, 4); GUI_DispNextLine();
GUI_DispString (calY0: ); GUI_DispDec(calY0, 4); GUI_DispNextLine();
GUI_DispString (calY1: ); GUI_DispDec(calY1, 4);
GUI_DispStringAt(lcdx0: , 0, 200); GUI_DispDec(aLogX[0], 4); GUI_DispNextLine();
GUI_DispString (lcdx1: ); GUI_DispDec(aLogX[1], 4); GUI_DispNextLine();
GUI_DispString (lcdy0: ); GUI_DispDec(aLogY[0], 4); GUI_DispNextLine();
GUI_DispString (lcdy1: ); GUI_DispDec(aLogY[1], 4); GUI_DispNextLine();
GUI_DispString (tscX0: ); GUI_DispDec(aPhysX[0], 4); GUI_DispNextLine();
GUI_DispString (tscX1: ); GUI_DispDec(aPhysX[1], 4); GUI_DispNextLine();
GUI_DispString (tscY0: ); GUI_DispDec(aPhysY[0], 4); GUI_DispNextLine();
GUI_DispString (tscY1: ); GUI_DispDec(aPhysY[1], 4); GUI_DispNextLine();
GUI_DispString (Please touch display to continue...);
GUI_Delay(1000);
_WaitForPressedState(1);
_WaitForPressedState(0);
}
GUI_Clear();
SystemOn();
OSTaskSuspend(OS_PRIO_SELF);
}
3、為了響應觸摸屏,做如下事:
1)創(chuàng)建進程處理觸摸事件,形式如下:
void TouchTask(void* data) {
INT8U err;
while(1)
{
CONSOL_Printf(Waiting for Touch......n);
OSMboxPend(TouchMbox, 0, err); /* Acquire semaphore to perform random numbers */
CONSOL_Printf(Got a messagen);
GUI_TOUCH_Exec();//
}
}
2) 如下修改函數(shù) GUI_TOUCH_Exec():
void GUI_TOUCH_Exec(void) {
#ifndef WIN32
static U8 ReadState;
int x,y;
/* calculate Min / Max values */
if (xyMinMax[GUI_COORD_X].Min xyMinMax[GUI_COORD_X].Max) {
評論