觸摸屏驅動測試
由于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
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
本文轉自張昺華-sky部落格園部落格,原文連結:http://www.cnblogs.com/sky-heaven/p/5107987.html,如需轉載請自行聯系原作者