Linux输入子系统模型:
Input Device Driver:输入设备驱动,需要用户自己实现
Input Core:输入子系统核心部分,Linux内核已经做好
Input Event Driver:输入时间驱动,Linux内核已经做好
Hardware:输入设备
任何一次输入事件,如鼠标移动, 按键按下,都需要通过InputDeviceDriver- >InputCore- >EventDrive才能到达用 户 空间的应用程序。
设备驱动层:将底层的硬件输入转化为统一事件型式, 向输入核心( InputCore)汇报。
输入核心层:为设备驱动层提供输入设备注册与操作接口,如:为设备驱动层提供输入设备注册与操作接口 , 如:input_register_device;通知事件处理层对事件进行处理。
事件驱动层:主要作用是和用户空间交互, 如提供read, open等设备方法, 创建设备文件等。
Linux输入子系统驱动设计流程:
Linux输入子系统事件类型:
EV_RST:
Reset
EV_REL:
相对坐标
EV_MSC:
其他
EV_SND:
声音
EV_REP:
Repeat
EV_FF:
力反馈
EV_KEY:
绝对坐标
EV_ABS:
绝对坐标
EV_LED:
LED
......
Linux输入子系统---应用程序示例:
Controlling the playback of effects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Control of playing is done with write(). Below is an example:
#include <linux/input.h>
#include <unistd.h>
struct input_event play;
struct input_event stop;
struct ff_effect effect;
int fd;
...
fd = open("/dev/input/eventXX", O_RDWR);
...
/* Play three times */
play.type = EV_FF;
play.code = effect.id;
play.value = 3;
write(fd, (const void*) &play, sizeof(play));
...
/* Stop an effect */
stop.type = EV_FF;
stop.code = effect.id;
stop.value = 0;
write(fd, (const void*) &play, sizeof(stop));
Information about the status of effects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Every time the status of an effect is changed, an event is sent. The values and meanings of the fields of the event are as follows:
struct input_event
{ /* When the status of the effect changed */
truct timeval time;
/* Set to EV_FF_STATUS */
nsigned short type;
/* Contains the id of the effect */
unsigned short code;
/* Indicates the status */
unsigned int value;
};
FF_STATUS_STOPPED The effect stopped playing FF_STATUS_PLAYING The effect started to play