转自:https://www.cnblogs.com/0822vaj/p/4185634.html

-----------------------------------------------------------------------
本文系本站原创,欢迎转载!
转载请注明出处:http://blog.csdn.net/android_huber
交流邮箱:dp.shao@gmail.com
-----------------------------------------------------------------------

linux drive中input子系统上报信息,调用函数

void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value),

input子系统最终调用copy_to_user(buffer, event, sizeof(struct input_event))将信息上报给上层,event为struct input_event类型结构体, 中间会有一些处理将 type,code,value值打包成input_event类型的数据。底层上报该结构体给上层。

struct input_event {

struct timeval time;

__u16 type;

__u16 code;

__s32 value;

};

struct timeval {

__kernel_time_t tv_sec; /* seconds */

__kernel_suseconds_t tv_usec; /* microseconds */

};

typedef long        __kernel_time_t;

typedef int __kernel_suseconds_t;

对于按键

type为事件类型,按键为EV_KEY,在include/linux/input.h中,

#define EV_KEY    0x01

code为按键的值,value用于标记按键是按下还是弹起,1是按下,0是弹起。

按下和弹起事件只需上报一次。

对于touch

static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)  为input_event的封装,函数如下

input_event(dev, EV_ABS, code, value);

type为EV_ABS,  #define EV_ABS   0X03,

code的值,根据上报属性的不同,分别如下:

(多点触摸)

#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */

#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */

#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */

#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */

#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */

#define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */

#define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */

#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */

#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */

#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */

#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */

ABS_MT_TOUCH_MAJOR和ABS_MT_PRESSURE实现一个应该就可以了。

(单点触摸)input.h中列举了很多属性,但只需实现以下几种即可。

#define ABS_X 0x00

#define ABS_Y 0x01

#define ABS_Z 0x02  (一般不必实现)

#define ABS_PRESSURE 0x18

下面一个BTN_TOUCH为点击事件,单点触摸中需要上报点击事件

#define BTN_TOUCH 0x14a

touch点上报机制

多点触摸

value为对应属性的值,如code为ABS_MT_POSITION_X,则value的值为就为x轴坐标。

当把一个点的信息发送完毕以后,还需加上input_mt_sync(注意:即使只有一个点也需要加上),这个函数转换成input_event事件为

input_event(dev, EV_SYN, SYN_MT_REPORT, 0);

其中#define EV_SYN  0x00,   #define SYN_MT_REPORT    2,

则type为0x00,code为2,value为0。

接着再上报第二个点,第二个点上报结束,依旧要上报input_mt_sync,直至最后一次报点结束,加上input_sync,转换成input_event事件为

input_event(dev, EV_SYN, SYN_REPORT, 0);

其中#define EV_SYN  0x00,#define SYN_REPORT 0,

则type为0x00,code为0,value为0。至此报点结束。

点需要一直上报。

Linux 驱动中的例子

input_report_abs(ssd2531_data.input, ABS_MT_TRACKING_ID, 1);

input_report_abs(ssd2531_data.input, ABS_MT_TOUCH_MAJOR, PRESS_STATUS);

input_report_abs(ssd2531_data.input, ABS_MT_POSITION_X, X_COOR);

input_report_abs(ssd2531_data.input, ABS_MT_POSITION_Y, Y_COOR);

input_mt_sync(ssd2531_data.input);

单点触摸

单点上报同多点上报差不多,只是不需要input_mt_sync了,上报过程中需要

input_event(dev, EV_KEY, BTN_TOUCH,  0/1 );  value为1,代表按下,value为0代表抬起。code值为BTN_TOUCH,  #define BTN_TOUCH 0x14a;

同样最后结束需要input_sync。

linux驱动的例子‘

input_report_abs(ts.input, ABS_X, ts.xp);

input_report_abs(ts.input, ABS_Y, ts.yp);

input_report_key(ts.input, BTN_TOUCH, 1);

input_sync(ts.input);

input_event结构体中,有一个成员为struct timeval time;用来记录此刻的墙上时间。

input子系统 KeyPad-Touch上报数据格式与机制【转】的更多相关文章

  1. input子系统 KeyPad-Touch上报数据格式与机制

    -----------------------------------------------------------------------本文系本站原创,欢迎转载!转载请注明出处:http://b ...

  2. Input子系统与多点触摸技术-3【转】

    转自:https://blog.csdn.net/u012839187/article/details/77335941 版权声明:本文为博主原创文章,欢迎转载,转载请注明转载地址 https://b ...

  3. 基于input子系统的sensor驱动调试(一)

    要想弄明白世界的本质,就要追根溯源:代码也是一样的道理: 最近调试几个sensor驱动,alps sensor驱动.compass sensor驱动.G-sensor驱动都是一样的架构: 一.基于in ...

  4. Linux Input子系统浅析(二)-- 模拟tp上报键值【转】

    转自:https://blog.csdn.net/xiaopangzi313/article/details/52383226 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...

  5. Linux--内核Uevent事件机制 与 Input子系统【转】

    转自:http://blog.csdn.net/lxl584685501/article/details/46379453 [-] 一Uevent机制 Uevent在kernel中的位置 Uevent ...

  6. Android驱动之 Linux Input子系统之TP——A/B(Slot)协议

    将A/B协议这部分单独拿出来说一方面是因为这部分内容是比较容易忽视的,周围大多数用到input子系统的开发人员也不甚理解:另一方面是由于这部分知识一旦扩展到TP(触摸屏Touch Panel)的多点触 ...

  7. input子系统事件处理层(evdev)的环形缓冲区【转】

    在事件处理层(evdev.c)中结构体evdev_client定义了一个环形缓冲区(circular buffer),其原理是用数组的方式实现了一个先进先出的循环队列(circular queue), ...

  8. 【驱动】input子系统全面分析

    初识linux输入子系统 linux输入子系统(linux input subsystem)从上到下由三层实现,分别为:输入子系统事件处理层(EventHandler).输入子系统核心层(InputC ...

  9. linux input输入子系统分析《四》:input子系统整体流程全面分析

    1      input输入子系统整体流程 本节分析input子系统在内核中的实现,包括输入子系统(Input Core),事件处理层(Event Handler)和设备驱动层.由于上节代码讲解了设备 ...

随机推荐

  1. App Inventor2项目部署到本地

    介绍App Inventor App Inventor 原是Google实验室(Google Lab)的一个子计划,该项目是一个完全在线开发的Android编程环境,抛弃复杂的程式代码而使用积木式的堆 ...

  2. 优先队列Priority Queue和堆Heap

    对COMP20003中的Priority queue部分进行总结.图片来自于COMP20003 queue队列,顾名思义特点先进先出 priority queue优先队列,出来的顺序按照优先级prio ...

  3. Jmeter二次开发代码(2)

    /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreem ...

  4. WebApi(五)-Swagger接口文档①简单集成

    1,通过NuGet引用Swashbuckle 2,打开项目属性-->生成,勾选XML文档文件,保存 3,找到项目App_Start文件夹下WebApiConfig查找GetXmlComments ...

  5. [转帖]Oracle 补丁体系(PSR/PSU/CPU) 及 opatch 工具 介绍

    Oracle 补丁体系(PSR/PSU/CPU) 及 opatch 工具 介绍 原文:http://blog.csdn.net/tianlesoftware/article/details/58095 ...

  6. AtCoder ABC 042D いろはちゃんとマス目 / Iroha and a Grid

    题目链接:https://abc042.contest.atcoder.jp/tasks/arc058_b 题目大意: 给定一个 H * W 的矩阵,其中左下角 A * B 区域是禁区,要求在不踏入禁 ...

  7. 我的CSS

    外框 固定宽高 内容居中 height: 200px ; width:200px; margin: 50rpx  auto 0 auto;     //上下居中 text-align: center; ...

  8. 【10】Cookie和Session

    一.cookie和session的介绍 cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们却又需要"保持状态",因此cookie就是在这样一个场景下 ...

  9. 关于TVWALL 通过AS300获取状态连接失败

    昨天晚会突然之间频繁出现tvwall视频软件,断开AS300管理软件的故障 发现AS300当中的cms服务进程,占用内存250M左右,一般情况下估计就是50M左右,增长了不少 无奈之下,只有重启AS3 ...

  10. java文件运行的过程

    javac .java——>编译成.class文件(字节码) 参考: https://www.cnblogs.com/yxwkf/p/3855363.html https://www.jians ...