搜索
bottom↓
回复: 9

RTT触摸按键,为何无法释放,一直是按下的状态【自己已解决】。

[复制链接]

出0入0汤圆

发表于 2011-4-20 10:57:57 | 显示全部楼层 |阅读模式

(原文件名: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, 杜汶泽)

出0入0汤圆

 楼主| 发表于 2011-4-21 09:36:53 | 显示全部楼层
看来还是自己来吧,基本上是可以进行触摸的,现在还在改进,现在的智能手机的触摸操作就是不错啊,希望可以实现他们那样的操作,
我这样改动也许会有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[11] < 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));
   
}

出0入0汤圆

 楼主| 发表于 2011-4-21 14:57:24 | 显示全部楼层
通过修改,下面的可以很完美的解决通过查询进行触摸的操作,下拉菜单也不会出现由于多次发送坐标值而导致 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[15] < 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
        {
               //一直按住,就执行空操作
        }
    }
}

出0入0汤圆

发表于 2011-4-25 11:27:13 | 显示全部楼层
楼主解决能力真强

出0入0汤圆

发表于 2012-1-7 16:43:04 | 显示全部楼层
写得好, 感觉感谢 。

出0入0汤圆

发表于 2012-2-10 16:37:07 | 显示全部楼层
学习

出0入0汤圆

发表于 2012-2-11 10:09:47 | 显示全部楼层
mark

出0入0汤圆

发表于 2013-3-26 15:13:36 | 显示全部楼层
请问楼主,这个触摸屏的线程如何编写??

出0入0汤圆

 楼主| 发表于 2013-4-24 09:41:00 | 显示全部楼层
gosman 发表于 2013-3-26 15:13
请问楼主,这个触摸屏的线程如何编写??

官方有例程。

出0入0汤圆

发表于 2013-5-7 21:06:19 | 显示全部楼层
mark aaaaaaa
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-23 09:21

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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