这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » STM32 » linux input&&uevent使用

共2条 1/1 1 跳转至

linux input&&uevent使用

高工
2019-02-24 13:19:19     打赏

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$ 

1

2

3

4

问题:最近我自己比较了这两个的作用,我们以前经常用这个来获取底层上报的值,用来做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

1

2

3

4

5

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

    }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Android接收 

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


//weiqifa modify for the hall uevent

    private UEventObserver mHALLObserver = new UEventObserver() {

        @Override

        public 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);//关闭闪光灯

            }           

        }

    };

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

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


//weiqifa modify add 

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

1

2

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


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


//weiqifa modify for hall

    hdyrodent_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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

底层例子


/*

 * 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 hall

    hdyrodent_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_interrupt

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





管理员
2019-02-25 09:40:17     打赏
2楼

谢谢楼主分享


共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]