1、Android sensor架构
Android4.0系统内置对传感器的支持达13种,它们分别是:加速度传感器gsensor(accelerometer)、磁力传感器(magnetic field)、方向传感器(orientation)、陀螺仪(gyroscope)、环境光照传感器(light)、压力传感器(pressure)、温度传感器(temperature)和距离传感器(proximity)等。
Android实现传感器系统包括以下几个部分:

各部分之间架构图如下:
2、Sensor HAL层接口
Google为Sensor提供了统一的HAL接口,不同的硬件厂商需要根据该接口来实现并完成具体的硬件抽象层,Android中Sensor的HAL接口定义在:hardware/libhardware/include/hardware/sensors.h
对传感器类型的定义:

传感器模块的定义结构体如下:

该接口的定义实际上是对标准的硬件模块hw_module_t的一个扩展,增加了一个get_sensors_list函数,用于获取传感器的列表。
对任意一个sensor设备 都会有一个 sensor_t 结构体,其定义如下:
struct sensor_t {
/* name of this sensors */
const char* name;
/* vendor of the hardware part */
const char* vendor;
/* version of the hardware part + driver. The value of this field
* must increase when the driver is updated in a way that changes the
* output of this sensor. This is important for fused sensors when the
* fusion algorithm is updated.
*/
int version;
/* handle that identifies this sensors. This handle is used to activate
* and deactivate this sensor. The value of the handle must be 8 bits
* in this version of the API.
*/
int handle;
/* this sensor's type. */
int type;
/* maximaum range of this sensor's value in SI units */
float &

本文介绍了Android传感器系统架构,包括13种内置传感器类型。重点解析了Sensor HAL层接口,如sensor_t和sensors_event_t结构体,以及如何通过激活、延迟设置和数据获取等操作进行传感器控制。此外,还以LM75温度传感器为例展示了Sensor HAL的实现过程。
最低0.47元/天 解锁文章
6434

被折叠的 条评论
为什么被折叠?



