传感器模块接口的定义hardware/libhardware/include/hardware/sensors.h中。模块ID为“sensors”。
类型定义
- Sensors Overview
- Position Sensors
- Android操作系统11传感器介绍
- 旋转矩阵
- 传感器类型SENSOR_TYPE_*
- 传感器矢量数据sensors_vec_t
1 |
META_DATA |
属性 |
|
2 |
GEOMAGNETIC_FIELD |
地磁 |
SENSOR_TYPE_MAGNETIC_FIELD |
3 |
ORIENTATION |
姿态 |
方向,仰角,旋转 |
4 |
GYROSCOPE |
陀螺仪 |
角速度 |
5 |
LIGHT |
光线 |
|
6 |
PRESSURE |
压力 |
|
7 |
TEMPERATURE |
温度 |
|
8 |
PROXIMITY |
接近度 |
距离 |
9 |
GRAVITY |
重力 |
|
10 |
LINEAR_ACCELERATION |
加速度 |
|
11 |
ROTATION_VECTOR |
旋转矩阵 |
|
12 |
RELATIVE_HUMIDITY |
||
13 |
AMBIENT_TEMPERATURE |
||
14 |
MAGNETIC_FIELD_UNCALIBRATED |
||
15 |
GAME_ROTATION_VECTOR |
游戏旋转矩阵 |
与旋转矩阵相比,没有地磁信息,但是更精确 |
16 |
GYROSCOPE_UNCALIBRATED |
未矫正陀螺仪 |
|
17 |
SIGNIFICANT_MOTION |
||
18 |
STEP_DETECTOR |
||
19 |
STEP_COUNTER |
||
20 |
GEOMAGNETIC_ROTATION_VECTOR |
地磁旋转矩阵 |
使用磁力仪代替陀螺仪,精度降低,但是省电 |
typedef struct { union { float v[3]; struct { float x; float y; float z; }; struct { float azimuth; float pitch; float roll; }; }; int8_t status; uint8_t reserved[3]; } sensors_vec_t; |
- 传感器事件sensors_event_t
typedef struct sensors_event_t { int32_t version; int32_t sensor; int32_t type; int32_t reserved0; int64_t timestamp; union { union { float data[16]; sensors_vec_t acceleration; sensors_vec_t magnetic; sensors_vec_t orientation; sensors_vec_t gyro; float temperature; float distance; float light; float pressure; float relative_humidity; uncalibrated_event_t uncalibrated_gyro; uncalibrated_event_t uncalibrated_magnetic; meta_data_event_t meta_data; }; union { uint64_t data[8]; uint64_t step_counter; } u64; }; uint32_t reserved1[4]; } sensors_event_t; |
- 传感器实例sensor_t
struct sensor_t { const char* name; const char* vendor; int version; int handle; int type; float maxRange; float resolution; float power; int32_t minDelay; uint32_t fifoReservedEventCount; uint32_t fifoMaxEventCount; void* reserved[6]; }; |
接口定义
- 传感器模块sensors_module_t
struct sensors_module_t { struct hw_module_t common; int (*get_sensors_list)(struct sensors_module_t* module, struct sensor_t const** list); }; |
- 传感器管理设备sensors_poll_device_t(0.1版本)
- 传感器管理设备sensors_poll_device_1_t(1.0版本)
activate |
int(*) |
打开、关闭传感器,一次性传感器打开有事件后会自动关闭,也可以手动关闭。 |
setDelay |
int(*) |
设置传感器事件周期,不应在批处理模式调用。连续性传感器:采样率,响应变化传感器:限制事件频率,一次性传感器:没有实际作用。 |
poll |
int(*) |
等待事件,返回实际读取的事件数,必须等待,不允许返回0 |
batch |
int(*) |
设置批处理模式,收集事件批量返回,设置超时时间非0,启动模式。1.0 |
flush |
int(*) |
为指定传感器增加FLUSH完成事件,使poll立即超时,且缓存事件一起返回。1.0 |