主题 : 应用层接收触摸屏上报的问题? 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 21390
精华: 0
发帖: 8
金钱: 45 两
威望: 9 点
综合积分: 16 分
注册时间: 2010-05-15
最后登录: 2011-05-02
楼主  发表于: 2011-01-17 20:05

 应用层接收触摸屏上报的问题?

触摸屏用的官方的驱动,应用程序如下:
#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
级别: 圣骑士
UID: 9221
精华: 0
发帖: 376
金钱: 2110 两
威望: 539 点
综合积分: 752 分
注册时间: 2009-09-22
最后登录: 2016-07-04
1楼  发表于: 2011-01-27 17:06
学习了
一起学习,一起进步