硬汉嵌入式论坛

 找回密码
 立即注册
查看: 5224|回复: 5
收起左侧

[emWin] emwin5.22触摸屏读不到消息

[复制链接]

1

主题

4

回帖

24

积分

新手上路

积分
24
发表于 2015-11-12 19:58:29 | 显示全部楼层 |阅读模式
OS   :UCOSII 2.98
STemwin5.22
LCD : 正点原子3.5寸  NT35310 XPT2046
触摸屏移植上去后在下面两个函数能读到触摸数据
int  GUI_TOUCH_X_MeasureX(void) {
int result;
result = TouchReadXY(XPT2046_RDX);
return result;
}

int  GUI_TOUCH_X_MeasureY(void) {
int result;
result = TouchReadXY(XPT2046_RDY);
return result;
}

10ms定时调用GUI_TOUCH_Exec()
static void tmrCb_Touch(void *p_tmr, void *p_arg)
{
(void)p_arg;
GUI_TOUCH_Exec();
}

触摸校准和demo任务
void EmWinDemo(void *p_arg)
{
WM_SetCreateFlags(WM_CF_MEMDEV);
GUI_Init();
TouchCalibrate();
for(;;)
{
GUIDEMO_Main();
}
}

但是在Touch_Calibrate()中获取不到消息
代码在第32行GUI_TOUCH_GetState(&State)中获取不到state的数据
  1. #include "GUI.h"
  2. #include "touch_calibrate.h"
  3. /********************************************************************
  4. *
  5. *       Static data
  6. *
  7. *********************************************************************
  8. */
  9. static const char * _acPos[] = {
  10.   "(upper left position)",
  11.   "(lower right position)"
  12. };
  13. /*********************************************************************
  14. *
  15. *       Static code
  16. *
  17. **********************************************************************
  18. */
  19. /*********************************************************************
  20. *
  21. *       _WaitForPressedState
  22. *
  23. * Purpose:
  24. *   Waits until the touch is in the given pressed state for at least 250 ms
  25. */
  26. static void _WaitForPressedState(int Pressed) {
  27.   GUI_PID_STATE State;
  28.   do {
  29.     GUI_TOUCH_GetState(&State);
  30.     GUI_Delay(1);
  31.     if (State.Pressed == Pressed) {
  32.       int TimeStart = GUI_GetTime();
  33.       do {
  34.         GUI_TOUCH_GetState(&State);
  35.         GUI_Delay(1);
  36.         if (State.Pressed != Pressed) {
  37.           break;
  38.         } else if ((GUI_GetTime() - 50) > TimeStart) {
  39.           return;
  40.         }
  41.       } while (1);
  42.     }
  43.   } while (1);
  44. }
  45. /*********************************************************************
  46. *
  47. *       _DispStringCentered
  48. *
  49. * Purpose:
  50. *   Shows the given text horizontally and vertically centered
  51. */
  52. static void _DispStringCentered(const char * pString) {
  53.   GUI_RECT Rect;
  54.   Rect.x0 = Rect.y0 = 0;
  55.   Rect.x1 = LCD_GetXSize() - 1;
  56.   Rect.y1 = LCD_GetYSize() - 1;
  57.   GUI_DispStringInRect(pString, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  58. }
  59. /*********************************************************************
  60. *
  61. *       _GetPhysValues
  62. *
  63. * Purpose:
  64. *   Asks the user to press the touch screen at the given position
  65. *   and returns the physical A/D values
  66. */
  67. static void _GetPhysValues(int LogX, int LogY, int * pPhysX, int * pPhysY, const char * pString) {
  68.   char acText[] = "Press here";
  69.   GUI_RECT Rect;
  70.   int FontSizeY, Align;
  71.   FontSizeY = GUI_GetFontSizeY();
  72.   GUI_Clear();
  73.   GUI_SetColor(GUI_BLACK);
  74.   _DispStringCentered("Runtime calibration,\n"
  75.                       "please touch the screen\n"
  76.                       "at the center of the ring."); /* Ask user to press the touch */
  77.   /* Calculate the rectangle for the string */
  78.   Rect.y0 = LogY - FontSizeY;
  79.   Rect.y1 = LogY + FontSizeY;
  80.   if (LogX < LCD_GetXSize() / 2) {
  81.     Rect.x0 = LogX + 15;
  82.     Rect.x1 = LCD_GetXSize();
  83.     Align = GUI_TA_LEFT;
  84.   } else {
  85.     Rect.x0 = 0;
  86.     Rect.x1 = LogX - 15;
  87.     Align = GUI_TA_RIGHT;
  88.   }
  89.   /* Show the text nearby the ring */
  90.   GUI_DispStringInRect(acText, &Rect, Align | GUI_TA_TOP);
  91.   GUI_DispStringInRect(pString, &Rect, Align | GUI_TA_BOTTOM);
  92.   /* Draw the ring */
  93.   GUI_FillCircle(LogX, LogY, 10);
  94.   GUI_SetColor(GUI_WHITE);
  95.   GUI_FillCircle(LogX, LogY, 5);
  96.   GUI_SetColor(GUI_BLACK);
  97.   /* Wait until touch is pressed */
  98.   _WaitForPressedState(1);
  99.   *pPhysX = GUI_TOUCH_GetxPhys();
  100.   *pPhysY = GUI_TOUCH_GetyPhys();
  101.   /* Wait until touch is released */
  102.   _WaitForPressedState(0);
  103. }
  104. /********************************************************************
  105. *
  106. *       _Explain
  107. *
  108. * Purpose:
  109. *   Shows a text to give a short explanation of the sample program
  110. */
  111. static void _Explain(void) {
  112.   _DispStringCentered("This sample shows how\n"
  113.                       "a touch screen can be\n"
  114.                       "calibrated at run time.\n"
  115.                       "Please press the touch\n"
  116.                       "screen to continue...");
  117.   GUI_DispStringHCenterAt("TOUCH_Calibrate", LCD_GetXSize() / 2, 5);
  118.   _WaitForPressedState(1);
  119.   _WaitForPressedState(0);
  120. }
  121. /*********************************************************************
  122. *
  123. *       Public code
  124. *
  125. **********************************************************************
  126. */
  127. /*********************************************************************
  128. *
  129. *       MainTask
  130. */
  131. void TouchCalibrate(void)
  132. {
  133.   int aPhysX[2], aPhysY[2], aLogX[2], aLogY[2], i;
  134.   GUI_SetBkColor(GUI_WHITE);
  135.   GUI_Clear();
  136.   GUI_SetColor(GUI_BLACK);
  137.   GUI_SetFont(&GUI_Font13B_ASCII);
  138.   _Explain();
  139.   /* Set the logical values */
  140.   aLogX[0] = 15;
  141.   aLogY[0] = 15;
  142.   aLogX[1] = LCD_GetXSize() - 15;
  143.   aLogY[1] = LCD_GetYSize() - 15;
  144.   /* Get the physical values of the AD converter for 2 positions */
  145.   for (i = 0; i < 2; i++) {
  146.     _GetPhysValues(aLogX[i], aLogY[i], &aPhysX[i], &aPhysY[i], _acPos[i]);
  147.   }
  148.   /* Use the physical values to calibrate the touch screen */
  149.   GUI_TOUCH_Calibrate(0, aLogX[0], aLogX[1], aPhysX[0], aPhysX[1]); /* Calibrate X-axis */
  150.   GUI_TOUCH_Calibrate(1, aLogY[0], aLogY[1], aPhysY[0], aPhysY[1]); /* Calibrate Y-axis */
  151.   /* Display the result */
  152.   GUI_CURSOR_Show();
  153.   GUI_Clear();
  154.   _DispStringCentered("Congratulation, your\n"
  155.                       "touch screen has been\n"
  156.                       "calibrated. Please use\n"
  157.                       "the cursor to test\n"
  158.                       "the calibration...");
  159.   GUI_Delay(500);
  160.   /* Let the user play */
  161. //  while(1) {
  162. //    GUI_PID_STATE State;
  163. //    GUI_TOUCH_GetState(&State);
  164. //    if (State.Pressed == 1) {
  165. //      GUI_FillCircle(State.x, State.y, 3);
  166. //    }
  167. //    GUI_Delay(10);
  168. //  }
  169. }
复制代码



回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115694
QQ
发表于 2015-11-12 20:42:16 | 显示全部楼层
向楼主确定几个问题:
1.  这个工程跑别的emWin例子有问题,是不是也有触摸问题。
2. 触摸的任务确定是否运行了。
3. 这两个函数
    WM_SetCreateFlags(WM_CF_MEMDEV);
    GUI_Init();
    换一下位置,如果函数WM_SetCreateFlags(WM_CF_MEMDEV);放在前面会导致桌面窗口也是用内存设备。
回复

使用道具 举报

1

主题

4

回帖

24

积分

新手上路

积分
24
 楼主| 发表于 2015-11-12 22:41:16 | 显示全部楼层
感谢,,已经解决了。
我理解错了。首先要使用
GUI_TOUCH_Calibrate(GUI_COORD_X,0,XSIZE_PHYS-1,TOUCH_AD_LEFT,TOUCH_AD_RIGHT);
GUI_TOUCH_Calibrate(GUI_COORD_Y,0,YSIZE_PHYS-1,TOUCH_AD_TOP,TOUCH_AD_BOTTOM);进行校准,初次校准之后才能使用GUI_TOUCH_GetState()获取触摸状态进行运行时校准。
如果不使用官方的校准代码,自行在初始化时校准也可以。
回复

使用道具 举报

1

主题

4

回帖

24

积分

新手上路

积分
24
 楼主| 发表于 2015-11-12 22:42:42 | 显示全部楼层
话说怎么结贴?
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115694
QQ
发表于 2015-11-13 09:39:07 | 显示全部楼层

回 xshenpan 的帖子

xshenpan:话说怎么结贴? (2015-11-12 22:42) 
没事,你回复了就可以了。[s:142]
回复

使用道具 举报

1

主题

4

回帖

24

积分

新手上路

积分
24
 楼主| 发表于 2015-11-14 12:15:33 | 显示全部楼层

回 eric2013 的帖子

eric2013:没事,你回复了就可以了。[s:142] (2015-11-13 09:39) 
[s:142]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-13 01:03 , Processed in 0.227777 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表