|
![](http://cache.amobbs.com/bbs_upload782111/files_38/ourdev_632251LYALS9.jpg)
(原文件名:110420A001_副本.jpg)
触摸按下时,可以显示按下状态,但是不触摸的时候,并没有进行显示未按状态,并进行画面切换,请教各位改如何解决。
由于我的触摸芯片中断无反应,我一直用的是spi的中断,进而进行查询。
void touch_timeout(void* parameter)
{
struct rtgui_event_mouse emouse;
static struct _touch_previous
{
rt_uint32_t x;
rt_uint32_t y;
} touch_previous;
if (SPI2_Touch_temp[11] < 30)//无触摸操作
{
int tmer = RT_TICK_PER_SECOND/100 ;
if (flag == 1)
{
//
//EXTI_Enable(1);
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
emouse.button = (RTGUI_MOUSE_BUTTON_LEFT |RTGUI_MOUSE_BUTTON_UP);
/* use old value */
emouse.x = touch->x;
emouse.y = touch->y;
/* stop timer */
rt_timer_stop(touch->poll_timer);
// rt_kprintf("touch up: (%d, %d)\n", emouse.x, emouse.y);
flag = 0;
}
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
{
/* callback function */
touch->calibration_func(emouse.x, emouse.y);
}
rt_timer_control(touch->poll_timer , RT_TIMER_CTRL_SET_TIME , &tmer);
}
else //有触摸
{
if(flag == 0)
{
int tmer = RT_TICK_PER_SECOND/100 ;
/* calculation */
SPI2_Touch_Recieve_Data();
/* send mouse event */
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
emouse.parent.sender = RT_NULL;
emouse.x = touch->x;
emouse.y = touch->y;
touch_previous.x = touch->x;
touch_previous.y = touch->y;
/* init mouse button */
emouse.button = (RTGUI_MOUSE_BUTTON_LEFT |RTGUI_MOUSE_BUTTON_DOWN);
//rt_kprintf("touch down: (%d, %d)\n", emouse.x, emouse.y);
flag = 1;
rt_timer_control(touch->poll_timer , RT_TIMER_CTRL_SET_TIME , &tmer);
}
else //flag =1
{
/* calculation */
SPI2_Touch_Recieve_Data();
#define previous_keep 8
//判断移动距离是否小于previous_keep,减少误动作.
if(
(touch_previous.x < touch->x + previous_keep)
&& (touch_previous.x > touch->x - previous_keep )
&& (touch_previous.y < touch->y + previous_keep)
&& (touch_previous.y> touch->y - previous_keep))
{
return;
}
touch_previous.x = touch->x;
touch_previous.y = touch->y;
/* send mouse event */
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON ;
emouse.parent.sender = RT_NULL;
emouse.x = touch->x;
emouse.y = touch->y;
/* init mouse button */
//emouse.button = (RTGUI_MOUSE_BUTTON_LEFT |RTGUI_MOUSE_BUTTON_DOWN);
emouse.button = 0;
// rt_kprintf("touch motion: (%d, %d)\n", emouse.x, emouse.y);
}
}
/* send event to server */
if (touch->calibrating != RT_TRUE)
rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse));
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|