dynamic generate command line parameters for qt embedded application
2015-09-17 11:34
399 查看
Read the fucking source code below.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <linux/input.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#define DIR_PATH "/dev/input"
#define NODE_PREFIX "event"
int main(int argc,char **argv)
{
DIR *tdir;
struct dirent *tdirent;
struct input_event tevent;
unsigned int evbit;
int fd;
unsigned char event_node_name[32];
int node_prefix_len=strlen(NODE_PREFIX);
int ret;
int valid_cnt=0;
int event_type;
//check input parameters.
if(argc<2)
{
printf("usage:%s <0/1>\n",argv[0]);
printf("<0>: scan mouse event nodes\n");
printf("<1>: scan keyboard event nodes\n");
return -1;
}
if(!strncmp(argv[1],"0",1))
{
event_type=EV_REL;
}else if(!strncmp(argv[1],"1",1))
{
event_type=EV_KEY;
}else{
printf("error:invalid scan type!\n");
return -1;
}
tdir=opendir(DIR_PATH);
if(!tdir)
{
printf("open dir failed!\n");
return -1;
}
while((tdirent=readdir(tdir))!=NULL)
{
if(!strncmp(tdirent->d_name,NODE_PREFIX,node_prefix_len))
{
sprintf(event_node_name,"%s/%s",DIR_PATH,tdirent->d_name);
//printf("%s,",event_node_name);
fd=open(event_node_name,O_RDONLY);
if(fd<0)
{
printf("open event node failed:%s\n",strerror(errno));
continue;
}
ret=ioctl(fd,EVIOCGBIT(0,EV_MAX),&evbit);
if(evbit&(0x1<<event_type))
{
printf("%s\n",event_node_name);
valid_cnt++;
}
close(fd);
}
}
closedir(tdir);
return valid_cnt;
}
#!/bin/bash
#brief:to solve match correct event node when EAVCapture starts.
#date:September 17,2015.
#author:zhangshaoyan,shell.albert@gmail.com
#qt's start command line parameters.
mouseplug=
kbdplug=
allplug="-platform linuxfb"
#scan /dev/input directory to get valid event that supports EV_REL.
./evtest.bin 0 > mouse_event.log
mouse_event_cnt=$?
#scan /dev/input diretory to get valid event that supports EV_KEY.
./evtest.bin 1 > kbd_event.log
kbd_event_cnt=$?
#generate the final one-line start parameter.
if [ $mouse_event_cnt -gt 0 ];then
while read line
do
mouseplug="$mouseplug -plugin evdevmouse:$line"
done < mouse_event.log
fi
if [ $kbd_event_cnt -gt 0 ];then
while read line
do
kbdplug="$kbdplug -plugin evdevkeyboard:$line"
done < kbd_event.log
fi
allplug="$allplug $mouseplug $kbdplug"
echo $allplug
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <linux/input.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#define DIR_PATH "/dev/input"
#define NODE_PREFIX "event"
int main(int argc,char **argv)
{
DIR *tdir;
struct dirent *tdirent;
struct input_event tevent;
unsigned int evbit;
int fd;
unsigned char event_node_name[32];
int node_prefix_len=strlen(NODE_PREFIX);
int ret;
int valid_cnt=0;
int event_type;
//check input parameters.
if(argc<2)
{
printf("usage:%s <0/1>\n",argv[0]);
printf("<0>: scan mouse event nodes\n");
printf("<1>: scan keyboard event nodes\n");
return -1;
}
if(!strncmp(argv[1],"0",1))
{
event_type=EV_REL;
}else if(!strncmp(argv[1],"1",1))
{
event_type=EV_KEY;
}else{
printf("error:invalid scan type!\n");
return -1;
}
tdir=opendir(DIR_PATH);
if(!tdir)
{
printf("open dir failed!\n");
return -1;
}
while((tdirent=readdir(tdir))!=NULL)
{
if(!strncmp(tdirent->d_name,NODE_PREFIX,node_prefix_len))
{
sprintf(event_node_name,"%s/%s",DIR_PATH,tdirent->d_name);
//printf("%s,",event_node_name);
fd=open(event_node_name,O_RDONLY);
if(fd<0)
{
printf("open event node failed:%s\n",strerror(errno));
continue;
}
ret=ioctl(fd,EVIOCGBIT(0,EV_MAX),&evbit);
if(evbit&(0x1<<event_type))
{
printf("%s\n",event_node_name);
valid_cnt++;
}
close(fd);
}
}
closedir(tdir);
return valid_cnt;
}
#!/bin/bash
#brief:to solve match correct event node when EAVCapture starts.
#date:September 17,2015.
#author:zhangshaoyan,shell.albert@gmail.com
#qt's start command line parameters.
mouseplug=
kbdplug=
allplug="-platform linuxfb"
#scan /dev/input directory to get valid event that supports EV_REL.
./evtest.bin 0 > mouse_event.log
mouse_event_cnt=$?
#scan /dev/input diretory to get valid event that supports EV_KEY.
./evtest.bin 1 > kbd_event.log
kbd_event_cnt=$?
#generate the final one-line start parameter.
if [ $mouse_event_cnt -gt 0 ];then
while read line
do
mouseplug="$mouseplug -plugin evdevmouse:$line"
done < mouse_event.log
fi
if [ $kbd_event_cnt -gt 0 ];then
while read line
do
kbdplug="$kbdplug -plugin evdevkeyboard:$line"
done < kbd_event.log
fi
allplug="$allplug $mouseplug $kbdplug"
echo $allplug
相关文章推荐
- Xcode 4.5( iOS6 SDK)、旧版本号cocos2d,支持iPhone5解析度
- Access the Spring-ApplicationContext from everywhere in your Application
- cocos2d-x --- 创建精灵的方法(3.x)
- Android-onInterceptTouchEvent()和onTouchEvent()总结---非常棒棒哒
- android添加wifi热点管理黑白名单
- Android之gallery 常见2种使用方法和3D效果总结
- iOS 9 适配系列教程
- Unity3D研究院之Assetbundle的实战(六十三)
- swift开发笔记4 - 设置tabbar选中颜色
- IOS开发之----property详解
- ios各种动画效果
- Android中Activity四种启动模式和taskAffinity属性详解
- Android之ListView
- android使用selector修改TextView中的字体颜色和背景颜色
- 常见Android开源框架使用笔记之——xUtils框架
- IOS 调用摄像头拍照
- Android SDK 完整版
- Android上下文菜单用法实例分析
- Android listview addHeaderView 和 addFooterView 详解 不显示问题
- iOS开发:MRC和ARC