日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux inputuevent使用

發布時間:2023/12/20 linux 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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);

總結

以上是生活随笔為你收集整理的linux inputuevent使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。