主题 : 触摸屏的问题 复制链接 | 浏览器收藏 | 打印
级别: 侠客
UID: 12186
精华: 0
发帖: 96
金钱: 480 两
威望: 96 点
综合积分: 192 分
注册时间: 2009-12-31
最后登录: 2013-11-25
楼主  发表于: 2011-01-08 08:48

 触摸屏的问题

现在又一个问题,想读取触摸屏的坐标怎么读取啊,
触摸屏是输入子系统
是读取/dev/input/event0
但我只能读取一个坐标是对的
有人做过这个或者是知道触摸屏坐标怎么读取吗?
帮小弟一把
我写的程序为
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
#include <linux/input.h>

int main()
{
  int fd,count;
   struct input_event {
    struct timeval time;
    __u16 type;
    __u16 code;
    __s32 value;
    };
   struct input_event ev_button[3];
  fd = open("/dev/input/event0", 0);
   if (fd < 0) {
   perror("open device buttons");
     exit(1);
  }
  count=read(fd,ev_button,sizeof(struct input_event));
  printf("type:%d code:%d value:%d\n",ev_button[2].type,ev_button[2].code,ev_button[2].value);
   printf("type:%d code:%d value:%d\n",ev_button[0].type,ev_button[0].code,ev_button[0].value);
   printf("type:%d code:%d value:%d\n",ev_button[1].type,ev_button[1].code,ev_button[1].value);
  printf("type:%d code:%d value:%d\n",ev_button[3].type,ev_button[3].code,ev_button[3].value);
  close(fd);
  return 0;
}
级别: 荣誉会员
UID: 34761
精华: 0
发帖: 1348
金钱: 6835 两
威望: 1367 点
综合积分: 2696 分
注册时间: 2010-12-21
最后登录: 2017-06-02
1楼  发表于: 2011-01-08 10:56
Qtopia2.2.0是开源的,可以参考Qtopia2.2.0的相关代码, 或者tslib也是开源的啊
级别: 侠客
UID: 12186
精华: 0
发帖: 96
金钱: 480 两
威望: 96 点
综合积分: 192 分
注册时间: 2009-12-31
最后登录: 2013-11-25
2楼  发表于: 2011-01-08 11:36
解决了,那个国嵌视频上误导我了

把read里的sizeof(struct input_event)改成sizeof(ev_button)就好了