2022-3-4 14:27:59
< >
其实人体感应模块驱动比较简单,就是一个GPIO口的检测,这里主要是想提供一个接口,给上层去比较容易的控制,一般我们可以写成JNI封装,我嫌太麻烦了,直接使用共享文件的方式,往/data/data/com.frame.cloud/mode.txt"下面写一个值,代表人体感应打开,另外一个值代表人体感应的关闭,内核和应用分别去监听文件的变化即可,比较简单,以下是驱动参考:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static struct class *body_detect_class = NULL;
static struct input_dev *sinput_dev;
static struct timer_list gpio_timer;
static unsigned int time_delay = HZ * 1;
extern int lcd_enable ;
static unsigned int gpio_state = 0;
static int gpio3_d3;
static int body_detect_switch = 0;
static int irq_gpio3_d3;
#define BODY_DETECT_OPEN 300
#define BODY_DETECT_CLOSE 200
#define EYEMODE_FILENAME "/data/data/com.frame.cloud/mode.txt"
struct delayed_work read_body_switch_work;
static struct of_device_id gpio_of_match[] = {
{ .compatible = "body_det" },
{ }
};
MODULE_DEVICE_TABLE(of, gpio_of_match);
static int get_body_det_value(void)
{
struct file *fp;
mm_segment_t fs;
loff_t pos;
char buf[5];
int buf_len = 0;
fp =filp_open(EYEMODE_FILENAME,O_RDONLY,0);
if (IS_ERR(fp)){
printk("open file errorn");
return -1;
}
fs =get_fs();
set_fs(KERNEL_DS);
pos =0;
buf_len = vfs_read(fp,buf, sizeof(buf), &pos);
buf[buf_len] = '