linux inputuevent使用

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);

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/469263.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linq中给字段添加别名

linq 是我们在查询中经常回用到的一种形式,比如我们创建一个类,然后List<添加> 并绑定到表格中public class Modeltest{string id;public string Id{get { return id; }set { id value; }}string pwd;public string Pwd{get { return pwd; }set { pwd value; }}string…

报错 ValueError: too many values to unpack (expected 2)

enc_output,enc_slf_attn self.slf_attn(user_embedding,item_input,item_input,mask slf_attn_mask) 实际上只有一个返回值&#xff0c;但是却写了两个返回值&#xff0c;所以报错。 改正为 enc_output self.slf_attn(user_embedding,item_input,item_input,mask sl…

Python带*参数和带**参数

一、带*形参 1、格式&#xff1a;*形参名&#xff0c;如*args 2、数据类型&#xff1a;元组 3、传参方式&#xff1a;接收任意个位置参数&#xff08;可以不传参&#xff09;。 4、位置&#xff1a;在一个函数里只能有一个&#xff0c;且放在末尾&#xff08;没有带**形参的…

IE浏览器解决无法识别js中getElementsByClassName问题

关于ie浏览器无法识别js中getElementsByClassName问题&#xff0c;现通过以下方法&#xff0c;引用如下js /***打印js对象详细信息*/ function alertObj(obj) {var description "";for ( var i in obj){var property obj[i];description i " " prope…

arduino i2c 如何写16位寄存器_树莓派3B开发Go语言(二)寄存器版本GPIO

作者&#xff1a;爪爪熊链接&#xff1a;https://www.jianshu.com/p/0495c0554a63來源&#xff1a;简书之前将go语言的运行环境给搭建起来了&#xff0c;但是没有开始真正的试试Go 语言操作树莓派硬件的效果。一、树莓派3B硬件介绍树莓派3B采用了博通的BCM2837方案&#xff0c;…

Android aidl在Framework的使用

为何要做这个 我要在framework的PhoneWindowManager.java里面调用LightService.java里面的函数&#xff0c;用来做灯光的提示之类的&#xff0c;为何我要在PhoneWindowManager.java里面加这个呢&#xff0c;这里就不做讨论了&#xff0c;但是直接调用哪些接口是不行的&#xf…

没有理智的欲望会走向毁灭,没有欲望的理智会永守清贫

欲望是人类的本性,哥伦布因为它片帆浮海、横渡大洋发现了美州。理性是人类的禀赋,哥白尼因为它仰望星空、冥想终生提出了日心说。在金融市场上没有理智的欲望会走向毁灭,没有欲望的理智会永守清贫。转载于:https://www.cnblogs.com/timlong/p/6509870.html

【Pytorch神经网络实战案例】25 (带数据增强)基于迁移学习识别多种鸟类(CUB-200数据集)

1 数据增强 在目前分类效果最好的EficientNet系列模型中&#xff0c;EfficientNet-B7版本的模型就是使用随机数据增强方法训练而成的。 RandAugment方法也是目前主流的数据增强方法&#xff0c;用RandAugment方法进行训练&#xff0c;会使模型的精度得到提升。 2 RandAugment…

Capture images using V4L2 on Linux

这文章相当好&#xff0c;没有理由不转载 I have always been using OpenCV’s VideoCapture API to capture images from webcam or USB cameras. OpenCV supportsV4L2 and I wanted to use something other than OpenCV’s VideoCapture API so I started digging up about …

diskgenius 数据迁移_U盘格式化后数据恢复免费方法教程

U盘里的数据一般都很重要&#xff0c;比如论文或者办公文件&#xff0c;而有时候我们会被病毒或者误操作把U盘给格式化了&#xff0c;这时候要怎么恢复U盘里的数据呢&#xff0c;只有一个办法&#xff0c;就是用U盘数据恢复软件&#xff0c;但网上此类软件虽然很多&#xff0c;…

结对编程1

Deadline&#xff1a; 2017-3-15 12:00AM&#xff0c;以博客发表日期为准。 评分基准: 按时交 - 有分&#xff0c;检查的项目包括后文的三个方面 题目要求代码提交博文规范晚交 - 0分迟交两周以上 - 倒扣本次作业分数抄袭 - 倒扣本次作业分数题目描述&#xff1a; 不知道大家是…

【Pytorch神经网络理论篇】 34 样本均衡+分类模型常见损失函数

同学你好&#xff01;本文章于2021年末编写&#xff0c;获得广泛的好评&#xff01; 故在2022年末对本系列进行填充与更新&#xff0c;欢迎大家订阅最新的专栏&#xff0c;获取基于Pytorch1.10版本的理论代码(2023版)实现&#xff0c; Pytorch深度学习理论篇(2023版)目录地址…

我的2015年

2015年的收获 1、结婚了&#xff0c;这是很开心的一件事情&#xff0c;从刚开始的吵吵闹闹&#xff0c;到现在的结婚成家&#xff0c;自己的责任也增加了许多。 2、老婆怀了宝宝&#xff0c;这件事跟结婚的喜悦是一样的&#xff0c;从开始到现在&#xff0c;很多人都在问我&a…

安卓 camera 调用流程_安卓如何做出微信那样的界面仿微信“我”的界面1/5

本系列目标通过安卓编程仿写微信“我”的界面,让大家也能做出类似微信界面.效果图如下:本文目标做出页面顶部的相机部分(其他部分在后续文章中逐步分享).效果图如下:实现方案通过截图工具或者下载一张照相机照片,放到工程的src/main/res/drawable目录下,命名为camera.png添加一…

【Pytorch神经网络实战案例】26 MaskR-CNN内置模型实现目标检测

1 Pytorch中的目标检测内置模型 在torchvision库下的modelsldetecton目录中&#xff0c;找到__int__.py文件。该文件中存放着可以导出的PyTorch内置的目标检测模型。 2 MaskR-CNN内置模型实现目标检测 2.1 代码逻辑简述 将COCO2017数据集上的预训练模型maskrcnm_resnet50_fp…

MTK平台Android4.4 拍照默认图片格式修改

因为摄像头效果要调试&#xff0c;需要把摄像头拍照的照片格式修改了 晚上看了一下资料&#xff0c;这个链接&#xff0c;这个链接比较有用 http://www.cnblogs.com/peterzd/archive/2012/10/11/2695640.html 里面有一段话这样写&#xff1a; ** Environment.getExternalS…

法与时应,度与情合

不能制定脱离实际的法度&#xff0c;否则就是恶法&#xff0c;不可操作&#xff0c;事与愿违。转载于:https://www.cnblogs.com/jcode/p/6514698.html

【Pytorch神经网络实战案例】27 MaskR-CNN内置模型实现语义分割

1 PyTorch中语义分割的内置模型 在torchvision库下的models\segmentation目录中&#xff0c;找到segmentation.Py文件。该文件中存放着PyTorch内置的语义分割模型。 2 MaskR-CNN内置模型实现语义分割 2.1 代码逻辑简述 将COCO 2017数据集上的预训练模型dceplabv3_resnet101…

怎么查看电脑内存和配置_电脑内存不足处理方法,电脑卡死处理方法。

超过10万人正在关注赶快来关注吧&#xff0c;这里有你想找的热点资讯&#xff0c;这里有你想要的各种资料&#xff0c;还有海量的资源&#xff0c;还在等什么。快来关注&#xff0c;大佬带你开车。电脑系统经常奔溃&#xff0c;软件经常运行不了&#xff0c;开不了机&#xff0…

前端开源项目周报0307

由OpenDigg 出品的前端开源项目周报第十一期来啦。我们的前端开源周报集合了OpenDigg一周来新收录的优质的前端开源项目&#xff0c;方便前端开发人员便捷的找到自己需要的项目工具等。 react-trend 简单优雅的光线 react-progressive-web-app 优化ProgressiveWeb应用开发 pull…