|
触摸屏用的tq的驱动编写的应用如下:
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <linux/input.h>
#include <stdlib.h>
#include <string.h>
int fd;
struct input_event event;
void input_handler(int signum)
{
if(read( fd, &event, sizeof(struct input_event))<0)
{
perror("read:");
}
if((event.type==3)&&(event.code==0))printf("x value: %d\n",event.value);
else if((event.type==3)&&(event.code==1))printf("y value: %d\n",event.value);
else if((event.type==3)&&(event.code==24))printf("press value: %d\n",event.value);
else if((event.type==0)&&(event.code==0))printf(" sync \n\n ");
else printf("none \n");
//printf("type is:%d ",event.type);
//printf("code is:%d ",event.code);
//printf("value is:%d\n",event.value);
}
main()
{
int oflags;
fd = open("/dev/event0", O_RDWR);
if (fd != - 1)
{
fsync(fd);
signal(SIGIO, input_handler);
fcntl(fd, F_SETOWN, getpid());//IO所有权
oflags = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, oflags | FASYNC); //文件状态标记
while(1);
}
else
{
printf("device open failure\n");
}
}
暂时忽略触摸屏校正,执行时有以下几个问题:
1.上报的数据有延迟,比如我现在A点附近按了几下,然后在B点按,这时候上报的是A点附近的数据,过一会才会出现B点的数据。
2.上报的有时不是按照规定的格式上报的:比如应该是x value: 179 y value: 194 sync 但是有时候报的是x value: 149 sync 或者是 y value: 872 sync |
|