1. static struct input_dev *input_dev;//添加input设备定义,全局变量
2.
#if 1
int ret1;
input_dev = input_allocate_device();//创建input子系统设备
if (input_dev == NULL) {
printk("Failed to allocate input device for MID_RADER .");
return 0;
}
input_dev->name = MID_RADAR_DEVICE;
input_dev->id.bustype = BUS_HOST;
input_dev->id.vendor = 0x0001;
input_dev->id.product = 0x0001;
input_dev->id.version = 0x0100;//设置最基本的input参数
//input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY);
//input_dev->keybit[BIT_WORD(KEY_F5)] = BIT_MASK(KEY_F5);
//input_dev->keybit[BIT_WORD(KEY_F6)] = BIT_MASK(KEY_F6);
__set_bit(EV_SYN, input_dev->evbit);
__set_bit(EV_KEY, input_dev->evbit);
input_set_capability(input_dev,EV_KEY,KEY_F5);
input_set_capability(input_dev,EV_KEY,KEY_F6);//设置可允许上报的input类型
ret = input_register_device(input_dev);//注册input设备
if (ret) {
input_set_drvdata(input_dev, NULL);
input_free_device(input_dev);
input_dev = NULL;
printk("kzhkzhkzh Register %s input device failed", input_dev->name);
return 0;
}
#endif
3.然后可以封装input上报的函数:
static void mid_radar_input_key(bool on)
{
if (on == true) {
input_report_key(input_dev, KEY_F5, 1);
input_sync(input_dev);
mdelay(20);
input_report_key(input_dev, KEY_F5, 0);
input_sync(input_dev);
printk("[hpei_radar] radar is moving F5 !!!!! \n");
}else{
input_report_key(input_dev, KEY_F6, 1);
input_sync(input_dev);
mdelay(20);
input_report_key(input_dev, KEY_F6, 0);
input_sync(input_dev);
printk("[hpei_radar] radar is static F6 !!!!! \n");
}
}
F5、F6为定义的input键值,设计目的是为了在微波距感ic的中断处理函数中上报“远离”,“靠近”俩个概念事件,
mid_radar_input_key函数封装好后,即可在中断处理函数中调用:
static void mid_radar_ctrl_work_hander(struct work_struct *work)
{
mutex_lock(&mid_radar_ctrl_mutex);
if (cur_interrupt_state == INTERRUPT_MOVING){
mid_radar_input_key(1);//上报键值
}
else {
mid_radar_input_key(0);//上报键值
}
mutex_unlock(&mid_radar_ctrl_mutex);
enable_irq(mid_radar_irq);
}
最后,记得在static void __exit mid_radar_exit(void)
{
printk("[mid_radar] input_unregister_device !!!! \n");
input_unregister_device(input_dev);//unregister input_dev for mid rader//记得注销input_dev
platform_driver_unregister(&mid_radar_driver);
}
至此,已经可以在adb shell getevent -l中查看到微波距感触发“靠近”,“远离”时分别上报的键值。