1 Star 0 Fork 1

qingsonggege / openwrt_mt7688_ctest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
readinput.c 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
Midas 提交于 2017-10-13 17:55 . input mousedev modified
/*-------------------------------------------------------------------
with reference to:
https://item.congci.com/-/content/linux-shubiao-shuju-duqu-caozuo
-------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <linux/input.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define LEFT_KEY 9
#define RIGHT_KEY 10
#define MIDDLE_KEY 12
int main(int argc,char **argv)
{
int fd,retval;
int nread;
int i;
unsigned char buf[8]={0};
fd_set readfds;
struct timeval tv;
if(argc<2)
{
printf(" Usage: %s dev_path \n",argv[0]);
exit(-1);
}
if( (fd=open(argv[1],O_RDONLY))<0)
{
printf(" Fail to open %s !\n",argv[1]);
exit(-1);
}
else
{
printf("Open %s successfuly!\n",argv[1]);
}
while(1)
{
tv.tv_sec=5;
tv.tv_usec=0;
FD_ZERO(&readfds);
FD_SET(fd,&readfds);
retval = select(fd+1, &readfds,NULL,NULL,&tv);
if(retval==0)
printf("Time out!\n");
if(FD_ISSET(fd,&readfds))
{
nread=read(fd,buf,8);
if(nread<0)
{
continue;
}
//printf("%d bytes data: 0x%02x, X:%d, Y:%d, Z:%d buf[4]=%d buf[7]=%d \n",nread,buf[0],buf[1],buf[2],buf[3],buf[4],buf[7]);
printf("%d bytes data: ",nread);
for(i=0;i<8;i++)
printf("buf[%d]=%d, ",i,buf[i]);
printf("\n");
//----------- react to mouse actions -----
switch(buf[0])
{
case LEFT_KEY:
system("mprev");
break;
case RIGHT_KEY:
system("mnext");
break;
default:
break;
}
}
}
close(fd);
return 0;
}
1
https://gitee.com/qingsonggege/openwrt_mt7688_ctest.git
git@gitee.com:qingsonggege/openwrt_mt7688_ctest.git
qingsonggege
openwrt_mt7688_ctest
openwrt_mt7688_ctest
master

搜索帮助