RTT触摸按键,为何无法释放,一直是按下的状态【自己已解决】。
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 < 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));
} 看来还是自己来吧,基本上是可以进行触摸的,现在还在改进,现在的智能手机的触摸操作就是不错啊,希望可以实现他们那样的操作,
我这样改动也许会有bug吧。
/*************************************************/
static unsigned int flag = 0;
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 < 30)//无触摸操作
{
int tmer = RT_TICK_PER_SECOND/100 ;
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
emouse.button = (RTGUI_MOUSE_BUTTON_LEFT |RTGUI_MOUSE_BUTTON_UP);
//当触摸离开(不按下时),发送当时按下时的坐标值,如果不发送的话,就会出现一直按下的状态,说明没有释放按键
emouse.x = touch_previous.x ;
emouse.y = touch_previous.y ;
//清零
touch_previous.x = 0;
touch_previous.y = 0;
/* stop timer */
rt_timer_stop(touch->poll_timer);
flag = 0;
rt_timer_control(touch->poll_timer , RT_TIMER_CTRL_SET_TIME , &tmer);
}
else //有触摸
{
if(flag == 0)
{
int tmer = RT_TICK_PER_SECOND/20 ;
/* 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;
//记录此时的坐标值,up时用
touch_previous.x = touch->x;
touch_previous.y = touch->y;
/* init mouse button */
emouse.button = (RTGUI_MOUSE_BUTTON_LEFT |RTGUI_MOUSE_BUTTON_DOWN);
flag = 1;
rt_timer_control(touch->poll_timer , RT_TIMER_CTRL_SET_TIME , &tmer);
}
else //flag =1此时保持按住状态
{
/* 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;
/* init mouse button */
//这里设为右键或者零都可以但是这样像slider就无法实现拖动了。
//emouse.button = (RTGUI_MOUSE_BUTTON_RIGHT | RTGUI_MOUSE_BUTTON_DOWN);
emouse.button = 0;
}
}
/* send event to server */
if (touch->calibrating != RT_TRUE)
rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse));
} 通过修改,下面的可以很完美的解决通过查询进行触摸的操作,下拉菜单也不会出现由于多次发送坐标值而导致 send event to wb failed 的情况。
按下后就不必一直发送right/down ,保持住就默认一个值,离开就是up。
static unsigned int touch_flag = 0;
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 < 100)//无触摸操作
{
int tmer = RT_TICK_PER_SECOND/100 ;
if (1 == touch_flag)
{
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
emouse.button = (RTGUI_MOUSE_BUTTON_LEFT |RTGUI_MOUSE_BUTTON_UP);
emouse.x = touch_previous.x ;
emouse.y = touch_previous.y ;
/* send event to server */
if (touch->calibrating != RT_TRUE)
rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse));
touch_flag = 0;
}
/* stop timer */
rt_timer_stop(touch->poll_timer);
rt_timer_control(touch->poll_timer , RT_TIMER_CTRL_SET_TIME , &tmer);
}
else //有触摸
{
if(0 == touch_flag)
{
int tmer = RT_TICK_PER_SECOND/20 ;
/* calculation */
SPI2_Touch_Recieve_Data();//通过查询确定touch->x,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;
touch_previous.x = touch->x;
touch_previous.y = touch->y;
/* init mouse button */
emouse.button = (RTGUI_MOUSE_BUTTON_LEFT |RTGUI_MOUSE_BUTTON_DOWN);
touch_flag = 1;
rt_timer_control(touch->poll_timer , RT_TIMER_CTRL_SET_TIME , &tmer);
/* send event to server */
if (touch->calibrating != RT_TRUE)
rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse));
}
else //touch_flag =1
{
//一直按住,就执行空操作
}
}
} 楼主解决能力真强 写得好, 感觉感谢 。 学习 mark 请问楼主,这个触摸屏的线程如何编写?? gosman 发表于 2013-3-26 15:13 static/image/common/back.gif
请问楼主,这个触摸屏的线程如何编写??
官方有例程。 mark aaaaaaa
页:
[1]