- UID
- 872238
|
ucos II+ucGUI+s3c2410+LCD+触摸屏整合03
/* 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 how\n"
"a touch screen can be\n"
"calibrated at run time.\n"
"Please press the touch\n"
"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, aLogY, &aPhysX, &aPhysY, _acPos);
}
/* 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)创建进程处理触摸事件,形式如下:
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 message\n");
GUI_TOUCH_Exec();//
}
}
2) 如下修改函数 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) {
xMin = xyMinMax[GUI_COORD_X].Min;
xMax = xyMinMax[GUI_COORD_X].Max;
} else {
xMax = xyMinMax[GUI_COORD_X].Min;
xMin = xyMinMax[GUI_COORD_X].Max;
}
if (xyMinMax[GUI_COORD_Y].Min < xyMinMax[GUI_COORD_Y].Max) {
yMin = xyMinMax[GUI_COORD_Y].Min;
yMax = xyMinMax[GUI_COORD_Y].Max;
} else {
yMax = xyMinMax[GUI_COORD_Y].Min;
yMin = xyMinMax[GUI_COORD_Y].Max;
}
/* Execute the state machine which reads the touch */
//switch (ReadState) {
//case 0:
yPhys = TOUCH_X_MeasureY();
// TOUCH_X_ActivateY(); /* Prepare X- measurement */
// ReadState++;
// break;
//default:
xPhys = TOUCH_X_MeasureX();
// TOUCH_X_ActivateX(); /* Prepare Y- measurement */
/* Convert values into logical values */
#if !GUI_TOUCH_SWAP_XY /* Is X/Y swapped ? */
x = xPhys;
y = yPhys;
#else
x = yPhys;
y = xPhys;
#endif
if ((x <xMin) | (x>xMax) | (y <yMin) | (y>yMax)) {
GUI_TOUCH_StoreUnstable(-1,-1);
} else {
x = AD2X(x);
y = AD2Y(y);
GUI_TOUCH_StoreUnstable(x,y);
}
/* Reset state machine */
//ReadState=0;
// break;
//}
#endif /* WIN32 */
}
五、 GUI多任务测试:
测试程序:MT_MultiTasking.c |
|