Linux觸摸屏驅動測試程序范例【轉】


觸摸屏驅動測試

由於mini2440的觸摸屏驅動是基於input子系統的,而input子系統給用戶層提供的是input_event結構體,我們主要是在應用層接收這個結構體,然后對其類型進行分類,取出我們需要的數值。

struct input_event { struct timeval time;

       unsigned short type;  //支持的類型,如EV_ABS

       unsigned short code;   //支持的具體事件,如坐標事件的ABS_X

       unsigned int value;  //值

};

測試觸摸屏驅動的應用層代碼如下

#include

#include

#include

#include

#include

int main(int argc, char *argv[])

{

       int fd = -1;

       int num;

       size_t rb;

       int version;

       char name[20];

       struct input_event ev;

       int i=0;

       if ((fd = open("/dev/input/event0", O_RDONLY)) < 0)  //打開設備

       {

              perror("open error");

              exit(1);

       }

       while(1)

       {

              rb = read(fd, &ev, sizeof(struct input_event));  //讀取設備

              if (rb < (int)sizeof(struct input_event))  //讀取錯誤

              {

                     perror("read error");

                     exit(1);

              }

              if (EV_ABS==ev.type)                     //讀取按鍵內容

              {

              printf("event=%s,value=%d\n",ev.code==ABS_X?"ABS_X":ev.code==ABS_Y?"ABS_Y":ev.code==ABS_PRESSURE?"ABS_PRESSURE":"UNKNOWEN",ev.value);     

              }else{

              printf("not ev_abs\n");        

              }

       }    

        close(fd);

       return 0;

}

 

編譯測試程序test.c

arm-linux-gcc test.c –o test

超級終端:

./test

測試結果:(觸筆按下觸摸屏)

event=ABS_X, value=505

event=ABS_Y, value=334

event=ABS_PRESSURE, value=1


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM