|
现在V5,V6和V7都已经统一,而且都是修改同样的函数实现。
裸机无需任何修改,emWin仅需对bsp_ts_touch.c文件函数TOUCH_PutKey做个修改:
- GUI_PID_STATE State;
- void TOUCH_PutKey(uint8_t _ucEvent, uint16_t _usX, uint16_t _usY)
- {
- #if 1
- uint16_t xx, yy;
- if (g_tTP.Enable == 1) /* 电阻屏。 形参是ADC值 */
- {
- xx = TOUCH_TransX(_usX, _usY);
- yy = TOUCH_TransY(_usX, _usY);
- }
- else /* GT811,FTX06,GT911 电容触摸走此分之 */
- {
- /* 无需转换, 直接是坐标值 */
- xx = _usX;
- yy = _usY;
- }
-
- /* 按下, 移动和松手事件 */
- switch (_ucEvent)
- {
- case TOUCH_DOWN:
- State.x = xx;
- State.y = yy;
- State.Pressed = 1;
- GUI_PID_StoreState(&State);
- break;
- case TOUCH_MOVE:
- State.x = xx;
- State.y = yy;
- State.Pressed = 1;
- GUI_PID_StoreState(&State);
- break;
- case TOUCH_RELEASE:
- State.Pressed = 0;
- GUI_PID_StoreState(&State);
- break;
- default:
- break;
- }
- #else
- uint16_t xx, yy;
- uint16_t x = 0, y = 0;
- g_tTP.Event[g_tTP.Write] = _ucEvent;
- if (g_tTP.Enable == 1) /* 电阻屏。 形参是ADC值 */
- {
- xx = TOUCH_TransX(_usX, _usY);
- yy = TOUCH_TransY(_usX, _usY);
- }
- else /* GT811,FTX06,GT911 电容触摸走此分之 */
- {
- /* 无需转换, 直接是坐标值 */
- xx = _usX;
- yy = _usY;
- }
-
- /* 横屏和竖屏方向识别 */
- switch (g_tTPParam.TouchDirection)
- {
- case 0: /* 校准触摸时,屏幕方向为0 */
- if (g_LcdDirection == 0) /* 横屏 */
- {
- x = xx;
- y = yy;
- }
- else if (g_LcdDirection == 1) /* 横屏180°*/
- {
- x = g_LcdWidth - xx - 1;
- y = g_LcdHeight - yy - 1;
- }
- else if (g_LcdDirection == 2) /* 竖屏 */
- {
- y = xx;
- x = g_LcdWidth - yy - 1;
- }
- else if (g_LcdDirection == 3) /* 竖屏180° */
- {
- y = g_LcdHeight - xx - 1;
- x = yy;
- }
- break;
- case 1: /* 校准触摸时,屏幕方向为1 */
- if (g_LcdDirection == 0) /* 横屏 */
- {
- x = g_LcdWidth - xx - 1;
- y = g_LcdHeight - yy - 1;
- }
- else if (g_LcdDirection == 1) /* 横屏180°*/
- {
- x = xx;
- y = yy;
- }
- else if (g_LcdDirection == 2) /* 竖屏 */
- {
- y = g_LcdHeight - xx - 1;
- x = yy;
- }
- else if (g_LcdDirection == 3) /* 竖屏180° */
- {
- y = xx;
- x = g_LcdWidth - yy - 1;
- }
- break;
- case 2: /* 校准触摸时,屏幕方向为2 */
- if (g_LcdDirection == 0) /* 横屏 */
- {
- y = xx;
- x = g_LcdWidth - yy - 1;
- }
- else if (g_LcdDirection == 1) /* 横屏180°*/
- {
- y = g_LcdHeight - xx - 1;
- x = yy;
- }
- else if (g_LcdDirection == 2) /* 竖屏 */
- {
- x = xx;
- y = yy;
- }
- else if (g_LcdDirection == 3) /* 竖屏180° */
- {
- x = g_LcdWidth - xx - 1;
- y = g_LcdHeight - yy - 1;
- }
- break;
- case 3: /* 校准触摸时,屏幕方向为3 */
- if (g_LcdDirection == 0) /* 横屏 */
- {
- y = xx;
- x = g_LcdWidth - yy - 1;
- }
- else if (g_LcdDirection == 1) /* 横屏180°*/
- {
- y = g_LcdHeight - xx - 1;
- x = yy;
- }
- else if (g_LcdDirection == 2) /* 竖屏 */
- {
- x = g_LcdWidth - xx - 1;
- y = g_LcdHeight - yy - 1;
- }
- else if (g_LcdDirection == 3) /* 竖屏180° */
- {
- x = xx;
- y = yy;
- }
- break;
- default:
- g_tTPParam.TouchDirection = 0; /* 方向参数无效时,纠正为缺省的横屏 */
- break;
- }
- g_tTP.XBuf[g_tTP.Write] = x;
- g_tTP.YBuf[g_tTP.Write] = y;
- if (++g_tTP.Write >= TOUCH_FIFO_SIZE)
- {
- g_tTP.Write = 0;
- }
-
- /* 调试语句,打印adc和坐标 */
- touch_printf("%d - (%d, %d) adcX=%d,adcY=%d\r\n", _ucEvent, x, y, g_tTP.usAdcNowX, g_tTP.usAdcNowY);
- #endif
- }
复制代码
同样,ThreadX GUIX也仅需对bsp_ts_touch.c文件函数TOUCH_PutKey做个修改:
- #include "gx_api.h"
- void TOUCH_PutKey(uint8_t _ucEvent, uint16_t _usX, uint16_t _usY)
- {
- #if 1
- uint16_t xx, yy;
- GX_EVENT event;
- if (g_tTP.Enable == 1) /* 电阻屏。 形参是ADC值 */
- {
- xx = TOUCH_TransX(_usX, _usY);
- yy = TOUCH_TransY(_usX, _usY);
- }
- else /* GT811,FTX06,GT911 电容触摸走此分之 */
- {
- /* 无需转换, 直接是坐标值 */
- xx = _usX;
- yy = _usY;
- }
-
- /* 按下, 移动和松手事件 */
- switch (_ucEvent)
- {
- case TOUCH_DOWN:
- event.gx_event_type = GX_EVENT_PEN_DOWN;
- event.gx_event_payload.gx_event_pointdata.gx_point_x = xx;
- event.gx_event_payload.gx_event_pointdata.gx_point_y = yy;
- event.gx_event_sender = 0;
- event.gx_event_target = 0;
- event.gx_event_display_handle = 0xC0000000;
- gx_system_event_send(&event);
- break;
- case TOUCH_MOVE:
- event.gx_event_type = GX_EVENT_PEN_DRAG;
- event.gx_event_payload.gx_event_pointdata.gx_point_x = xx;
- event.gx_event_payload.gx_event_pointdata.gx_point_y = yy;
- event.gx_event_sender = 0;
- event.gx_event_target = 0;
- event.gx_event_display_handle = 0xC0000000;
- gx_system_event_fold(&event);
- break;
- case TOUCH_RELEASE:
- event.gx_event_type = GX_EVENT_PEN_UP;
- event.gx_event_payload.gx_event_pointdata.gx_point_x = xx;
- event.gx_event_payload.gx_event_pointdata.gx_point_y = yy;
- event.gx_event_sender = 0;
- event.gx_event_target = 0;
- event.gx_event_display_handle = 0xC0000000;
- gx_system_event_send(&event);
- break;
- default:
- break;
- }
- #else
- uint16_t xx, yy;
- uint16_t x = 0, y = 0;
- g_tTP.Event[g_tTP.Write] = _ucEvent;
- if (g_tTP.Enable == 1) /* 电阻屏。 形参是ADC值 */
- {
- xx = TOUCH_TransX(_usX, _usY);
- yy = TOUCH_TransY(_usX, _usY);
- }
- else /* GT811,FTX06,GT911 电容触摸走此分之 */
- {
- /* 无需转换, 直接是坐标值 */
- xx = _usX;
- yy = _usY;
- }
-
- /* 横屏和竖屏方向识别 */
- switch (g_tTPParam.TouchDirection)
- {
- case 0: /* 校准触摸时,屏幕方向为0 */
- if (g_LcdDirection == 0) /* 横屏 */
- {
- x = xx;
- y = yy;
- }
- else if (g_LcdDirection == 1) /* 横屏180°*/
- {
- x = g_LcdWidth - xx - 1;
- y = g_LcdHeight - yy - 1;
- }
- else if (g_LcdDirection == 2) /* 竖屏 */
- {
- y = xx;
- x = g_LcdWidth - yy - 1;
- }
- else if (g_LcdDirection == 3) /* 竖屏180° */
- {
- y = g_LcdHeight - xx - 1;
- x = yy;
- }
- break;
- case 1: /* 校准触摸时,屏幕方向为1 */
- if (g_LcdDirection == 0) /* 横屏 */
- {
- x = g_LcdWidth - xx - 1;
- y = g_LcdHeight - yy - 1;
- }
- else if (g_LcdDirection == 1) /* 横屏180°*/
- {
- x = xx;
- y = yy;
- }
- else if (g_LcdDirection == 2) /* 竖屏 */
- {
- y = g_LcdHeight - xx - 1;
- x = yy;
- }
- else if (g_LcdDirection == 3) /* 竖屏180° */
- {
- y = xx;
- x = g_LcdWidth - yy - 1;
- }
- break;
- case 2: /* 校准触摸时,屏幕方向为2 */
- if (g_LcdDirection == 0) /* 横屏 */
- {
- y = xx;
- x = g_LcdWidth - yy - 1;
- }
- else if (g_LcdDirection == 1) /* 横屏180°*/
- {
- y = g_LcdHeight - xx - 1;
- x = yy;
- }
- else if (g_LcdDirection == 2) /* 竖屏 */
- {
- x = xx;
- y = yy;
- }
- else if (g_LcdDirection == 3) /* 竖屏180° */
- {
- x = g_LcdWidth - xx - 1;
- y = g_LcdHeight - yy - 1;
- }
- break;
- case 3: /* 校准触摸时,屏幕方向为3 */
- if (g_LcdDirection == 0) /* 横屏 */
- {
- y = xx;
- x = g_LcdWidth - yy - 1;
- }
- else if (g_LcdDirection == 1) /* 横屏180°*/
- {
- y = g_LcdHeight - xx - 1;
- x = yy;
- }
- else if (g_LcdDirection == 2) /* 竖屏 */
- {
- x = g_LcdWidth - xx - 1;
- y = g_LcdHeight - yy - 1;
- }
- else if (g_LcdDirection == 3) /* 竖屏180° */
- {
- x = xx;
- y = yy;
- }
- break;
- default:
- g_tTPParam.TouchDirection = 0; /* 方向参数无效时,纠正为缺省的横屏 */
- break;
- }
- g_tTP.XBuf[g_tTP.Write] = x;
- g_tTP.YBuf[g_tTP.Write] = y;
- if (++g_tTP.Write >= TOUCH_FIFO_SIZE)
- {
- g_tTP.Write = 0;
- }
-
- /* 调试语句,打印adc和坐标 */
- touch_printf("%d - (%d, %d) adcX=%d,adcY=%d\r\n", _ucEvent, x, y, g_tTP.usAdcNowX, g_tTP.usAdcNowY);
- #endif
- }
复制代码
|
|