blob: ef86a40b6cbf3b7acf7764995352f42601ba7b04 [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)
Aravind Akellab20f1a32014-04-07 22:46:01 +000036#define SENSORS_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION_2(1, 2, SENSORS_HEADER_VERSION)
Mathias Agopian56f66cc2012-11-08 15:57:38 -080037
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080038/**
39 * The id of this module
40 */
41#define SENSORS_HARDWARE_MODULE_ID "sensors"
42
43/**
44 * Name of the sensors device to open
45 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -070046#define SENSORS_HARDWARE_POLL "poll"
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080047
48/**
49 * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
50 * A Handle identifies a given sensors. The handle is used to activate
51 * and/or deactivate sensors.
52 * In this version of the API there can only be 256 handles.
53 */
54#define SENSORS_HANDLE_BASE 0
55#define SENSORS_HANDLE_BITS 8
56#define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS)
57
58
Mathias Agopiana4557722012-11-28 17:21:55 -080059/*
60 * flags for (*batch)()
61 * Availability: SENSORS_DEVICE_API_VERSION_1_0
62 * see (*batch)() documentation for details
63 */
64enum {
65 SENSORS_BATCH_DRY_RUN = 0x00000001,
66 SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
67};
68
Mathias Agopian16671c52013-07-24 21:07:40 -070069/*
70 * what field for meta_data_event_t
71 */
72enum {
73 /* a previous flush operation has completed */
Mathias Agopianaf32a8d2013-08-06 20:33:38 -070074 META_DATA_FLUSH_COMPLETE = 1,
75 META_DATA_VERSION /* always last, leave auto-assigned */
Mathias Agopian16671c52013-07-24 21:07:40 -070076};
77
Aravind Akellab20f1a32014-04-07 22:46:01 +000078/*
79 * The permission to use for body sensors (like heart rate monitors).
80 * See sensor types for more details on what sensors should require this
81 * permission.
82 */
83#define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS"
84
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080085/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -080086 * Definition of the axis used by the sensor HAL API
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080087 *
88 * This API is relative to the screen of the device in its default orientation,
89 * that is, if the device can be used in portrait or landscape, this API
90 * is only relative to the NATURAL orientation of the screen. In other words,
91 * the axis are not swapped when the device's screen orientation changes.
92 * Higher level services /may/ perform this transformation.
93 *
94 * x<0 x>0
95 * ^
96 * |
97 * +-----------+--> y>0
98 * | |
99 * | |
100 * | |
101 * | | / z<0
102 * | | /
103 * | | /
104 * O-----------+/
105 * |[] [ ] []/
106 * +----------/+ y<0
107 * /
108 * /
109 * |/ z>0 (toward the sky)
110 *
111 * O: Origin (x=0,y=0,z=0)
112 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800113 */
114
Mathias Agopiana4557722012-11-28 17:21:55 -0800115/*
116 * Interaction with suspend mode
117 *
118 * Unless otherwise noted, an enabled sensor shall not prevent the
119 * SoC to go into suspend mode. It is the responsibility of applications
120 * to keep a partial wake-lock should they wish to receive sensor
121 * events while the screen is off. While in suspend mode, and unless
Etienne Le Grand28f04112013-03-27 18:59:10 -0700122 * otherwise noted (batch mode, sensor particularities, ...), enabled sensors'
123 * events are lost.
Mathias Agopiana4557722012-11-28 17:21:55 -0800124 *
125 * Note that conceptually, the sensor itself is not de-activated while in
126 * suspend mode -- it's just that the data it returns are lost. As soon as
127 * the SoC gets out of suspend mode, operations resume as usual. Of course,
128 * in practice sensors shall be disabled while in suspend mode to
129 * save power, unless batch mode is active, in which case they must
130 * continue fill their internal FIFO (see the documentation of batch() to
131 * learn how suspend interacts with batch mode).
132 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700133 * In batch mode, and only when the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is
Mathias Agopian1144bea2013-01-29 15:52:10 -0800134 * set and supported, the specified sensor must be able to wake-up the SoC and
135 * be able to buffer at least 10 seconds worth of the requested sensor events.
Mathias Agopiana4557722012-11-28 17:21:55 -0800136 *
137 * There are notable exceptions to this behavior, which are sensor-dependent
138 * (see sensor types definitions below)
139 *
140 *
141 * The sensor type documentation below specifies the wake-up behavior of
142 * each sensor:
143 * wake-up: yes this sensor must wake-up the SoC to deliver events
144 * wake-up: no this sensor shall not wake-up the SoC, events are dropped
145 *
146 */
147
148/*
149 * Sensor type
150 *
151 * Each sensor has a type which defines what this sensor measures and how
152 * measures are reported. All types are defined below.
Mathias Agopian1599ec62013-08-19 14:34:47 -0700153 *
154 * Device manufacturers (OEMs) can define their own sensor types, for
155 * their private use by applications or services provided by them. Such
156 * sensor types are specific to an OEM and can't be exposed in the SDK.
157 * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE.
Aravind Akellab20f1a32014-04-07 22:46:01 +0000158 *
159 * All sensors defined outside of the device private range must correspond to
160 * a type defined in this file, and must satisfy the characteristics listed in
161 * the description of the sensor type.
162 *
163 * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also
164 * has a stringType.
165 * - StringType of sensors inside of the device private range MUST be prefixed
166 * by the sensor provider's or OEM reverse domain name. In particular, they
167 * cannot use the "android.sensor" prefix.
168 * - StringType of sensors outside of the device private range MUST correspond
169 * to the one defined in this file (starting with "android.sensor").
170 * For example, accelerometers must have
171 * type=SENSOR_TYPE_ACCELEROMETER and
172 * stringType=SENSOR_STRING_TYPE_ACCELEROMETER
173 *
174 * When android introduces a new sensor type that can replace an OEM-defined
175 * sensor type, the OEM must use the official sensor type and stringType on
176 * versions of the HAL that support this new official sensor type.
177 *
178 * Example (made up): Suppose Google's Glass team wants to surface a sensor
179 * detecting that Glass is on a head.
180 * - Such a sensor is not officially supported in android KitKat
181 * - Glass devices launching on KitKat can implement a sensor with
182 * type = 0x10001 and stringType = "com.google.glass.onheaddetector"
183 * - In L android release, if android decides to define
184 * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR,
185 * those types should replace the Glass-team-specific types in all future
186 * launches.
187 * - When launching glass on the L release, Google should now use the official
188 * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType.
189 * - This way, all applications can now use this sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800190 */
191
192/*
Mathias Agopian1599ec62013-08-19 14:34:47 -0700193 * Base for device manufacturers private sensor types.
194 * These sensor types can't be exposed in the SDK.
195 */
196#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000
197
198/*
Mathias Agopiana4557722012-11-28 17:21:55 -0800199 * Sensor fusion and virtual sensors
200 *
201 * Many sensor types are or can be implemented as virtual sensors from
202 * physical sensors on the device. For instance the rotation vector sensor,
Mathias Agopian2f276f52013-01-28 17:54:41 -0800203 * orientation sensor, step-detector, step-counter, etc...
Mathias Agopiana4557722012-11-28 17:21:55 -0800204 *
205 * From the point of view of this API these virtual sensors MUST appear as
206 * real, individual sensors. It is the responsibility of the driver and HAL
207 * to make sure this is the case.
208 *
209 * In particular, all sensors must be able to function concurrently.
210 * For example, if defining both an accelerometer and a step counter,
211 * then both must be able to work concurrently.
212 */
213
214/*
215 * Trigger modes
216 *
217 * Sensors can report events in different ways called trigger modes,
218 * each sensor type has one and only one trigger mode associated to it.
219 * Currently there are four trigger modes defined:
220 *
221 * continuous: events are reported at a constant rate defined by setDelay().
222 * eg: accelerometers, gyroscopes.
223 * on-change: events are reported only if the sensor's value has changed.
224 * setDelay() is used to set a lower limit to the reporting
225 * period (minimum time between two events).
226 * The HAL must return an event immediately when an on-change
227 * sensor is activated.
228 * eg: proximity, light sensors
Etienne Le Grandca858142013-02-26 19:17:20 -0800229 * one-shot: upon detection of an event, the sensor deactivates itself and
230 * then sends a single event. Order matters to avoid race
231 * conditions. No other event is sent until the sensor get
232 * reactivated. setDelay() is ignored.
Mathias Agopiana4557722012-11-28 17:21:55 -0800233 * eg: significant motion sensor
234 * special: see details in the sensor type specification below
235 *
236 */
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800237
Mathias Agopian16671c52013-07-24 21:07:40 -0700238
239/*
240 * SENSOR_TYPE_META_DATA
241 * trigger-mode: n/a
242 * wake-up sensor: n/a
243 *
244 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
245 *
246 * SENSOR_TYPE_META_DATA is a special token used to populate the
247 * sensors_meta_data_event structure. It doesn't correspond to a physical
248 * sensor. sensors_meta_data_event are special, they exist only inside
249 * the HAL and are generated spontaneously, as opposed to be related to
250 * a physical sensor.
251 *
Mathias Agopianaf32a8d2013-08-06 20:33:38 -0700252 * sensors_meta_data_event_t.version must be META_DATA_VERSION
253 * sensors_meta_data_event_t.sensor must be 0
254 * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
255 * sensors_meta_data_event_t.reserved must be 0
256 * sensors_meta_data_event_t.timestamp must be 0
Mathias Agopian16671c52013-07-24 21:07:40 -0700257 *
258 * The payload is a meta_data_event_t, where:
259 * meta_data_event_t.what can take the following values:
260 *
261 * META_DATA_FLUSH_COMPLETE
262 * This event indicates that a previous (*flush)() call has completed for the sensor
263 * handle specified in meta_data_event_t.sensor.
264 * see (*flush)() for more details
265 *
266 * All other values for meta_data_event_t.what are reserved and
267 * must not be used.
268 *
269 */
Aravind Akellab20f1a32014-04-07 22:46:01 +0000270#define SENSOR_TYPE_META_DATA (0)
Mathias Agopian16671c52013-07-24 21:07:40 -0700271
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800272/*
273 * SENSOR_TYPE_ACCELEROMETER
Mathias Agopiana4557722012-11-28 17:21:55 -0800274 * trigger-mode: continuous
275 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800276 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800277 * All values are in SI units (m/s^2) and measure the acceleration of the
278 * device minus the force of gravity.
279 *
280 * Acceleration sensors return sensor events for all 3 axes at a constant
281 * rate defined by setDelay().
282 *
283 * x: Acceleration on the x-axis
284 * y: Acceleration on the y-axis
285 * z: Acceleration on the z-axis
286 *
287 * Note that the readings from the accelerometer include the acceleration
288 * due to gravity (which is opposite to the direction of the gravity vector).
289 *
290 * Examples:
291 * The norm of <x, y, z> should be close to 0 when in free fall.
292 *
293 * When the device lies flat on a table and is pushed on its left side
294 * toward the right, the x acceleration value is positive.
295 *
296 * When the device lies flat on a table, the acceleration value is +9.81,
297 * which correspond to the acceleration of the device (0 m/s^2) minus the
298 * force of gravity (-9.81 m/s^2).
299 *
300 * When the device lies flat on a table and is pushed toward the sky, the
301 * acceleration value is greater than +9.81, which correspond to the
302 * acceleration of the device (+A m/s^2) minus the force of
303 * gravity (-9.81 m/s^2).
304 */
305#define SENSOR_TYPE_ACCELEROMETER (1)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000306#define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800307
308/*
309 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Mathias Agopiana4557722012-11-28 17:21:55 -0800310 * trigger-mode: continuous
311 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800312 *
313 * All values are in micro-Tesla (uT) and measure the geomagnetic
314 * field in the X, Y and Z axis.
315 *
316 * Returned values include calibration mechanisms such that the vector is
317 * aligned with the magnetic declination and heading of the earth's
318 * geomagnetic field.
319 *
320 * Magnetic Field sensors return sensor events for all 3 axes at a constant
321 * rate defined by setDelay().
322 */
323#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
324#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akellab20f1a32014-04-07 22:46:01 +0000325#define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800326
327/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800328 * SENSOR_TYPE_ORIENTATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800329 * trigger-mode: continuous
330 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800331 *
332 * All values are angles in degrees.
333 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700334 * Orientation sensors return sensor events for all 3 axes at a constant
335 * rate defined by setDelay().
336 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800337 * azimuth: angle between the magnetic north direction and the Y axis, around
338 * the Z axis (0<=azimuth<360).
339 * 0=North, 90=East, 180=South, 270=West
340 *
341 * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when
342 * the z-axis moves toward the y-axis.
343 *
344 * roll: Rotation around Y axis (-90<=roll<=90), with positive values when
Mathias Agopian19ea59f2010-02-26 13:15:18 -0800345 * the x-axis moves towards the z-axis.
346 *
347 * Note: For historical reasons the roll angle is positive in the clockwise
348 * direction (mathematically speaking, it should be positive in the
349 * counter-clockwise direction):
350 *
351 * Z
352 * ^
353 * (+roll) .--> |
354 * / |
355 * | | roll: rotation around Y axis
356 * X <-------(.)
357 * Y
358 * note that +Y == -roll
359 *
360 *
361 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800362 * Note: This definition is different from yaw, pitch and roll used in aviation
363 * where the X axis is along the long side of the plane (tail to nose).
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800364 */
365#define SENSOR_TYPE_ORIENTATION (3)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000366#define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800367
368/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800369 * SENSOR_TYPE_GYROSCOPE
Mathias Agopiana4557722012-11-28 17:21:55 -0800370 * trigger-mode: continuous
371 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800372 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700373 * All values are in radians/second and measure the rate of rotation
374 * around the X, Y and Z axis. The coordinate system is the same as is
Mathias Agopianc04e5f62010-09-14 10:53:55 -0700375 * used for the acceleration sensor. Rotation is positive in the
376 * counter-clockwise direction (right-hand rule). That is, an observer
377 * looking from some positive location on the x, y or z axis at a device
378 * positioned on the origin would report positive rotation if the device
379 * appeared to be rotating counter clockwise. Note that this is the
380 * standard mathematical definition of positive rotation and does not agree
381 * with the definition of roll given earlier.
382 * The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
Kevin Powellb01a0432010-07-19 19:12:15 -0700383 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800384 * automatic gyro-drift compensation is allowed but not required.
385 */
386#define SENSOR_TYPE_GYROSCOPE (4)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000387#define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800388
389/*
390 * SENSOR_TYPE_LIGHT
Mathias Agopiana4557722012-11-28 17:21:55 -0800391 * trigger-mode: on-change
392 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800393 *
394 * The light sensor value is returned in SI lux units.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800395 */
396#define SENSOR_TYPE_LIGHT (5)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000397#define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800398
399/*
400 * SENSOR_TYPE_PRESSURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800401 * trigger-mode: continuous
402 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800403 *
404 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800405 */
406#define SENSOR_TYPE_PRESSURE (6)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000407#define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800408
409/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
410#define SENSOR_TYPE_TEMPERATURE (7)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000411#define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800412
413/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800414 * SENSOR_TYPE_PROXIMITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800415 * trigger-mode: on-change
416 * wake-up sensor: yes
Mike Lockwooda2414312009-11-03 10:29:50 -0500417 *
418 * The distance value is measured in centimeters. Note that some proximity
419 * sensors only support a binary "close" or "far" measurement. In this case,
420 * the sensor should report its maxRange value in the "far" state and a value
421 * less than maxRange in the "near" state.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800422 */
423#define SENSOR_TYPE_PROXIMITY (8)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000424#define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800425
426/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800427 * SENSOR_TYPE_GRAVITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800428 * trigger-mode: continuous
429 * wake-up sensor: no
Mathias Agopian42b743c2010-11-22 15:55:32 -0800430 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800431 * A gravity output indicates the direction of and magnitude of gravity in
432 * the devices's coordinates. On Earth, the magnitude is 9.8 m/s^2.
433 * Units are m/s^2. The coordinate system is the same as is used for the
434 * acceleration sensor. When the device is at rest, the output of the
435 * gravity sensor should be identical to that of the accelerometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800436 */
437#define SENSOR_TYPE_GRAVITY (9)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000438#define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800439
440/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800441 * SENSOR_TYPE_LINEAR_ACCELERATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800442 * trigger-mode: continuous
443 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800444 *
445 * Indicates the linear acceleration of the device in device coordinates,
446 * not including gravity.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800447 *
448 * The output is conceptually:
449 * output of TYPE_ACCELERATION - output of TYPE_GRAVITY
450 *
451 * Readings on all axes should be close to 0 when device lies on a table.
452 * Units are m/s^2.
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800453 * The coordinate system is the same as is used for the acceleration sensor.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800454 */
455#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000456#define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800457
458
459/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800460 * SENSOR_TYPE_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800461 * trigger-mode: continuous
462 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800463 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700464 * The rotation vector symbolizes the orientation of the device relative to the
465 * East-North-Up coordinates frame. It is usually obtained by integration of
466 * accelerometer, gyroscope and magnetometer readings.
Mathias Agopian42b743c2010-11-22 15:55:32 -0800467 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700468 * The East-North-Up coordinate system is defined as a direct orthonormal basis
Mathias Agopiand93ff972011-05-02 19:10:31 -0700469 * where:
Etienne Le Grand28f04112013-03-27 18:59:10 -0700470 * - X points east and is tangential to the ground.
471 * - Y points north and is tangential to the ground.
Mathias Agopiand93ff972011-05-02 19:10:31 -0700472 * - Z points towards the sky and is perpendicular to the ground.
473 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700474 * The orientation of the phone is represented by the rotation necessary to
475 * align the East-North-Up coordinates with the phone's coordinates. That is,
476 * applying the rotation to the world frame (X,Y,Z) would align them with the
477 * phone coordinates (x,y,z).
Mathias Agopiand93ff972011-05-02 19:10:31 -0700478 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700479 * The rotation can be seen as rotating the phone by an angle theta around
480 * an axis rot_axis to go from the reference (East-North-Up aligned) device
481 * orientation to the current device orientation.
Mathias Agopian42b743c2010-11-22 15:55:32 -0800482 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700483 * The rotation is encoded as the 4 (reordered) components of a unit quaternion:
484 * sensors_event_t.data[0] = rot_axis.x*sin(theta/2)
485 * sensors_event_t.data[1] = rot_axis.y*sin(theta/2)
486 * sensors_event_t.data[2] = rot_axis.z*sin(theta/2)
487 * sensors_event_t.data[3] = cos(theta/2)
488 * where
489 * - rot_axis.x,y,z are the North-East-Up coordinates of a unit length vector
490 * representing the rotation axis
491 * - theta is the rotation angle
492 *
493 * The quaternion must be of norm 1 (it is a unit quaternion). Failure to ensure
494 * this will cause erratic client behaviour.
Etienne Le Grandca858142013-02-26 19:17:20 -0800495 *
496 * In addition, this sensor reports an estimated heading accuracy.
Etienne Le Grand28f04112013-03-27 18:59:10 -0700497 * sensors_event_t.data[4] = estimated_accuracy (in radians)
Etienne Le Grandca858142013-02-26 19:17:20 -0800498 * The heading error must be less than estimated_accuracy 95% of the time
499 *
500 * This sensor must use a gyroscope and an accelerometer as main orientation
501 * change input.
502 *
503 * This sensor can also include magnetometer input to make up for gyro drift,
504 * but it cannot be implemented using only a magnetometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800505 */
506#define SENSOR_TYPE_ROTATION_VECTOR (11)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000507#define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800508
509/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800510 * SENSOR_TYPE_RELATIVE_HUMIDITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800511 * trigger-mode: on-change
512 * wake-up sensor: no
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100513 *
514 * A relative humidity sensor measures relative ambient air humidity and
515 * returns a value in percent.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800516 */
517#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000518#define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800519
520/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800521 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800522 * trigger-mode: on-change
523 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700524 *
525 * The ambient (room) temperature in degree Celsius.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800526 */
527#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000528#define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800529
530/*
531 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800532 * trigger-mode: continuous
533 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700534 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800535 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
536 * reported separately instead of being included in the measurement.
537 * Factory calibration and temperature compensation should still be applied to
538 * the "uncalibrated" measurement.
539 * Separating away the hard iron calibration estimation allows the system to
540 * better recover from bad hard iron estimation.
541 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800542 * All values are in micro-Tesla (uT) and measure the ambient magnetic
Etienne Le Grandca858142013-02-26 19:17:20 -0800543 * field in the X, Y and Z axis. Assumptions that the the magnetic field
544 * is due to the Earth's poles should be avoided.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800545 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800546 * The uncalibrated_magnetic event contains
547 * - 3 fields for uncalibrated measurement: x_uncalib, y_uncalib, z_uncalib.
548 * Each is a component of the measured magnetic field, with soft iron
549 * and temperature compensation applied, but not hard iron calibration.
550 * These values should be continuous (no re-calibration should cause a jump).
551 * - 3 fields for hard iron bias estimates: x_bias, y_bias, z_bias.
552 * Each field is a component of the estimated hard iron calibration.
Etienne Le Grand7a813e82013-04-23 14:22:23 -0700553 * They represent the offsets to apply to the calibrated readings to obtain
554 * uncalibrated readings (x_uncalib ~= x_calibrated + x_bias)
Etienne Le Grandca858142013-02-26 19:17:20 -0800555 * These values are expected to jump as soon as the estimate of the hard iron
Etienne Le Grand7a813e82013-04-23 14:22:23 -0700556 * changes, and they should be stable the rest of the time.
Mathias Agopian1144bea2013-01-29 15:52:10 -0800557 *
558 * If this sensor is present, then the corresponding
559 * SENSOR_TYPE_MAGNETIC_FIELD must be present and both must return the
560 * same sensor_t::name and sensor_t::vendor.
Etienne Le Grandca858142013-02-26 19:17:20 -0800561 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700562 * Minimum filtering should be applied to this sensor. In particular, low pass
563 * filters should be avoided.
564 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800565 * See SENSOR_TYPE_MAGNETIC_FIELD for more information
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800566 */
567#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000568#define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800569
570/*
571 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800572 * trigger-mode: continuous
573 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800574 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800575 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
576 * field. Therefore the Y axis doesn't point north, but instead to some other
577 * reference. That reference is allowed to drift by the same order of
578 * magnitude than the gyroscope drift around the Z axis.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800579 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800580 * This sensor does not report an estimated heading accuracy:
Etienne Le Grand28f04112013-03-27 18:59:10 -0700581 * sensors_event_t.data[4] is reserved and should be set to 0
Etienne Le Grandca858142013-02-26 19:17:20 -0800582 *
583 * In the ideal case, a phone rotated and returning to the same real-world
584 * orientation should report the same game rotation vector
585 * (without using the earth's geomagnetic field).
586 *
587 * This sensor must be based on a gyroscope. It cannot be implemented using
588 * a magnetometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800589 *
590 * see SENSOR_TYPE_ROTATION_VECTOR for more details
591 */
592#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000593#define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800594
595/*
596 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800597 * trigger-mode: continuous
598 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800599 *
600 * All values are in radians/second and measure the rate of rotation
Mathias Agopian1144bea2013-01-29 15:52:10 -0800601 * around the X, Y and Z axis. An estimation of the drift on each axis is
602 * reported as well.
603 *
604 * No gyro-drift compensation shall be performed.
605 * Factory calibration and temperature compensation should still be applied
606 * to the rate of rotation (angular speeds).
607 *
608 * The coordinate system is the same as is
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800609 * used for the acceleration sensor. Rotation is positive in the
610 * counter-clockwise direction (right-hand rule). That is, an observer
611 * looking from some positive location on the x, y or z axis at a device
612 * positioned on the origin would report positive rotation if the device
613 * appeared to be rotating counter clockwise. Note that this is the
614 * standard mathematical definition of positive rotation and does not agree
615 * with the definition of roll given earlier.
616 * The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
617 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800618 * Content of an uncalibrated_gyro event: (units are rad/sec)
619 * x_uncalib : angular speed (w/o drift compensation) around the X axis
620 * y_uncalib : angular speed (w/o drift compensation) around the Y axis
621 * z_uncalib : angular speed (w/o drift compensation) around the Z axis
622 * x_bias : estimated drift around X axis in rad/s
623 * y_bias : estimated drift around Y axis in rad/s
624 * z_bias : estimated drift around Z axis in rad/s
Mathias Agopian1144bea2013-01-29 15:52:10 -0800625 *
626 * IMPLEMENTATION NOTES:
627 *
628 * If the implementation is not able to estimate the drift, then this
629 * sensor MUST NOT be reported by this HAL. Instead, the regular
630 * SENSOR_TYPE_GYROSCOPE is used without drift compensation.
631 *
632 * If this sensor is present, then the corresponding
633 * SENSOR_TYPE_GYROSCOPE must be present and both must return the
634 * same sensor_t::name and sensor_t::vendor.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800635 */
636#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000637#define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800638
Mathias Agopiana4557722012-11-28 17:21:55 -0800639
640/*
641 * SENSOR_TYPE_SIGNIFICANT_MOTION
642 * trigger-mode: one-shot
643 * wake-up sensor: yes
644 *
645 * A sensor of this type triggers an event each time significant motion
646 * is detected and automatically disables itself.
647 * The only allowed value to return is 1.0.
648 *
Etienne Le Grand1461f282013-03-05 22:00:33 -0800649 * A significant motion is a motion that might lead to a change in the user
650 * location.
651 * Examples of such motions are:
652 * walking, biking, sitting in a moving car, coach or train.
653 * Examples of situations that should not trigger significant motion:
654 * - phone in pocket and person is not moving
655 * - phone is on a table, even if the table shakes a bit due to nearby traffic
656 * or washing machine
Mathias Agopiana4557722012-11-28 17:21:55 -0800657 *
Etienne Le Grand1461f282013-03-05 22:00:33 -0800658 * A note on false positive / false negative / power consumption tradeoff
659 * - The goal of this sensor is to save power.
660 * - Triggering an event when the user is not moving (false positive) is costly
661 * in terms of power, so it should be avoided.
662 * - Not triggering an event when the user is moving (false negative) is
Etienne Le Grand2e7d3cd2013-03-07 12:22:32 -0800663 * acceptable as long as it is not done repeatedly. If the user has been
Etienne Le Grand1461f282013-03-05 22:00:33 -0800664 * walking for 10 seconds, not triggering an event within those 10 seconds
665 * is not acceptable.
Mathias Agopiana4557722012-11-28 17:21:55 -0800666 *
667 * IMPORTANT NOTE: this sensor type is very different from other types
668 * in that it must work when the screen is off without the need of
669 * holding a partial wake-lock and MUST allow the SoC to go into suspend.
670 * When significant motion is detected, the sensor must awaken the SoC and
671 * the event be reported.
672 *
673 * If a particular hardware cannot support this mode of operation then this
674 * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
675 * to "emulate" this sensor in the HAL.
676 *
677 * The whole point of this sensor type is to save power by keeping the
678 * SoC in suspend mode when the device is at rest.
679 *
680 * When the sensor is not activated, it must also be deactivated in the
681 * hardware: it must not wake up the SoC anymore, even in case of
682 * significant motion.
683 *
684 * setDelay() has no effect and is ignored.
685 * Once a "significant motion" event is returned, a sensor of this type
686 * must disables itself automatically, as if activate(..., 0) had been called.
687 */
688
689#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000690#define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
Mathias Agopiana4557722012-11-28 17:21:55 -0800691
692/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800693 * SENSOR_TYPE_STEP_DETECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800694 * trigger-mode: special
695 * wake-up sensor: no
696 *
697 * A sensor of this type triggers an event each time a step is taken
698 * by the user. The only allowed value to return is 1.0 and an event is
699 * generated for each step. Like with any other event, the timestamp
700 * indicates when the event (here the step) occurred, this corresponds to when
701 * the foot hit the ground, generating a high variation in acceleration.
702 *
703 * While this sensor operates, it shall not disrupt any other sensors, in
704 * particular, but not limited to, the accelerometer; which might very well
705 * be in use as well.
706 *
707 * This sensor must be low power. That is, if the step detection cannot be
708 * done in hardware, this sensor should not be defined. Also, when the
Mathias Agopian2f276f52013-01-28 17:54:41 -0800709 * step detector is activated and the accelerometer is not, only steps should
Mathias Agopiana4557722012-11-28 17:21:55 -0800710 * trigger interrupts (not accelerometer data).
711 *
712 * setDelay() has no impact on this sensor type
713 */
714
Mathias Agopian2f276f52013-01-28 17:54:41 -0800715#define SENSOR_TYPE_STEP_DETECTOR (18)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000716#define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
Mathias Agopiana4557722012-11-28 17:21:55 -0800717
718
719/*
720 * SENSOR_TYPE_STEP_COUNTER
721 * trigger-mode: on-change
722 * wake-up sensor: no
723 *
724 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800725 * the last reboot while activated. The value is returned as a uint64_t and is
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700726 * reset to zero only on a system / android reboot.
Mathias Agopiana4557722012-11-28 17:21:55 -0800727 *
728 * The timestamp of the event is set to the time when the first step
729 * for that event was taken.
Mathias Agopian2f276f52013-01-28 17:54:41 -0800730 * See SENSOR_TYPE_STEP_DETECTOR for the signification of the time of a step.
Mathias Agopiana4557722012-11-28 17:21:55 -0800731 *
732 * The minimum size of the hardware's internal counter shall be 16 bits
733 * (this restriction is here to avoid too frequent wake-ups when the
734 * delay is very large).
735 *
736 * IMPORTANT NOTE: this sensor type is different from other types
737 * in that it must work when the screen is off without the need of
738 * holding a partial wake-lock and MUST allow the SoC to go into suspend.
739 * Unlike other sensors, while in suspend mode this sensor must stay active,
740 * no events are reported during that time but, steps continue to be
741 * accounted for; an event will be reported as soon as the SoC resumes if
742 * the timeout has expired.
743 *
744 * In other words, when the screen is off and the device allowed to
745 * go into suspend mode, we don't want to be woken up, regardless of the
746 * setDelay() value, but the steps shall continue to be counted.
747 *
748 * The driver must however ensure that the internal step count never
749 * overflows. It is allowed in this situation to wake the SoC up so the
750 * driver can do the counter maintenance.
751 *
752 * While this sensor operates, it shall not disrupt any other sensors, in
753 * particular, but not limited to, the accelerometer; which might very well
754 * be in use as well.
755 *
756 * If a particular hardware cannot support these modes of operation then this
757 * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
758 * to "emulate" this sensor in the HAL.
759 *
760 * This sensor must be low power. That is, if the step detection cannot be
761 * done in hardware, this sensor should not be defined. Also, when the
762 * step counter is activated and the accelerometer is not, only steps should
763 * trigger interrupts (not accelerometer data).
764 *
765 * The whole point of this sensor type is to save power by keeping the
766 * SoC in suspend mode when the device is at rest.
767 */
768
769#define SENSOR_TYPE_STEP_COUNTER (19)
Aravind Akellab20f1a32014-04-07 22:46:01 +0000770#define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
Mathias Agopiana4557722012-11-28 17:21:55 -0800771
Etienne Le Grandca858142013-02-26 19:17:20 -0800772/*
773 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
774 * trigger-mode: continuous
775 * wake-up sensor: no
776 *
777 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
778 * of using a gyroscope.
779 *
780 * This sensor must be based on a magnetometer. It cannot be implemented using
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700781 * a gyroscope, and gyroscope input cannot be used by this sensor, as the
782 * goal of this sensor is to be low power.
783 * The accelerometer can be (and usually is) used.
Etienne Le Grandca858142013-02-26 19:17:20 -0800784 *
785 * Just like SENSOR_TYPE_ROTATION_VECTOR, this sensor reports an estimated
786 * heading accuracy:
Etienne Le Grand28f04112013-03-27 18:59:10 -0700787 * sensors_event_t.data[4] = estimated_accuracy (in radians)
Etienne Le Grandca858142013-02-26 19:17:20 -0800788 * The heading error must be less than estimated_accuracy 95% of the time
789 *
790 * see SENSOR_TYPE_ROTATION_VECTOR for more details
791 */
Aravind Akellab20f1a32014-04-07 22:46:01 +0000792#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
793#define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
794
795/*
796 * SENSOR_TYPE_HEART_RATE
797 * trigger-mode: on-change
798 * wake-up sensor: no
799 *
800 * A sensor of this type returns the current heart rate if activated.
801 * The value is returned as a float which represents the heart rate in beats
802 * per minute (BPM).
803 * When the sensor cannot measure the heart rate, the returned value must be 0.
804 * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
805 */
806#define SENSOR_TYPE_HEART_RATE (21)
807#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
Mathias Agopiana4557722012-11-28 17:21:55 -0800808
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800809/**
810 * Values returned by the accelerometer in various locations in the universe.
811 * all values are in SI units (m/s^2)
812 */
813#define GRAVITY_SUN (275.0f)
814#define GRAVITY_EARTH (9.80665f)
815
816/** Maximum magnetic field on Earth's surface */
817#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
818
819/** Minimum magnetic field on Earth's surface */
820#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
821
822
823/**
824 * status of orientation sensor
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800825 */
Kevin Powellb01a0432010-07-19 19:12:15 -0700826
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800827#define SENSOR_STATUS_UNRELIABLE 0
828#define SENSOR_STATUS_ACCURACY_LOW 1
829#define SENSOR_STATUS_ACCURACY_MEDIUM 2
830#define SENSOR_STATUS_ACCURACY_HIGH 3
831
832
833/**
834 * sensor event data
835 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800836typedef struct {
837 union {
838 float v[3];
839 struct {
840 float x;
841 float y;
842 float z;
843 };
844 struct {
845 float azimuth;
846 float pitch;
847 float roll;
848 };
849 };
850 int8_t status;
851 uint8_t reserved[3];
852} sensors_vec_t;
853
854/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800855 * uncalibrated gyroscope and magnetometer event data
856 */
857typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700858 union {
859 float uncalib[3];
860 struct {
861 float x_uncalib;
862 float y_uncalib;
863 float z_uncalib;
864 };
865 };
866 union {
867 float bias[3];
868 struct {
869 float x_bias;
870 float y_bias;
871 float z_bias;
872 };
873 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800874} uncalibrated_event_t;
875
Mathias Agopian16671c52013-07-24 21:07:40 -0700876typedef struct meta_data_event {
877 int32_t what;
878 int32_t sensor;
879} meta_data_event_t;
880
Etienne Le Grandca858142013-02-26 19:17:20 -0800881/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800882 * Union of the various types of sensor data
883 * that can be returned.
884 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700885typedef struct sensors_event_t {
886 /* must be sizeof(struct sensors_event_t) */
887 int32_t version;
888
889 /* sensor identifier */
890 int32_t sensor;
891
892 /* sensor type */
893 int32_t type;
894
895 /* reserved */
896 int32_t reserved0;
897
898 /* time is in nanosecond */
899 int64_t timestamp;
900
901 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700902 union {
903 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700904
Mathias Agopian27e16682013-07-08 14:00:54 -0700905 /* acceleration values are in meter per second per second (m/s^2) */
906 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700907
Mathias Agopian27e16682013-07-08 14:00:54 -0700908 /* magnetic vector values are in micro-Tesla (uT) */
909 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700910
Mathias Agopian27e16682013-07-08 14:00:54 -0700911 /* orientation values are in degrees */
912 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700913
Mathias Agopian27e16682013-07-08 14:00:54 -0700914 /* gyroscope values are in rad/s */
915 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700916
Mathias Agopian27e16682013-07-08 14:00:54 -0700917 /* temperature is in degrees centigrade (Celsius) */
918 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700919
Mathias Agopian27e16682013-07-08 14:00:54 -0700920 /* distance in centimeters */
921 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700922
Mathias Agopian27e16682013-07-08 14:00:54 -0700923 /* light in SI lux units */
924 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700925
Mathias Agopian27e16682013-07-08 14:00:54 -0700926 /* pressure in hectopascal (hPa) */
927 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100928
Mathias Agopian27e16682013-07-08 14:00:54 -0700929 /* relative humidity in percent */
930 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800931
Mathias Agopian27e16682013-07-08 14:00:54 -0700932 /* uncalibrated gyroscope values are in rad/s */
933 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800934
Mathias Agopian27e16682013-07-08 14:00:54 -0700935 /* uncalibrated magnetometer values are in micro-Teslas */
936 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700937
Aravind Akellab20f1a32014-04-07 22:46:01 +0000938 /* heart rate in bpm */
939 float heart_rate;
940
Mathias Agopian16671c52013-07-24 21:07:40 -0700941 /* this is a special event. see SENSOR_TYPE_META_DATA above.
942 * sensors_meta_data_event_t events are all reported with a type of
943 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
944 */
945 meta_data_event_t meta_data;
Mathias Agopian27e16682013-07-08 14:00:54 -0700946 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800947
Mathias Agopian27e16682013-07-08 14:00:54 -0700948 union {
949 uint64_t data[8];
950
951 /* step-counter */
952 uint64_t step_counter;
953 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700954 };
Mathias Agopian27e16682013-07-08 14:00:54 -0700955 uint32_t reserved1[4];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700956} sensors_event_t;
957
958
Mathias Agopian16671c52013-07-24 21:07:40 -0700959/* see SENSOR_TYPE_META_DATA */
960typedef sensors_event_t sensors_meta_data_event_t;
961
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700962
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800963struct sensor_t;
964
965/**
966 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
967 * and the fields of this data structure must begin with hw_module_t
968 * followed by module specific information.
969 */
970struct sensors_module_t {
971 struct hw_module_t common;
972
973 /**
974 * Enumerate all available sensors. The list is returned in "list".
975 * @return number of sensors in the list
976 */
977 int (*get_sensors_list)(struct sensors_module_t* module,
978 struct sensor_t const** list);
979};
980
981struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800982
983 /* Name of this sensor.
984 * All sensors of the same "type" must have a different "name".
985 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800986 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800987
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800988 /* vendor of the hardware part */
989 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800990
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800991 /* version of the hardware part + driver. The value of this field
992 * must increase when the driver is updated in a way that changes the
993 * output of this sensor. This is important for fused sensors when the
994 * fusion algorithm is updated.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800995 */
996 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800997
998 /* handle that identifies this sensors. This handle is used to reference
999 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001000 */
1001 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -08001002
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001003 /* this sensor's type. */
1004 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -08001005
1006 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001007 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -08001008
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001009 /* smallest difference between two values reported by this sensor */
1010 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -08001011
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001012 /* rough estimate of this sensor's power consumption in mA */
1013 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -08001014
1015 /* this value depends on the trigger mode:
1016 *
1017 * continuous: minimum sample period allowed in microseconds
1018 * on-change : 0
1019 * one-shot :-1
1020 * special : 0, unless otherwise noted
1021 */
Mathias Agopian1511e202010-07-29 15:33:22 -07001022 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -08001023
Mathias Agopian16671c52013-07-24 21:07:40 -07001024 /* number of events reserved for this sensor in the batch mode FIFO.
1025 * If there is a dedicated FIFO for this sensor, then this is the
1026 * size of this FIFO. If the FIFO is shared with other sensors,
1027 * this is the size reserved for that sensor and it can be zero.
1028 */
1029 uint32_t fifoReservedEventCount;
1030
1031 /* maximum number of events of this sensor that could be batched.
1032 * This is especially relevant when the FIFO is shared between
1033 * several sensors; this value is then set to the size of that FIFO.
1034 */
1035 uint32_t fifoMaxEventCount;
1036
Aravind Akellab20f1a32014-04-07 22:46:01 +00001037 /* type of this sensor as a string. Set to corresponding
1038 * SENSOR_STRING_TYPE_*.
1039 * When defining an OEM specific sensor or sensor manufacturer specific
1040 * sensor, use your reserve domain name as a prefix.
1041 * ex: com.google.glass.onheaddetector
1042 * For sensors of known type, the android framework might overwrite this
1043 * string automatically.
1044 */
1045 const char* stringType;
1046
1047 /* permission required to see this sensor, register to it and receive data.
1048 * Set to "" if no permission is required. Some sensor types like the
1049 * heart rate monitor have a mandatory require_permission.
1050 * For sensors that always require a specific permission, like the heart
1051 * rate monitor, the android framework might overwrite this string
1052 * automatically.
1053 */
1054 const char* requiredPermission;
1055
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001056 /* reserved fields, must be zero */
Aravind Akellab20f1a32014-04-07 22:46:01 +00001057 void* reserved[4];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001058};
1059
1060
Mathias Agopiana4557722012-11-28 17:21:55 -08001061/*
1062 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
1063 * and is present for backward binary and source compatibility.
1064 * (see documentation of the hooks in struct sensors_poll_device_1 below)
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001065 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001066struct sensors_poll_device_t {
1067 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001068 int (*activate)(struct sensors_poll_device_t *dev,
1069 int handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001070 int (*setDelay)(struct sensors_poll_device_t *dev,
1071 int handle, int64_t ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001072 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001073 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001074};
1075
Mathias Agopiana4557722012-11-28 17:21:55 -08001076/*
1077 * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
1078 */
1079typedef struct sensors_poll_device_1 {
1080 union {
1081 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
1082 * and can be down-cast to it
1083 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001084 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -08001085
1086 struct {
1087 struct hw_device_t common;
1088
1089 /* Activate/de-activate one sensor.
1090 *
1091 * handle is the handle of the sensor to change.
1092 * enabled set to 1 to enable, or 0 to disable the sensor.
1093 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001094 * if enabled is set to 1, the sensor is activated even if
1095 * setDelay() wasn't called before. In this case, a default rate
1096 * should be used.
1097 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001098 * unless otherwise noted in the sensor types definitions, an
1099 * activated sensor never prevents the SoC to go into suspend
1100 * mode; that is, the HAL shall not hold a partial wake-lock on
1101 * behalf of applications.
1102 *
1103 * one-shot sensors de-activate themselves automatically upon
1104 * receiving an event and they must still accept to be deactivated
1105 * through a call to activate(..., ..., 0).
1106 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001107 * if "enabled" is 1 and the sensor is already activated, this
Mathias Agopiana4557722012-11-28 17:21:55 -08001108 * function is a no-op and succeeds.
1109 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001110 * if "enabled" is 0 and the sensor is already de-activated,
Mathias Agopiana4557722012-11-28 17:21:55 -08001111 * this function is a no-op and succeeds.
1112 *
1113 * return 0 on success, negative errno code otherwise
1114 */
1115 int (*activate)(struct sensors_poll_device_t *dev,
1116 int handle, int enabled);
1117
1118 /**
Mathias Agopian1144bea2013-01-29 15:52:10 -08001119 * Set the events's period in nanoseconds for a given sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -08001120 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001121 * What the period_ns parameter means depends on the specified
Mathias Agopiana4557722012-11-28 17:21:55 -08001122 * sensor's trigger mode:
1123 *
1124 * continuous: setDelay() sets the sampling rate.
1125 * on-change: setDelay() limits the delivery rate of events
1126 * one-shot: setDelay() is ignored. it has no effect.
1127 * special: see specific sensor type definitions
1128 *
1129 * For continuous and on-change sensors, if the requested value is
1130 * less than sensor_t::minDelay, then it's silently clamped to
1131 * sensor_t::minDelay unless sensor_t::minDelay is 0, in which
1132 * case it is clamped to >= 1ms.
1133 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001134 * setDelay will not be called when the sensor is in batching mode.
1135 * In this case, batch() will be called with the new period.
1136 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001137 * @return 0 if successful, < 0 on error
1138 */
1139 int (*setDelay)(struct sensors_poll_device_t *dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -08001140 int handle, int64_t period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -08001141
1142 /**
1143 * Returns an array of sensor data.
1144 * This function must block until events are available.
1145 *
1146 * return the number of events read on success, or -errno in case
1147 * of an error.
1148 *
1149 * The number of events returned in data must be less or equal
Etienne Le Grand28f04112013-03-27 18:59:10 -07001150 * to the "count" argument.
Mathias Agopiana4557722012-11-28 17:21:55 -08001151 *
1152 * This function shall never return 0 (no event).
1153 */
1154 int (*poll)(struct sensors_poll_device_t *dev,
1155 sensors_event_t* data, int count);
1156 };
1157 };
1158
Mathias Agopiana4557722012-11-28 17:21:55 -08001159
1160 /*
Mathias Agopian1144bea2013-01-29 15:52:10 -08001161 * Enables batch mode for the given sensor and sets the delay between events
Mathias Agopiana4557722012-11-28 17:21:55 -08001162 *
1163 * A timeout value of zero disables batch mode for the given sensor.
1164 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001165 * The period_ns parameter is equivalent to calling setDelay() -- this
1166 * function both enables or disables the batch mode AND sets the events's
1167 * period in nanosecond. See setDelay() above for a detailed explanation of
1168 * the period_ns parameter.
1169 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001170 * BATCH MODE:
1171 * -----------
1172 * In non-batch mode, all sensor events must be reported as soon as they
1173 * are detected. For example, an accelerometer activated at 50Hz will
1174 * trigger interrupts 50 times per second.
1175 * While in batch mode, sensor events do not need to be reported as soon
1176 * as they are detected. They can be temporarily stored in batches and
1177 * reported in batches, as long as no event is delayed by more than
1178 * "timeout" nanoseconds. That is, all events since the previous batch
1179 * are recorded and returned all at once. This allows to reduce the amount
1180 * of interrupts sent to the SoC, and allow the SoC to switch to a lower
1181 * power state (Idle) while the sensor is capturing and batching data.
Mathias Agopiana4557722012-11-28 17:21:55 -08001182 *
1183 * setDelay() is not affected and it behaves as usual.
1184 *
1185 * Each event has a timestamp associated with it, the timestamp
1186 * must be accurate and correspond to the time at which the event
1187 * physically happened.
1188 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001189 * Batching does not modify the behavior of poll(): batches from different
1190 * sensors can be interleaved and split. As usual, all events from the same
1191 * sensor are time-ordered.
1192 *
1193 * BEHAVIOUR OUTSIDE OF SUSPEND MODE:
1194 * ----------------------------------
1195 *
1196 * When the SoC is awake (not in suspend mode), events must be reported in
1197 * batches at least every "timeout". No event shall be dropped or lost.
Mathias Agopiana4557722012-11-28 17:21:55 -08001198 * If internal h/w FIFOs fill-up before the timeout, then events are
Etienne Le Grand28f04112013-03-27 18:59:10 -07001199 * reported at that point to ensure no event is lost.
Mathias Agopian1144bea2013-01-29 15:52:10 -08001200 *
1201 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001202 * NORMAL BEHAVIOR IN SUSPEND MODE:
1203 * ---------------------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001204 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001205 * By default, batch mode doesn't significantly change the interaction with
1206 * suspend mode. That is, sensors must continue to allow the SoC to
Mathias Agopiana4557722012-11-28 17:21:55 -08001207 * go into suspend mode and sensors must stay active to fill their
Etienne Le Grand28f04112013-03-27 18:59:10 -07001208 * internal FIFO. In this mode, when the FIFO fills up, it shall wrap
Mathias Agopiana4557722012-11-28 17:21:55 -08001209 * around (basically behave like a circular buffer, overwriting events).
1210 * As soon as the SoC comes out of suspend mode, a batch is produced with
1211 * as much as the recent history as possible, and batch operation
1212 * resumes as usual.
1213 *
1214 * The behavior described above allows applications to record the recent
1215 * history of a set of sensor while keeping the SoC into suspend. It
1216 * also allows the hardware to not have to rely on a wake-up interrupt line.
1217 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001218 * WAKE_UPON_FIFO_FULL BEHAVIOR IN SUSPEND MODE:
1219 * ----------------------------------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001220 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001221 * There are cases, however, where an application cannot afford to lose
1222 * any events, even when the device goes into suspend mode.
1223 * For a given rate, if a sensor has the capability to store at least 10
1224 * seconds worth of events in its FIFO and is able to wake up the Soc, it
1225 * can implement an optional secondary mode: the WAKE_UPON_FIFO_FULL mode.
1226 *
1227 * The caller will set the SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag to
1228 * activate this mode. If the sensor does not support this mode, batch()
1229 * will fail when the flag is set.
1230 *
1231 * When running with the WAKE_UPON_FIFO_FULL flag set, no events can be
1232 * lost. When the FIFO is getting full, the sensor must wake up the SoC from
1233 * suspend and return a batch before the FIFO fills-up.
1234 * Depending on the device, it might take a few miliseconds for the SoC to
1235 * entirely come out of suspend and start flushing the FIFO. Enough head
1236 * room must be allocated in the FIFO to allow the device to entirely come
1237 * out of suspend without the FIFO overflowing (no events shall be lost).
1238 *
1239 * Implementing the WAKE_UPON_FIFO_FULL mode is optional.
1240 * If the hardware cannot support this mode, or if the physical
Mathias Agopiana4557722012-11-28 17:21:55 -08001241 * FIFO is so small that the device would never be allowed to go into
Mathias Agopian1144bea2013-01-29 15:52:10 -08001242 * suspend for at least 10 seconds, then this function MUST fail when
1243 * the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is set, regardless of
1244 * the value of the timeout parameter.
Mathias Agopiana4557722012-11-28 17:21:55 -08001245 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001246 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001247 * DRY RUN:
1248 * --------
Mathias Agopiana4557722012-11-28 17:21:55 -08001249 *
1250 * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns
Mathias Agopian1144bea2013-01-29 15:52:10 -08001251 * without modifying the batch mode or the event period and has no side
1252 * effects, but returns errors as usual (as it would if this flag was
1253 * not set). This flag is used to check if batch mode is available for a
1254 * given configuration -- in particular for a given sensor at a given rate.
1255 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001256 *
1257 * Return values:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001258 * --------------
1259 *
1260 * Because sensors must be independent, the return value must not depend
1261 * on the state of the system (whether another sensor is on or not),
1262 * nor on whether the flag SENSORS_BATCH_DRY_RUN is set (in other words,
1263 * if a batch call with SENSORS_BATCH_DRY_RUN is successful,
1264 * the same call without SENSORS_BATCH_DRY_RUN must succeed as well).
Mathias Agopiana4557722012-11-28 17:21:55 -08001265 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001266 * When timeout is not 0:
1267 * If successful, 0 is returned.
1268 * If the specified sensor doesn't support batch mode, return -EINVAL.
1269 * If the specified sensor's trigger-mode is one-shot, return -EINVAL.
1270 * If WAKE_UPON_FIFO_FULL is specified and the specified sensor's internal
1271 * FIFO is too small to store at least 10 seconds worth of data at the
1272 * given rate, -EINVAL is returned. Note that as stated above, this has to
1273 * be determined at compile time, and not based on the state of the
1274 * system.
1275 * If some other constraints above cannot be satisfied, return -EINVAL.
Mathias Agopiana4557722012-11-28 17:21:55 -08001276 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001277 * Note: the timeout parameter, when > 0, has no impact on whether this
1278 * function succeeds or fails.
1279 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001280 * When timeout is 0:
1281 * The caller will never set the wake_upon_fifo_full flag.
1282 * The function must succeed, and batch mode must be deactivated.
1283 *
1284 * Independently of whether DRY_RUN is specified, When the call to batch()
1285 * fails, no state should be changed. In particular, a failed call to
1286 * batch() should not change the rate of the sensor. Example:
1287 * setDelay(..., 10ms)
1288 * batch(..., 20ms, ...) fails
1289 * rate should stay 10ms.
Mathias Agopiana4557722012-11-28 17:21:55 -08001290 *
1291 *
1292 * IMPLEMENTATION NOTES:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001293 * ---------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001294 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001295 * Batch mode, if supported, should happen at the hardware level,
Mathias Agopiana4557722012-11-28 17:21:55 -08001296 * typically using hardware FIFOs. In particular, it SHALL NOT be
1297 * implemented in the HAL, as this would be counter productive.
1298 * The goal here is to save significant amounts of power.
1299 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001300 * In some implementations, events from several sensors can share the
1301 * same physical FIFO. In that case, all events in the FIFO can be sent and
1302 * processed by the HAL as soon as one batch must be reported.
1303 * For example, if the following sensors are activated:
1304 * - accelerometer batched with timeout = 20s
1305 * - gyroscope batched with timeout = 5s
1306 * then the accelerometer batches can be reported at the same time the
1307 * gyroscope batches are reported (every 5 seconds)
1308 *
1309 * Batch mode can be enabled or disabled at any time, in particular
1310 * while the specified sensor is already enabled, and this shall not
Mathias Agopiana4557722012-11-28 17:21:55 -08001311 * result in the loss of events.
1312 *
Etienne Le Grandca858142013-02-26 19:17:20 -08001313 * COMPARATIVE IMPORTANCE OF BATCHING FOR DIFFERENT SENSORS:
1314 * ---------------------------------------------------------
1315 *
1316 * On platforms on which hardware fifo size is limited, the system designers
1317 * might have to choose how much fifo to reserve for each sensor. To help
Etienne Le Grand28f04112013-03-27 18:59:10 -07001318 * with this choice, here is a list of applications made possible when
Etienne Le Grandca858142013-02-26 19:17:20 -08001319 * batching is implemented on the different sensors.
1320 *
1321 * High value: Low power pedestrian dead reckoning
1322 * Target batching time: 20 seconds to 1 minute
1323 * Sensors to batch:
1324 * - Step detector
1325 * - Rotation vector or game rotation vector at 5Hz
Etienne Le Grand28f04112013-03-27 18:59:10 -07001326 * Gives us step and heading while letting the SoC go to Suspend.
Etienne Le Grandca858142013-02-26 19:17:20 -08001327 *
1328 * High value: Medium power activity/gesture recognition
1329 * Target batching time: 3 seconds
1330 * Sensors to batch: accelerometer between 20Hz and 50Hz
1331 * Allows recognizing arbitrary activities and gestures without having
Etienne Le Grand28f04112013-03-27 18:59:10 -07001332 * to keep the SoC fully awake while the data is collected.
Etienne Le Grandca858142013-02-26 19:17:20 -08001333 *
1334 * Medium-high value: Interrupt load reduction
1335 * Target batching time: < 1 second
1336 * Sensors to batch: any high frequency sensor.
1337 * If the gyroscope is set at 800Hz, even batching just 10 gyro events can
1338 * reduce the number of interrupts from 800/second to 80/second.
1339 *
1340 * Medium value: Continuous low frequency data collection
1341 * Target batching time: > 1 minute
1342 * Sensors to batch: barometer, humidity sensor, other low frequency
1343 * sensors.
1344 * Allows creating monitoring applications at low power.
1345 *
1346 * Medium value: Continuous full-sensors collection
1347 * Target batching time: > 1 minute
1348 * Sensors to batch: all, at high frequencies
Etienne Le Grand28f04112013-03-27 18:59:10 -07001349 * Allows full collection of sensor data while leaving the SoC in
Etienne Le Grandca858142013-02-26 19:17:20 -08001350 * suspend mode. Only to consider if fifo space is not an issue.
Etienne Le Grand28f04112013-03-27 18:59:10 -07001351 *
1352 * In each of the cases above, if WAKE_UPON_FIFO_FULL is implemented, the
1353 * applications might decide to let the SoC go to suspend, allowing for even
1354 * more power savings.
Mathias Agopiana4557722012-11-28 17:21:55 -08001355 */
1356 int (*batch)(struct sensors_poll_device_1* dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -08001357 int handle, int flags, int64_t period_ns, int64_t timeout);
Mathias Agopiana4557722012-11-28 17:21:55 -08001358
Mathias Agopian16671c52013-07-24 21:07:40 -07001359 /*
1360 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
1361 * to the end of the "batch mode" FIFO for the specified sensor and flushes
1362 * the FIFO; those events are delivered as usual (i.e.: as if the batch
1363 * timeout had expired) and removed from the FIFO.
1364 *
1365 * See the META_DATA_FLUSH_COMPLETE section for details about the
1366 * META_DATA_FLUSH_COMPLETE event.
1367 *
1368 * The flush happens asynchronously (i.e.: this function must return
1369 * immediately).
1370 *
1371 * If the implementation uses a single FIFO for several sensors, that
1372 * FIFO is flushed and the META_DATA_FLUSH_COMPLETE event is added only
1373 * for the specified sensor.
1374 *
1375 * If the specified sensor wasn't in batch mode, flush succeeds and
1376 * promptly sends a META_DATA_FLUSH_COMPLETE event for that sensor.
1377 *
1378 * If the FIFO was empty at the time of the call, flush returns
1379 * 0 (success) and promptly sends a META_DATA_FLUSH_COMPLETE event
1380 * for that sensor.
1381 *
1382 * If the specified sensor wasn't enabled, flush returns -EINVAL.
1383 *
1384 * return 0 on success, negative errno code otherwise.
1385 */
1386 int (*flush)(struct sensors_poll_device_1* dev, int handle);
1387
Mathias Agopiana4557722012-11-28 17:21:55 -08001388 void (*reserved_procs[8])(void);
1389
1390} sensors_poll_device_1_t;
1391
1392
1393
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001394/** convenience API for opening and closing a device */
1395
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001396static inline int sensors_open(const struct hw_module_t* module,
1397 struct sensors_poll_device_t** device) {
1398 return module->methods->open(module,
1399 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1400}
1401
1402static inline int sensors_close(struct sensors_poll_device_t* device) {
1403 return device->common.close(&device->common);
1404}
1405
Mathias Agopiana4557722012-11-28 17:21:55 -08001406static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001407 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001408 return module->methods->open(module,
1409 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1410}
1411
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001412static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001413 return device->common.close(&device->common);
1414}
1415
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001416__END_DECLS
1417
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001418#endif // ANDROID_SENSORS_INTERFACE_H