Android Sensor 适配层的书写--主要是对函数的介绍
Android Sensor 适配层的书写--主要是对函数的介绍
Sensor 适配层的书写-----大家多讨论,前文说了,适配层的基本的接口。现在将接口中的内容扩展说下,其实在sensors.h文件中已经说的很明确了,这里只不过是怕自己有遗忘翻译了一下。
这些函数的调用顺序是如何的呢?这就要看上层JAVA的调用了,反正JNI也指示函数的重定义。(当然这也只是我自己的理解) 其实到了这里大家也都清楚这些函数的作用,整个hal层的代码也只是这些函数的实现。其中这里hal和java的通信的话不得不考虑其中有一个native_handle这样的机制,下面再看看这个再说。
- /**
- * Every device data structure must begin with hw_device_t
- * followed by module specific public methods and attributes.
- */
- struct sensors_control_device_t {
- struct hw_device_t common;
- /**
- *返回一个native_handle_t的指针
- *
- * The caller takes ownership of this handle. This is intended to be
- * passed cross processes.
- *
- *成功返回native_handle_t,失败返回NULL
- */
- native_handle_t* (*open_data_source)(struct sensors_control_device_t *dev);
- /**
- * 释放所有在open_data_source中申请的资源
- * 这个调用的函数是可选的,可以设置为NULL
- * 成功返回0,失败小于0
- *
- * @return 0 if successful, < 0 on error
- */
- int (*close_data_source)(struct sensors_control_device_t *dev);
- /** 使一个sensor有效或者无效
- *
- * 参数:
- * handle: 需要变化的sensor的handle
- * enable: 1,使能;0,无效
- * 返回值:
- * 成功为0,失败为1
- */
- int (*activate)(struct sensors_control_device_t *dev,
- int handle, int enabled);
- /**
- * 设置sensor event的间隔时间,单位ms
- *
- * 成功为0,失败小于0
- */
- int (*set_delay)(struct sensors_control_device_t *dev, int32_t ms);
- /**
- * 促使sensors_data_device_t.poll()立即返回-EWOULDBLOCK
- */
- int (*wake)(struct sensors_control_device_t *dev);
- };
- struct sensors_data_device_t {
- struct hw_device_t common;
- /**
- * 准备读取sensor的数据
- *
- * This routine does NOT take ownership of the handle
- * and must not close it. Typically this routine would
- * use a duplicate of the nh parameter.
- *这个函数不能改变handle的权限,也不能关闭他。标准的做法,只是简单的将nh复制给dev使用;
- * 参数nh:来自于sensors_control_open
- * 返回值:0表示成功,小于0表示失败;
- */
- int (*data_open)(struct sensors_data_device_t *dev, native_handle_t* nh);
- /**
- *
- * 调用者必须完成了sensor的数据读取才可以调用此函数。因此可以知道,此函数��将设备节点给关闭掉;
- * 调用此函数不会阻塞poll函数。
- * 成功返回0,失败小于0
- * /
- int (*data_close)(struct sensors_data_device_t *dev);
- /**
- *
- * sensors_data_t指针返回指定的sensor的数据
- * 返回值:sensor的handle
- * poll的实现这里也说的很清楚,是返回指定的sensor的数据,也就是说这个poll不能一次把所有的sensor的数据都拿到
- */
- int (*poll)(struct sensors_data_device_t *dev,
- sensors_data_t* data);
- };
评论暂时关闭