手机版
你好,游客 登录 注册
背景:
阅读新闻

Linux下的触摸屏驱动

[日期:2012-12-17] 来源:CSDN  作者:weiqing1981127 [字体:大 中 小]

三.触摸屏驱动测试

由于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 <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <linux/input.h>

#include <sys/fcntl.h>

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

linux
相关资讯       Linux驱动开发  Linux触摸屏驱动 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款