input 输入子系统

在应用层使用的时候,容易出现找不到UEventObserver.java 这时候就要导入jar包
导入classes.jar这个jar包

weiqifa@weiqifa-Inspiron-3847:~/weiqifa/tm100$ ls out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/
classes  classes.dex  classes-full-debug.jar  classes.jar  classes-jarjar.jar  emma_out  javalib.jar  noproguard.classes.jar  noproguard.classes-with-local.dex
weiqifa@weiqifa-Inspiron-3847:~/weiqifa/tm100$

问题:最近我自己比较了这两个的作用,我们以前经常用这个来获取底层上报的值,用来做usb插入,键盘输入等

区别: input 如果上报的值是1 ,在framework里面就一直获取这个键值,这个是按键的特性

D/WindowManager(  632): interceptKeyTi keyCode=42 down=true repeatCount=1427 keyguardOn=true mHomePressed=false canceled=false metaState:0
D/WindowManager(  632): interceptKeyTi keyCode=42 down=true repeatCount=1428 keyguardOn=true mHomePressed=false canceled=false metaState:0
D/WindowManager(  632): interceptKeyTi keyCode=42 down=true repeatCount=1429 keyguardOn=true mHomePressed=false canceled=false metaState:0
D/WindowManager(  632): interceptKeyTi keyCode=42 down=true repeatCount=1430 keyguardOn=true mHomePressed=false canceled=false metaState:0
D/WindowManager(  632): interceptKeyTi keyCode=42 down=true repeatCount=1431 keyguardOn=true mHomePressed=false canceled=false metaState:0

linux uevent

这个就是比input区别在于输入的时候不会一直上报1,使用也比较方便

底层发送的关键代码

    char *envp[2];int ret;if(work_flag==true){envp[0]="CAMERA=close";envp[1]=NULL;//关键是kobj这个kobj 要从生成dev的地方去找到ret = kobject_uevent_env(&hdyrodent_hall_class_dev->kobj, KOBJ_CHANGE,envp);if(ret<0){printk("%s kobject error\n",__func__);  }else{printk("%s kobject uevent report close success!!!\n",__func__);     }   printk("------------>%s<------------%s\n",__FUNCTION__,kobject_get_path(&hdyrodent_hall_class_dev->kobj,GFP_KERNEL));}

Android接收
event.get(“CAMERA”); 这个是上报的=号前面的,然后就可以获取来比较就可以了

//weiqifa modify for the hall ueventprivate UEventObserver mHALLObserver = new UEventObserver() {@Overridepublic void onUEvent(UEventObserver.UEvent event) {String camera = event.get("CAMERA");Slog.d(TAG, "------------------------------->camera=" + camera);if("open".equals(event.get("CAMERA"))){ //磁铁离开的时候这时候应该是打开摄像头的时候Slog.d(TAG, "------------------------------->Open the camera app!!!!=" + camera);Intent intent = new Intent("com.key.android.KEY_CAMERA_OPEN");mContext.sendBroadcast(intent);startAPP("com.android.gallery3d");}else if("close".equals(event.get("CAMERA"))){//磁铁接触的时候就会一直发送down 过来 这时候应该是关闭摄像头的Slog.d(TAG, "------------------------------->Close the camera app!!!!=" + camera);Intent intent = new Intent("com.key.android.KEY_CAMERA_CLOSE");mContext.sendBroadcast(intent);stopAPP("com.android.gallery3d");WriteInt("/sys/class/hdyrodent/cameraflash",0);//关闭闪光灯}           }};

然后再找个地方运行一下这句代码

//weiqifa modify add mHALLObserver.startObserving("DEVPATH=/devices/virtual/hdyrodent_hall_class/hdyrodent_hall");

/devices/virtual/hdyrodent_hall_class/hdyrodent_hall 这个是我们在驱动下面生成的,驱动上报的时候我用个函数把它打印出来了,前面的DEVPATH=这个是一定要加的。

然后我还是写一下这个目录是怎么来的,看下面的代码

//weiqifa modify for hallhdyrodent_hall_class = class_create(THIS_MODULE,"hdyrodent_hall_class");if (IS_ERR(hdyrodent_hall_class)) {pr_err("%s: class_create() failed hdyrodent_hall_class\n", __func__);class_destroy(hdyrodent_hall_class);}//add device to class hdyrodent_hall_class_dev = device_create(hdyrodent_hall_class, NULL,hdyrodent_hall_device_no, NULL, "hdyrodent_hall");if (!hdyrodent_hall_class_dev) {pr_err("%s: class_device_create failed hdyrodent_hall \n", __func__);device_destroy(hdyrodent_hall_class, hdyrodent_hall_device_no);}//weiqifa modify for hall end

底层例子

/** drivers/leds/leds-mt65xx.c** This file is subject to the terms and conditions of the GNU General Public* License.  See the file COPYING in the main directory of this archive for* more details.** Hydrodent weiqifa modify add**/#include <linux/module.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/input.h>
#include <mach/upmu_hw.h>
#include <mach/mt_boot.h>
#include <mach/mt_gpio.h>
#include <mach/eint.h>
#include <cust_eint.h>
#include "cust_gpio_usage.h"
#include <mach/mt_pm_ldo.h>
#include <linux/workqueue.h>extern void mt_eint_unmask(unsigned int eint_num);
extern void mt_eint_set_polarity(unsigned int eint_num, unsigned int pol);
extern void mt_eint_set_hw_debounce(unsigned int eintno, unsigned int ms);
extern unsigned int mt_eint_set_sens(unsigned int eintno, unsigned int sens);
extern void mt_eint_registration(unsigned int eint_num, unsigned int flag, void (EINT_FUNC_PTR) (void), unsigned int is_auto_umask);//struct input_dev *hdy_input_dev;
static struct class *hdyrodent_hall_class = NULL;//weiqifa modify add
static dev_t hdyrodent_hall_device_no;//weiqifa modify add
struct device *hdyrodent_hall_class_dev;//weiqifa modify add
struct work_struct hall_work;
struct workqueue_struct *hall_wq;
static bool work_flag=false;void hall_func(struct work_struct *work)
{char *envp[2];int ret;if(work_flag==true){envp[0]="CAMERA=close";envp[1]=NULL;ret = kobject_uevent_env(&hdyrodent_hall_class_dev->kobj, KOBJ_CHANGE,envp);if(ret<0){printk("%s kobject error\n",__func__);  }else{printk("%s kobject uevent report close success!!!\n",__func__);     }   printk("------------>%s<------------%s\n",__FUNCTION__,kobject_get_path(&hdyrodent_hall_class_dev->kobj,GFP_KERNEL));}else if(work_flag==false){envp[0]="CAMERA=open";envp[1]=NULL;ret = kobject_uevent_env(&hdyrodent_hall_class_dev->kobj, KOBJ_CHANGE,envp);if(ret<0){printk("%s kobject error\n",__func__);  }else{printk("%s kobject uevent report open success!!!\n",__func__);      }printk("------------>%s<------------%s\n",__FUNCTION__,kobject_get_path(&hdyrodent_hall_class_dev->kobj,GFP_KERNEL));}
}//中断服务函数
void hal_eint_interrupt_handler(void)
{char *envp[2];int ret;printk("------------>%s<------------ GPIO_MHALL_EINT_PIN value=%d\n",__FUNCTION__,mt_get_gpio_in(GPIO_MHALL_EINT_PIN));/*设置中断触发方式,打开摄像头后产生了一次中断,然后改变中断触发方式,关闭摄像头后又会产生一次关闭摄像头的中断*/if(mt_get_gpio_in(GPIO_MHALL_EINT_PIN)){mt_eint_set_polarity(CUST_EINT_MHALL_NUM, MT_EINT_POL_NEG);//中断触发方式设置成下降沿  关闭摄像头queue_work(hall_wq, &hall_work);work_flag=false;}else{mt_eint_set_polarity(CUST_EINT_MHALL_NUM, MT_EINT_POL_POS);//中断触发方式设置成上升沿  打开摄像头queue_work(hall_wq, &hall_work);work_flag=true;     }mt_eint_unmask(CUST_EINT_MHALL_NUM);
}static int __init hdyrodent_hall_init(void)
{int err = -1;//int r=0;hall_wq=create_workqueue("hall_wq");printk("%s mhall_pin value=%d start\n",__FUNCTION__,mt_get_gpio_in(GPIO_MHALL_EINT_PIN));//weiqifa modify for hallhdyrodent_hall_class = class_create(THIS_MODULE,"hdyrodent_hall_class");if (IS_ERR(hdyrodent_hall_class)) {pr_err("%s: class_create() failed hdyrodent_hall_class\n", __func__);class_destroy(hdyrodent_hall_class);}//add device to class hdyrodent_hall_class_dev = device_create(hdyrodent_hall_class, NULL,hdyrodent_hall_device_no, NULL, "hdyrodent_hall");if (!hdyrodent_hall_class_dev) {pr_err("%s: class_device_create failed hdyrodent_hall \n", __func__);device_destroy(hdyrodent_hall_class, hdyrodent_hall_device_no);}//weiqifa modify for hall end//霍尔开关电源控制if(hwPowerOn(MT6323_POWER_LDO_VIBR, VOL_2800, "VIBR")) {printk("Success: open the MT65XX_POWER_LDO_VIBR 2.8V\n");}//Init the irq gpio1_interruptmt_set_gpio_mode(GPIO_MHALL_EINT_PIN, GPIO_MHALL_EINT_PIN_M_EINT);mt_set_gpio_dir(GPIO_MHALL_EINT_PIN, GPIO_DIR_IN);mt_set_gpio_pull_enable(GPIO_MHALL_EINT_PIN, GPIO_PULL_ENABLE);mt_set_gpio_pull_select(GPIO_MHALL_EINT_PIN, GPIO_PULL_UP);msleep(50);/*mt_eint_set_hw_debounce设置抖动mt_eint_registration第一个是中断号,触发极性,第二个是设定是否开启抖动,第三个是绑定中断函数,第四个关闭中断mt_eint_unmask屏蔽中断    */mt_eint_set_hw_debounce(CUST_EINT_MHALL_NUM, CUST_EINT_MHALL_DEBOUNCE_CN);mt_eint_registration(CUST_EINT_MHALL_NUM, CUST_EINT_MHALL_TYPE, hal_eint_interrupt_handler, 0);mt_eint_unmask(CUST_EINT_MHALL_NUM);//工作队列INIT_WORK(&hall_work, hall_func);printk("%s end\n", __FUNCTION__);return 0;}static void __exit hdyrodent_hall_exit(void)
{class_destroy(hdyrodent_hall_class);device_destroy(hdyrodent_hall_class, hdyrodent_hall_device_no);printk("hdyrodent module cleanup OK!\n");
}MODULE_AUTHOR("329410527@qq.com");
MODULE_DESCRIPTION("HDYRODENT HALL MODULE");
MODULE_LICENSE("GPL");
MODULE_VERSION("ver0.1");module_init(hdyrodent_hall_init);
module_exit(hdyrodent_hall_exit);

linux inputuevent使用相关推荐

  1. 过滤Linux下不同大小的文件,linux查找当前目录下 M/G 大小的文件,删除Linux下指定大小的文件

    过滤Linux下不同大小的文件,linux查找当前目录下 M/G 大小的文件,删除Linux下指定大小的文件 find ./ -type f -size +1G| xargs rm 在清理系统日志文件 ...

  2. linux环境下nacos的安装+启动,阿里云服务器安装nacos

    nacos安装+启动(linux环境): 基础:安装java环境 官网下载压缩包:如 nacos-server-1.2.1.tar.gz 放在自定义目录下 # 解压 tar -xvf nacos-se ...

  3. Alibaba Cloud Linux 2.1903 LTS 64位服务器yum源下载404,Alibaba Cloud Linux 2实例中使用docker-ce、epel等YUM源安装软件失败

    [Alibaba Cloud Linux 2.1903 LTS 64位]服务器yum源下载404 failure: repodata/repomd.xml from docker-ce-stable: ...

  4. Linux下创建硬链接,文件访问为空,提示:xxxx: 符号连接的层数过多

    Linux下创建软链接|硬链接,文件访问为空,提示:x x x: 符号连接的层数过多. 原因:创建符号链接的时候未使用绝对路径,无论是源文件路径还是目标路径,都需要使用绝对路径. 如: ln -s / ...

  5. 作为一个java程序员,常用的linux命令(越攒越多)

    本篇记录我在工作中不断遇到的常用的linux命令,并进行总结,时常更新! 1. 升级服务时先停止服务,然后进行替换 linux中杀进程时候,如果你是知道它所占用的端口号的话,可以通过 netstat ...

  6. 设置linux初始root密码

    简单一步设置linux第一个root密码 sudo passwd root #输入当前账户密码 #输入准备设置的root密码 #确认密码 如下所示:

  7. Linux/docker下oracle开启监听,开启自动启动

    写在前头: 之前呢,使用docker安装了oracle,但它默认是会关闭的.使用了几天以后突然连接异常了,报的问题是oracle监听有问题了,我知道了是oracle服务自动关闭了,监听也跟着关了.所以 ...

  8. Linux通过端口号杀死指定进程

    前言: 我们在服务器上升级项目的时候,需要将原来的项目停止,然后启动新的项目. 这时候我们只知道应用所占的端口号,如何将进程杀死呢? linux中杀进程时候,如果你是知道它所占用的端口号的话,可以通过 ...

  9. 设置腾讯云linux服务器中 MySQL 允许远程访问

    申请了一台linux腾讯云服务器,想要把数据库搭建在上面,本地的Windows直接可以访问 以下就是具体的操作流程,首先你需要安装好一个mysql,安装方法–>mysql安装(Linux) 接着 ...

最新文章

  1. oracle之 手动创建 emp 表 与 dept 表
  2. HDU 4946 Area of Mushroom 凸包
  3. 服了,为什么100M宽带还这么卡?
  4. 【公告】【公告】【公告】【公告】
  5. C#图形处理系列(一)——最简单第一步:逆反处理、二值处理
  6. QT的安装以及测试是否成功
  7. Qt QProcess执行Linux 命令行的方法
  8. 解决神经网络过拟合问题—Dropout方法、python实现
  9. gulp通过http-proxy-middleware开启反向代理,实现跨域
  10. pg日期转周_PostgreSQL的时间/日期函数使用
  11. activiti 设置候选人_中标 | 河南移动公示无源波分复用设备集采中标候选人名单:3家厂商上榜...
  12. HTML5期末大作业:英雄联盟网站设计——英雄联盟LOL(4页) HTML+CSS+JavaScript web期末网站设计大作业
  13. NLP--2 语言结构和传统pipeline
  14. redis数据类型总结
  15. VScode突然之间连接服务器显示不断重连retry多次
  16. 开源协同OA办公平台教程:O2OA服务管理中,接口的调用权限
  17. 淘宝商品详情查询V1新版接口
  18. SDN:简述对SDN北向接口协议的认识
  19. 物业管理软件的主要功能
  20. 美国人打电话时最常用的句子

热门文章

  1. 正则表达式匹配多个字符串中的一个
  2. javax.servlet.jsp.JspTagException:
  3. 转:Yupoo(又拍网)的系统架构
  4. Linux 脚本、 正则表达式 等
  5. 哔哩哔哩修改视频速度
  6. Vmware上安装RedHat Linux 7.3操作系统手册
  7. android9叫什么名字,白猜这么多名字!谷歌Android 9.0正式发布:命名Android Pie
  8. linux c++ 编译 库,LINUX C/C++ 编译库关系
  9. 【解决】如何打开.ipynb文件
  10. 关于Eclipes的Logcat无法打印消息的解决办法