zoukankan      html  css  js  c++  java
  • 项目中的小bug

    最近在做电子书项目中,采用select方式输入子系统,运行后发现键盘输入没问题,可是触摸屏却没反应,触摸屏驱动没问题,tslib也移植正确。问题在哪呢?
    在代码中加入打印语句:

     54 static int isOutOf500ms(struct timeval *ptPreTime, struct timeval *ptNowTime)
     55 {
     56     int iPreMs;
     57     int iNowMs;
     58     
     59     iPreMs = ptPreTime->tv_sec * 1000 + ptPreTime->tv_usec / 1000;
     60     iNowMs = ptNowTime->tv_sec * 1000 + ptNowTime->tv_usec / 1000;
     61     printf("PreTime %d ms , NowTime%d ms
    ",iPreMs,iNowMs);
     62 
     63     return (iNowMs > iPreMs + 500);
     64 }
     65 
     66 static int TouchScreenGetInputEvent(PT_InputEvent ptInputEvent)
     67 {
     68     struct ts_sample tSamp;
     69     int iRet;
     70 
     71     static struct timeval tPreTime;
     72     printf("PreTime %ld:%ld
    ",tPreTime.tv_sec,tPreTime.tv_usec);
     73 
     74     iRet = ts_read(g_tTSDev, &tSamp, 1);
     75     printf("tSamp : %ld.%06ld: %6d %6d %6d
    ", tSamp.tv.tv_sec, tSamp.tv.tv_usec, tSamp.x, tSamp.y, tSamp.pressure);
     76 
     77     if (iRet < 0) {
     78         return -1;
     79     }
     80 
     81     if (isOutOf500ms(&tPreTime, &tSamp.tv))
     82     {
     83         tPreTime = tSamp.tv;
     84         ptInputEvent->tTime = tSamp.tv;
     85         ptInputEvent->iType = INPUT_TYPE_TOUCHSCREEN;
     86 
     87         if (tSamp.y < giYres/3)
     88         {
     89             ptInputEvent->iVal = INPUT_VALUE_UP;
     90         }
     91         else if (tSamp.y > 2*giYres/3)
     92         {
     93             ptInputEvent->iVal = INPUT_VALUE_DOWN;
     94         }
     95         else
     96         {
     97             ptInputEvent->iVal = INPUT_VALUE_UNKNOWN;
     98         }
     99         printf("Out 500ms
    ");
    100         printf("Y = %d,giYres = %d
    ",tSamp.y,giYres);
    101         return 0;
    102         
    103     }
    104     else
    105     {
    106         printf("In 500ms
    ");
    107         return -1;
    108     }
    109     
    110 
    111     return 0;
    112 }

    输出结果如下:

    观察红色圈中的,PreTime为正,NowTime为负,那么NowTime永远不可能大于PreTime,所以永远返回0,所以触摸屏不会有反应。
    在源码中,iPreMs,iNowMs定义为:
    int iPreMs;
    int iNowMs;
    修改为:
    unsigned int iPreMs;
    unsigned int iNowMs;
    运行结果如下:


    完美运行。

    虽然这只是一个小小的bug,但是我也是经过三天茶饭不思般的思考才找到的,阅读tslib源码库,自己重写代码,也是走了好大的弯路,但是,其中积累的经验也是不可多得的。

    ————————————————————————————————————————————————————————————————————————————— 无他,唯手熟尔。。。
  • 相关阅读:
    openstack newton 版本 horizon二次开发
    ubuntu 远程root登录
    记录一次用户态踩内存问题
    (leetcode)二叉树的前序遍历-c语言实现
    通过blacklist来禁用驱动
    最小栈问题
    判断是否为环形链表
    按照层次序列创建二叉树,并判断二叉树是否为二叉搜索树
    操作系统交付时需要做哪些安全检查项
    RDMA相关的技术网站
  • 原文地址:https://www.cnblogs.com/ZXNblog/p/4034952.html
Copyright © 2011-2022 走看看