Linux: 输入设备驱动测试程序

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:39   1889   0

测试写好的输入设备模块,比如遥控器,交叉编译后bin档放到rootfs/bin,直接运行

/* test remote.ko
* you should insmod remote.ko and config it before
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>

struct input_event buff;

int main(int argc, char **argv)
{
int fd;

printf("%s: entered/n", argv[0]);

fd = open("/dev/input/event0", O_RDONLY);
if(fd == -1) {
printf("open failed");
exit(-1);
}
printf("%s: open successful: %d/n", argv[0], fd);
while(1) {
if(read(fd,&buff,sizeof(struct input_event))!=0)
printf("type:%d code:%d value:%d/n",buff.type,buff.code,buff.value);
}

close(fd);

}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP