blob: 2abca72e42f9ba7bff427050a93e3dd6a0cbf78b [file] [log] [blame]
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001/*
Mathias Agopiana4557722012-11-28 17:21:55 -08002 * Copyright (C) 2012 The Android Open Source Project
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_SENSORS_INTERFACE_H
18#define ANDROID_SENSORS_INTERFACE_H
19
20#include <stdint.h>
21#include <sys/cdefs.h>
22#include <sys/types.h>
23
24#include <hardware/hardware.h>
Mike Lockwood21b652f2009-05-22 10:05:48 -040025#include <cutils/native_handle.h>
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080026
27__BEGIN_DECLS
28
Mathias Agopian56f66cc2012-11-08 15:57:38 -080029/*****************************************************************************/
30
31#define SENSORS_HEADER_VERSION 1
32#define SENSORS_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
33#define SENSORS_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, SENSORS_HEADER_VERSION)
Mathias Agopiana4557722012-11-28 17:21:55 -080034#define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION)
Mathias Agopian16671c52013-07-24 21:07:40 -070035#define SENSORS_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, SENSORS_HEADER_VERSION)
Mathias Agopian56f66cc2012-11-08 15:57:38 -080036
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080037/**
Clay Murphy8db1fb42013-12-19 09:58:28 -080038 * Please see the Sensors section of source.android.com for an
39 * introduction to and detailed descriptions of Android sensor types:
40 * http://source.android.com/devices/sensors/index.html
41 */
42
43/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080044 * The id of this module
45 */
46#define SENSORS_HARDWARE_MODULE_ID "sensors"
47
48/**
49 * Name of the sensors device to open
50 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -070051#define SENSORS_HARDWARE_POLL "poll"
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080052
53/**
54 * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
55 * A Handle identifies a given sensors. The handle is used to activate
56 * and/or deactivate sensors.
57 * In this version of the API there can only be 256 handles.
58 */
59#define SENSORS_HANDLE_BASE 0
60#define SENSORS_HANDLE_BITS 8
61#define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS)
62
63
Mathias Agopiana4557722012-11-28 17:21:55 -080064/*
65 * flags for (*batch)()
66 * Availability: SENSORS_DEVICE_API_VERSION_1_0
67 * see (*batch)() documentation for details
68 */
69enum {
70 SENSORS_BATCH_DRY_RUN = 0x00000001,
71 SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
72};
73
Mathias Agopian16671c52013-07-24 21:07:40 -070074/*
75 * what field for meta_data_event_t
76 */
77enum {
78 /* a previous flush operation has completed */
Mathias Agopianaf32a8d2013-08-06 20:33:38 -070079 META_DATA_FLUSH_COMPLETE = 1,
80 META_DATA_VERSION /* always last, leave auto-assigned */
Mathias Agopian16671c52013-07-24 21:07:40 -070081};
82
Mathias Agopiana4557722012-11-28 17:21:55 -080083/*
84 * Sensor type
85 *
86 * Each sensor has a type which defines what this sensor measures and how
Clay Murphy8db1fb42013-12-19 09:58:28 -080087 * measures are reported. See the Base sensors and Composite sensors lists
88 * for complete descriptions:
89 * http://source.android.com/devices/sensors/base_triggers.html
90 * http://source.android.com/devices/sensors/composite_sensors.html
Mathias Agopian1599ec62013-08-19 14:34:47 -070091 *
92 * Device manufacturers (OEMs) can define their own sensor types, for
93 * their private use by applications or services provided by them. Such
94 * sensor types are specific to an OEM and can't be exposed in the SDK.
95 * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE.
Mathias Agopiana4557722012-11-28 17:21:55 -080096 */
97
98/*
Mathias Agopian1599ec62013-08-19 14:34:47 -070099 * Base for device manufacturers private sensor types.
100 * These sensor types can't be exposed in the SDK.
101 */
102#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000
103
104/*
Mathias Agopian16671c52013-07-24 21:07:40 -0700105 * SENSOR_TYPE_META_DATA
106 * trigger-mode: n/a
107 * wake-up sensor: n/a
108 *
109 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
110 *
111 * SENSOR_TYPE_META_DATA is a special token used to populate the
112 * sensors_meta_data_event structure. It doesn't correspond to a physical
113 * sensor. sensors_meta_data_event are special, they exist only inside
114 * the HAL and are generated spontaneously, as opposed to be related to
115 * a physical sensor.
116 *
Mathias Agopianaf32a8d2013-08-06 20:33:38 -0700117 * sensors_meta_data_event_t.version must be META_DATA_VERSION
118 * sensors_meta_data_event_t.sensor must be 0
119 * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
120 * sensors_meta_data_event_t.reserved must be 0
121 * sensors_meta_data_event_t.timestamp must be 0
Mathias Agopian16671c52013-07-24 21:07:40 -0700122 *
123 * The payload is a meta_data_event_t, where:
124 * meta_data_event_t.what can take the following values:
125 *
126 * META_DATA_FLUSH_COMPLETE
127 * This event indicates that a previous (*flush)() call has completed for the sensor
128 * handle specified in meta_data_event_t.sensor.
129 * see (*flush)() for more details
130 *
131 * All other values for meta_data_event_t.what are reserved and
132 * must not be used.
133 *
134 */
135#define SENSOR_TYPE_META_DATA (0)
136
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800137/*
138 * SENSOR_TYPE_ACCELEROMETER
Mathias Agopiana4557722012-11-28 17:21:55 -0800139 * trigger-mode: continuous
140 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800141 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800142 * All values are in SI units (m/s^2) and measure the acceleration of the
143 * device minus the force of gravity.
144 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800145 */
146#define SENSOR_TYPE_ACCELEROMETER (1)
147
148/*
149 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Mathias Agopiana4557722012-11-28 17:21:55 -0800150 * trigger-mode: continuous
151 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800152 *
153 * All values are in micro-Tesla (uT) and measure the geomagnetic
154 * field in the X, Y and Z axis.
155 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800156 */
157#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
158#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
159
160/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800161 * SENSOR_TYPE_ORIENTATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800162 * trigger-mode: continuous
163 * wake-up sensor: no
Clay Murphy8db1fb42013-12-19 09:58:28 -0800164 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800165 * All values are angles in degrees.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800166 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700167 * Orientation sensors return sensor events for all 3 axes at a constant
168 * rate defined by setDelay().
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800169 */
170#define SENSOR_TYPE_ORIENTATION (3)
171
172/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800173 * SENSOR_TYPE_GYROSCOPE
Mathias Agopiana4557722012-11-28 17:21:55 -0800174 * trigger-mode: continuous
175 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800176 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700177 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800178 * around the X, Y and Z axis.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800179 */
180#define SENSOR_TYPE_GYROSCOPE (4)
181
182/*
183 * SENSOR_TYPE_LIGHT
Mathias Agopiana4557722012-11-28 17:21:55 -0800184 * trigger-mode: on-change
185 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800186 *
187 * The light sensor value is returned in SI lux units.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800188 */
189#define SENSOR_TYPE_LIGHT (5)
190
191/*
192 * SENSOR_TYPE_PRESSURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800193 * trigger-mode: continuous
194 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800195 *
196 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800197 */
198#define SENSOR_TYPE_PRESSURE (6)
199
200/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
201#define SENSOR_TYPE_TEMPERATURE (7)
202
203/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800204 * SENSOR_TYPE_PROXIMITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800205 * trigger-mode: on-change
206 * wake-up sensor: yes
Mike Lockwooda2414312009-11-03 10:29:50 -0500207 *
Clay Murphy8db1fb42013-12-19 09:58:28 -0800208 * The value corresponds to the distance to the nearest object in centimeters.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800209 */
210#define SENSOR_TYPE_PROXIMITY (8)
211
212/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800213 * SENSOR_TYPE_GRAVITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800214 * trigger-mode: continuous
215 * wake-up sensor: no
Mathias Agopian42b743c2010-11-22 15:55:32 -0800216 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800217 * A gravity output indicates the direction of and magnitude of gravity in
Clay Murphy8db1fb42013-12-19 09:58:28 -0800218 * the devices's coordinates.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800219 */
220#define SENSOR_TYPE_GRAVITY (9)
221
222/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800223 * SENSOR_TYPE_LINEAR_ACCELERATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800224 * trigger-mode: continuous
225 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800226 *
227 * Indicates the linear acceleration of the device in device coordinates,
228 * not including gravity.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800229 */
230#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
231
232
233/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800234 * SENSOR_TYPE_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800235 * trigger-mode: continuous
236 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800237 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700238 * The rotation vector symbolizes the orientation of the device relative to the
Clay Murphy8db1fb42013-12-19 09:58:28 -0800239 * East-North-Up coordinates frame.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800240 */
241#define SENSOR_TYPE_ROTATION_VECTOR (11)
242
243/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800244 * SENSOR_TYPE_RELATIVE_HUMIDITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800245 * trigger-mode: on-change
246 * wake-up sensor: no
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100247 *
248 * A relative humidity sensor measures relative ambient air humidity and
249 * returns a value in percent.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800250 */
251#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
252
253/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800254 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800255 * trigger-mode: on-change
256 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700257 *
258 * The ambient (room) temperature in degree Celsius.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800259 */
260#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
261
262/*
263 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800264 * trigger-mode: continuous
265 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700266 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800267 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
268 * reported separately instead of being included in the measurement.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800269 */
270#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
271
272/*
273 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800274 * trigger-mode: continuous
275 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800276 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800277 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
Clay Murphy8db1fb42013-12-19 09:58:28 -0800278 * field.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800279 */
280#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
281
282/*
283 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800284 * trigger-mode: continuous
285 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800286 *
287 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800288 * around the X, Y and Z axis.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800289 */
290#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
291
Mathias Agopiana4557722012-11-28 17:21:55 -0800292/*
293 * SENSOR_TYPE_SIGNIFICANT_MOTION
294 * trigger-mode: one-shot
295 * wake-up sensor: yes
296 *
297 * A sensor of this type triggers an event each time significant motion
298 * is detected and automatically disables itself.
299 * The only allowed value to return is 1.0.
Mathias Agopiana4557722012-11-28 17:21:55 -0800300 */
301
302#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
303
304
305/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800306 * SENSOR_TYPE_STEP_DETECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800307 * trigger-mode: special
308 * wake-up sensor: no
309 *
310 * A sensor of this type triggers an event each time a step is taken
Clay Murphy8db1fb42013-12-19 09:58:28 -0800311 * by the user. The only allowed value to return is 1.0 and an event
312 * is generated for each step.
Mathias Agopiana4557722012-11-28 17:21:55 -0800313 */
314
Mathias Agopian2f276f52013-01-28 17:54:41 -0800315#define SENSOR_TYPE_STEP_DETECTOR (18)
Mathias Agopiana4557722012-11-28 17:21:55 -0800316
317
318/*
319 * SENSOR_TYPE_STEP_COUNTER
320 * trigger-mode: on-change
321 * wake-up sensor: no
322 *
323 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800324 * the last reboot while activated. The value is returned as a uint64_t and is
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700325 * reset to zero only on a system / android reboot.
Mathias Agopiana4557722012-11-28 17:21:55 -0800326 */
327
328#define SENSOR_TYPE_STEP_COUNTER (19)
329
Etienne Le Grandca858142013-02-26 19:17:20 -0800330/*
331 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
332 * trigger-mode: continuous
333 * wake-up sensor: no
334 *
335 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
336 * of using a gyroscope.
Etienne Le Grandca858142013-02-26 19:17:20 -0800337 */
338#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
Mathias Agopiana4557722012-11-28 17:21:55 -0800339
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800340/**
341 * Values returned by the accelerometer in various locations in the universe.
342 * all values are in SI units (m/s^2)
343 */
344#define GRAVITY_SUN (275.0f)
345#define GRAVITY_EARTH (9.80665f)
346
347/** Maximum magnetic field on Earth's surface */
348#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
349
350/** Minimum magnetic field on Earth's surface */
351#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
352
353
354/**
355 * status of orientation sensor
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800356 */
Kevin Powellb01a0432010-07-19 19:12:15 -0700357
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800358#define SENSOR_STATUS_UNRELIABLE 0
359#define SENSOR_STATUS_ACCURACY_LOW 1
360#define SENSOR_STATUS_ACCURACY_MEDIUM 2
361#define SENSOR_STATUS_ACCURACY_HIGH 3
362
363
364/**
365 * sensor event data
366 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800367typedef struct {
368 union {
369 float v[3];
370 struct {
371 float x;
372 float y;
373 float z;
374 };
375 struct {
376 float azimuth;
377 float pitch;
378 float roll;
379 };
380 };
381 int8_t status;
382 uint8_t reserved[3];
383} sensors_vec_t;
384
385/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800386 * uncalibrated gyroscope and magnetometer event data
387 */
388typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700389 union {
390 float uncalib[3];
391 struct {
392 float x_uncalib;
393 float y_uncalib;
394 float z_uncalib;
395 };
396 };
397 union {
398 float bias[3];
399 struct {
400 float x_bias;
401 float y_bias;
402 float z_bias;
403 };
404 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800405} uncalibrated_event_t;
406
Mathias Agopian16671c52013-07-24 21:07:40 -0700407typedef struct meta_data_event {
408 int32_t what;
409 int32_t sensor;
410} meta_data_event_t;
411
Etienne Le Grandca858142013-02-26 19:17:20 -0800412/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800413 * Union of the various types of sensor data
414 * that can be returned.
415 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700416typedef struct sensors_event_t {
417 /* must be sizeof(struct sensors_event_t) */
418 int32_t version;
419
420 /* sensor identifier */
421 int32_t sensor;
422
423 /* sensor type */
424 int32_t type;
425
426 /* reserved */
427 int32_t reserved0;
428
429 /* time is in nanosecond */
430 int64_t timestamp;
431
432 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700433 union {
434 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700435
Mathias Agopian27e16682013-07-08 14:00:54 -0700436 /* acceleration values are in meter per second per second (m/s^2) */
437 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700438
Mathias Agopian27e16682013-07-08 14:00:54 -0700439 /* magnetic vector values are in micro-Tesla (uT) */
440 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700441
Mathias Agopian27e16682013-07-08 14:00:54 -0700442 /* orientation values are in degrees */
443 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700444
Mathias Agopian27e16682013-07-08 14:00:54 -0700445 /* gyroscope values are in rad/s */
446 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700447
Mathias Agopian27e16682013-07-08 14:00:54 -0700448 /* temperature is in degrees centigrade (Celsius) */
449 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700450
Mathias Agopian27e16682013-07-08 14:00:54 -0700451 /* distance in centimeters */
452 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700453
Mathias Agopian27e16682013-07-08 14:00:54 -0700454 /* light in SI lux units */
455 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700456
Mathias Agopian27e16682013-07-08 14:00:54 -0700457 /* pressure in hectopascal (hPa) */
458 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100459
Mathias Agopian27e16682013-07-08 14:00:54 -0700460 /* relative humidity in percent */
461 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800462
Mathias Agopian27e16682013-07-08 14:00:54 -0700463 /* uncalibrated gyroscope values are in rad/s */
464 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800465
Mathias Agopian27e16682013-07-08 14:00:54 -0700466 /* uncalibrated magnetometer values are in micro-Teslas */
467 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700468
469 /* this is a special event. see SENSOR_TYPE_META_DATA above.
470 * sensors_meta_data_event_t events are all reported with a type of
471 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
472 */
473 meta_data_event_t meta_data;
Mathias Agopian27e16682013-07-08 14:00:54 -0700474 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800475
Mathias Agopian27e16682013-07-08 14:00:54 -0700476 union {
477 uint64_t data[8];
478
479 /* step-counter */
480 uint64_t step_counter;
481 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700482 };
Mathias Agopian27e16682013-07-08 14:00:54 -0700483 uint32_t reserved1[4];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700484} sensors_event_t;
485
486
Mathias Agopian16671c52013-07-24 21:07:40 -0700487/* see SENSOR_TYPE_META_DATA */
488typedef sensors_event_t sensors_meta_data_event_t;
489
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700490
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800491struct sensor_t;
492
493/**
494 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
495 * and the fields of this data structure must begin with hw_module_t
496 * followed by module specific information.
497 */
498struct sensors_module_t {
499 struct hw_module_t common;
500
501 /**
502 * Enumerate all available sensors. The list is returned in "list".
503 * @return number of sensors in the list
504 */
505 int (*get_sensors_list)(struct sensors_module_t* module,
506 struct sensor_t const** list);
507};
508
509struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800510
511 /* Name of this sensor.
512 * All sensors of the same "type" must have a different "name".
513 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800514 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800515
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800516 /* vendor of the hardware part */
517 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800518
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800519 /* version of the hardware part + driver. The value of this field
520 * must increase when the driver is updated in a way that changes the
521 * output of this sensor. This is important for fused sensors when the
522 * fusion algorithm is updated.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800523 */
524 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800525
526 /* handle that identifies this sensors. This handle is used to reference
527 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800528 */
529 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800530
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800531 /* this sensor's type. */
532 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800533
534 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800535 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800536
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800537 /* smallest difference between two values reported by this sensor */
538 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800539
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800540 /* rough estimate of this sensor's power consumption in mA */
541 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800542
543 /* this value depends on the trigger mode:
544 *
545 * continuous: minimum sample period allowed in microseconds
546 * on-change : 0
547 * one-shot :-1
548 * special : 0, unless otherwise noted
549 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700550 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800551
Mathias Agopian16671c52013-07-24 21:07:40 -0700552 /* number of events reserved for this sensor in the batch mode FIFO.
553 * If there is a dedicated FIFO for this sensor, then this is the
554 * size of this FIFO. If the FIFO is shared with other sensors,
555 * this is the size reserved for that sensor and it can be zero.
556 */
557 uint32_t fifoReservedEventCount;
558
559 /* maximum number of events of this sensor that could be batched.
560 * This is especially relevant when the FIFO is shared between
561 * several sensors; this value is then set to the size of that FIFO.
562 */
563 uint32_t fifoMaxEventCount;
564
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800565 /* reserved fields, must be zero */
Mathias Agopian16671c52013-07-24 21:07:40 -0700566 void* reserved[6];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800567};
568
569
Mathias Agopiana4557722012-11-28 17:21:55 -0800570/*
571 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
572 * and is present for backward binary and source compatibility.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800573 * See the Sensors HAL interface section for complete descriptions of the
574 * following functions:
575 * http://source.android.com/devices/sensors/index.html#hal
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800576 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700577struct sensors_poll_device_t {
578 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700579 int (*activate)(struct sensors_poll_device_t *dev,
580 int handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700581 int (*setDelay)(struct sensors_poll_device_t *dev,
582 int handle, int64_t ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700583 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700584 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700585};
586
Mathias Agopiana4557722012-11-28 17:21:55 -0800587/*
588 * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
589 */
590typedef struct sensors_poll_device_1 {
591 union {
592 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
593 * and can be down-cast to it
594 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800595 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -0800596
597 struct {
598 struct hw_device_t common;
599
Clay Murphy8db1fb42013-12-19 09:58:28 -0800600 /* Activate/de-activate one sensor. Return 0 on success, negative
Mathias Agopiana4557722012-11-28 17:21:55 -0800601 *
602 * handle is the handle of the sensor to change.
603 * enabled set to 1 to enable, or 0 to disable the sensor.
604 *
Clay Murphy8db1fb42013-12-19 09:58:28 -0800605 * Return 0 on success, negative errno code otherwise.
Mathias Agopiana4557722012-11-28 17:21:55 -0800606 */
607 int (*activate)(struct sensors_poll_device_t *dev,
608 int handle, int enabled);
609
610 /**
Mathias Agopian1144bea2013-01-29 15:52:10 -0800611 * Set the events's period in nanoseconds for a given sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800612 */
613 int (*setDelay)(struct sensors_poll_device_t *dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -0800614 int handle, int64_t period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -0800615
616 /**
617 * Returns an array of sensor data.
Mathias Agopiana4557722012-11-28 17:21:55 -0800618 */
619 int (*poll)(struct sensors_poll_device_t *dev,
620 sensors_event_t* data, int count);
621 };
622 };
623
Mathias Agopiana4557722012-11-28 17:21:55 -0800624
625 /*
Clay Murphy8db1fb42013-12-19 09:58:28 -0800626 * Enables batch mode for the given sensor and sets the delay between events.
627 * See the Batching sensor results page for details:
628 * http://source.android.com/devices/sensors/batching.html
Mathias Agopiana4557722012-11-28 17:21:55 -0800629 */
630 int (*batch)(struct sensors_poll_device_1* dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -0800631 int handle, int flags, int64_t period_ns, int64_t timeout);
Mathias Agopiana4557722012-11-28 17:21:55 -0800632
Mathias Agopian16671c52013-07-24 21:07:40 -0700633 /*
634 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
635 * to the end of the "batch mode" FIFO for the specified sensor and flushes
Clay Murphy8db1fb42013-12-19 09:58:28 -0800636 * the FIFO.
Mathias Agopian16671c52013-07-24 21:07:40 -0700637 */
638 int (*flush)(struct sensors_poll_device_1* dev, int handle);
639
Mathias Agopiana4557722012-11-28 17:21:55 -0800640 void (*reserved_procs[8])(void);
641
642} sensors_poll_device_1_t;
643
644
645
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800646/** convenience API for opening and closing a device */
647
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700648static inline int sensors_open(const struct hw_module_t* module,
649 struct sensors_poll_device_t** device) {
650 return module->methods->open(module,
651 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
652}
653
654static inline int sensors_close(struct sensors_poll_device_t* device) {
655 return device->common.close(&device->common);
656}
657
Mathias Agopiana4557722012-11-28 17:21:55 -0800658static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800659 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -0800660 return module->methods->open(module,
661 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
662}
663
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800664static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -0800665 return device->common.close(&device->common);
666}
667
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800668__END_DECLS
669
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800670#endif // ANDROID_SENSORS_INTERFACE_H