如何理解Sensor架构 - 华清远见 - 图文 下载本文

* 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 maxRange;

/* smallest difference between two values reported by this sensor */ float resolution;

/* rough estimate of this sensor's power consumption in mA */ float power;

/* minimum delay allowed between events in microseconds. A value of zero * means that this sensor doesn't report events at a constant rate, but * rather only when a new data is available */ int32_t minDelay;

/* reserved fields, must be zero */ void* reserved[8];

};

2.6.4 struct sensors_event_t 定义 [cpp]

view plaincopytypedef 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; /**

* Union of the various types of sensor data * that can be returned. */

typedef struct sensors_event_t {

/* must be sizeof(struct sensors_event_t) */ int32_t version; /* sensor identifier */ int32_t sensor; /* sensor type */ int32_t type; /* reserved */ int32_t reserved0;

/* time is in nanosecond */ int64_t timestamp; union { float data[16];

/* acceleration values are in meter per second per second (m/s^2) */ sensors_vec_t acceleration;

/* magnetic vector values are in micro-Tesla (uT) */ sensors_vec_t magnetic;

/* orientation values are in degrees */ sensors_vec_t orientation;

/* gyroscope values are in rad/s */ sensors_vec_t gyro;

/* temperature is in degrees centigrade (Celsius) */ float temperature;

/* distance in centimeters */

float distance;

/* light in SI lux units */ float light;

/* pressure in hectopascal (hPa) */ float pressure;

/* relative humidity in percent */ float relative_humidity; };

uint32_t reserved1[4]; } sensors_event_t;

2.6.5 struct sensors_module_t 实现 [cpp]

view plaincopy#include #include \/*

* the AK8973 has a 8-bit ADC but the firmware seems to average 16 samples, * or at least makes its calibration on 12-bits values. This increases the * resolution by 4 bits. */

static const struct sensor_t sSensorList[] = { { \\1, SENSORS_HANDLE_BASE+ID_A,

SENSOR_TYPE_ACCELEROMETER, 4.0f*9.81f, (4.0f*9.81f)/256.0f, 0.2f, 0, { } },

{ \\

1, SENSORS_HANDLE_BASE+ID_M,

SENSOR_TYPE_MAGNETIC_FIELD, 2000.0f, 1.0f/16.0f, 6.8f, 0, { } }, { \\

1, SENSORS_HANDLE_BASE+ID_O,

SENSOR_TYPE_ORIENTATION, 360.0f, 1.0f, 7.0f, 0, { } }, { \\

1, SENSORS_HANDLE_BASE+ID_GY,

SENSOR_TYPE_GYROSCOPE, RANGE_GYRO, CONVERT_GYRO, 6.1f, 1190, { } }, { \\1, SENSORS_HANDLE_BASE+ID_P, SENSOR_TYPE_PROXIMITY,

PROXIMITY_THRESHOLD_CM, PROXIMITY_THRESHOLD_CM, 0.5f, 0, { } },

{ \\1, SENSORS_HANDLE_BASE+ID_L,

SENSOR_TYPE_LIGHT, 10240.0f, 1.0f, 0.5f, 0, { } }, };

static int open_sensors(const struct hw_module_t* module, const char* name,