blob: cc080919244da985e1681986586f3c6630869e37 [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 *
Etienne Le Grand7b361582014-05-16 11:08:28 -0700800 * A sensor of this type returns the current heart rate.
801 * The events contain the current heart rate in beats per minute (BPM) and the
802 * status of the sensor during the measurement. See heart_rate_event_t for more
803 * details.
804 *
805 * Because this sensor is on-change, events must be generated when and only
806 * when heart_rate.bpm or heart_rate.status have changed since the last
Vinod Krishnan74279e32014-08-28 15:25:13 -0700807 * event. In particular, upon the first activation, unless the device is known
808 * to not be on the body, the status field of the first event must be set to
809 * SENSOR_STATUS_UNRELIABLE. The event should be generated no faster than every
810 * period_ns passed to setDelay() or to batch().
811 * See the definition of the on-change trigger mode for more information.
Etienne Le Grand7b361582014-05-16 11:08:28 -0700812 *
Aravind Akellab20f1a32014-04-07 22:46:01 +0000813 * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
814 */
815#define SENSOR_TYPE_HEART_RATE (21)
816#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
Mathias Agopiana4557722012-11-28 17:21:55 -0800817
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800818/**
819 * Values returned by the accelerometer in various locations in the universe.
820 * all values are in SI units (m/s^2)
821 */
822#define GRAVITY_SUN (275.0f)
823#define GRAVITY_EARTH (9.80665f)
824
825/** Maximum magnetic field on Earth's surface */
826#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
827
828/** Minimum magnetic field on Earth's surface */
829#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
830
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800831/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700832 * Possible values of the status field of sensor events.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800833 */
Etienne Le Grand7b361582014-05-16 11:08:28 -0700834#define SENSOR_STATUS_NO_CONTACT -1
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800835#define SENSOR_STATUS_UNRELIABLE 0
836#define SENSOR_STATUS_ACCURACY_LOW 1
837#define SENSOR_STATUS_ACCURACY_MEDIUM 2
838#define SENSOR_STATUS_ACCURACY_HIGH 3
839
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800840/**
841 * sensor event data
842 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800843typedef struct {
844 union {
845 float v[3];
846 struct {
847 float x;
848 float y;
849 float z;
850 };
851 struct {
852 float azimuth;
853 float pitch;
854 float roll;
855 };
856 };
857 int8_t status;
858 uint8_t reserved[3];
859} sensors_vec_t;
860
861/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800862 * uncalibrated gyroscope and magnetometer event data
863 */
864typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700865 union {
866 float uncalib[3];
867 struct {
868 float x_uncalib;
869 float y_uncalib;
870 float z_uncalib;
871 };
872 };
873 union {
874 float bias[3];
875 struct {
876 float x_bias;
877 float y_bias;
878 float z_bias;
879 };
880 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800881} uncalibrated_event_t;
882
Mathias Agopian16671c52013-07-24 21:07:40 -0700883typedef struct meta_data_event {
884 int32_t what;
885 int32_t sensor;
886} meta_data_event_t;
887
Etienne Le Grandca858142013-02-26 19:17:20 -0800888/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700889 * Heart rate event data
890 */
891typedef struct {
892 // Heart rate in beats per minute.
893 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
894 float bpm;
895 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
896 int8_t status;
897} heart_rate_event_t;
898
899/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800900 * Union of the various types of sensor data
901 * that can be returned.
902 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700903typedef struct sensors_event_t {
904 /* must be sizeof(struct sensors_event_t) */
905 int32_t version;
906
907 /* sensor identifier */
908 int32_t sensor;
909
910 /* sensor type */
911 int32_t type;
912
913 /* reserved */
914 int32_t reserved0;
915
916 /* time is in nanosecond */
917 int64_t timestamp;
918
919 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700920 union {
921 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700922
Mathias Agopian27e16682013-07-08 14:00:54 -0700923 /* acceleration values are in meter per second per second (m/s^2) */
924 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700925
Mathias Agopian27e16682013-07-08 14:00:54 -0700926 /* magnetic vector values are in micro-Tesla (uT) */
927 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700928
Mathias Agopian27e16682013-07-08 14:00:54 -0700929 /* orientation values are in degrees */
930 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700931
Mathias Agopian27e16682013-07-08 14:00:54 -0700932 /* gyroscope values are in rad/s */
933 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700934
Mathias Agopian27e16682013-07-08 14:00:54 -0700935 /* temperature is in degrees centigrade (Celsius) */
936 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700937
Mathias Agopian27e16682013-07-08 14:00:54 -0700938 /* distance in centimeters */
939 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700940
Mathias Agopian27e16682013-07-08 14:00:54 -0700941 /* light in SI lux units */
942 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700943
Mathias Agopian27e16682013-07-08 14:00:54 -0700944 /* pressure in hectopascal (hPa) */
945 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100946
Mathias Agopian27e16682013-07-08 14:00:54 -0700947 /* relative humidity in percent */
948 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800949
Mathias Agopian27e16682013-07-08 14:00:54 -0700950 /* uncalibrated gyroscope values are in rad/s */
951 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800952
Mathias Agopian27e16682013-07-08 14:00:54 -0700953 /* uncalibrated magnetometer values are in micro-Teslas */
954 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700955
Etienne Le Grand7b361582014-05-16 11:08:28 -0700956 /* heart rate data containing value in bpm and status */
957 heart_rate_event_t heart_rate;
Aravind Akellab20f1a32014-04-07 22:46:01 +0000958
Mathias Agopian16671c52013-07-24 21:07:40 -0700959 /* this is a special event. see SENSOR_TYPE_META_DATA above.
960 * sensors_meta_data_event_t events are all reported with a type of
961 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
962 */
963 meta_data_event_t meta_data;
Mathias Agopian27e16682013-07-08 14:00:54 -0700964 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800965
Mathias Agopian27e16682013-07-08 14:00:54 -0700966 union {
967 uint64_t data[8];
968
969 /* step-counter */
970 uint64_t step_counter;
971 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700972 };
Mathias Agopian27e16682013-07-08 14:00:54 -0700973 uint32_t reserved1[4];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700974} sensors_event_t;
975
976
Mathias Agopian16671c52013-07-24 21:07:40 -0700977/* see SENSOR_TYPE_META_DATA */
978typedef sensors_event_t sensors_meta_data_event_t;
979
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700980
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800981struct sensor_t;
982
983/**
984 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
985 * and the fields of this data structure must begin with hw_module_t
986 * followed by module specific information.
987 */
988struct sensors_module_t {
989 struct hw_module_t common;
990
991 /**
992 * Enumerate all available sensors. The list is returned in "list".
993 * @return number of sensors in the list
994 */
995 int (*get_sensors_list)(struct sensors_module_t* module,
996 struct sensor_t const** list);
997};
998
999struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -08001000
1001 /* Name of this sensor.
1002 * All sensors of the same "type" must have a different "name".
1003 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001004 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -08001005
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001006 /* vendor of the hardware part */
1007 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -08001008
Mathias Agopiane9eaf372011-11-07 21:32:34 -08001009 /* version of the hardware part + driver. The value of this field
1010 * must increase when the driver is updated in a way that changes the
1011 * output of this sensor. This is important for fused sensors when the
1012 * fusion algorithm is updated.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001013 */
1014 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -08001015
1016 /* handle that identifies this sensors. This handle is used to reference
1017 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001018 */
1019 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -08001020
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001021 /* this sensor's type. */
1022 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -08001023
1024 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001025 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -08001026
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001027 /* smallest difference between two values reported by this sensor */
1028 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -08001029
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001030 /* rough estimate of this sensor's power consumption in mA */
1031 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -08001032
1033 /* this value depends on the trigger mode:
1034 *
1035 * continuous: minimum sample period allowed in microseconds
1036 * on-change : 0
1037 * one-shot :-1
1038 * special : 0, unless otherwise noted
1039 */
Mathias Agopian1511e202010-07-29 15:33:22 -07001040 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -08001041
Mathias Agopian16671c52013-07-24 21:07:40 -07001042 /* number of events reserved for this sensor in the batch mode FIFO.
1043 * If there is a dedicated FIFO for this sensor, then this is the
1044 * size of this FIFO. If the FIFO is shared with other sensors,
1045 * this is the size reserved for that sensor and it can be zero.
1046 */
1047 uint32_t fifoReservedEventCount;
1048
1049 /* maximum number of events of this sensor that could be batched.
1050 * This is especially relevant when the FIFO is shared between
1051 * several sensors; this value is then set to the size of that FIFO.
1052 */
1053 uint32_t fifoMaxEventCount;
1054
Aravind Akellab20f1a32014-04-07 22:46:01 +00001055 /* type of this sensor as a string. Set to corresponding
1056 * SENSOR_STRING_TYPE_*.
1057 * When defining an OEM specific sensor or sensor manufacturer specific
1058 * sensor, use your reserve domain name as a prefix.
1059 * ex: com.google.glass.onheaddetector
1060 * For sensors of known type, the android framework might overwrite this
1061 * string automatically.
1062 */
1063 const char* stringType;
1064
1065 /* permission required to see this sensor, register to it and receive data.
1066 * Set to "" if no permission is required. Some sensor types like the
1067 * heart rate monitor have a mandatory require_permission.
1068 * For sensors that always require a specific permission, like the heart
1069 * rate monitor, the android framework might overwrite this string
1070 * automatically.
1071 */
1072 const char* requiredPermission;
1073
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001074 /* reserved fields, must be zero */
Aravind Akellab20f1a32014-04-07 22:46:01 +00001075 void* reserved[4];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001076};
1077
1078
Mathias Agopiana4557722012-11-28 17:21:55 -08001079/*
1080 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
1081 * and is present for backward binary and source compatibility.
1082 * (see documentation of the hooks in struct sensors_poll_device_1 below)
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001083 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001084struct sensors_poll_device_t {
1085 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001086 int (*activate)(struct sensors_poll_device_t *dev,
1087 int handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001088 int (*setDelay)(struct sensors_poll_device_t *dev,
1089 int handle, int64_t ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001090 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001091 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001092};
1093
Mathias Agopiana4557722012-11-28 17:21:55 -08001094/*
1095 * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
1096 */
1097typedef struct sensors_poll_device_1 {
1098 union {
1099 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
1100 * and can be down-cast to it
1101 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001102 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -08001103
1104 struct {
1105 struct hw_device_t common;
1106
1107 /* Activate/de-activate one sensor.
1108 *
1109 * handle is the handle of the sensor to change.
1110 * enabled set to 1 to enable, or 0 to disable the sensor.
1111 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001112 * if enabled is set to 1, the sensor is activated even if
1113 * setDelay() wasn't called before. In this case, a default rate
1114 * should be used.
1115 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001116 * unless otherwise noted in the sensor types definitions, an
1117 * activated sensor never prevents the SoC to go into suspend
1118 * mode; that is, the HAL shall not hold a partial wake-lock on
1119 * behalf of applications.
1120 *
1121 * one-shot sensors de-activate themselves automatically upon
1122 * receiving an event and they must still accept to be deactivated
1123 * through a call to activate(..., ..., 0).
1124 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001125 * if "enabled" is 1 and the sensor is already activated, this
Mathias Agopiana4557722012-11-28 17:21:55 -08001126 * function is a no-op and succeeds.
1127 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001128 * if "enabled" is 0 and the sensor is already de-activated,
Mathias Agopiana4557722012-11-28 17:21:55 -08001129 * this function is a no-op and succeeds.
1130 *
1131 * return 0 on success, negative errno code otherwise
1132 */
1133 int (*activate)(struct sensors_poll_device_t *dev,
1134 int handle, int enabled);
1135
1136 /**
Mathias Agopian1144bea2013-01-29 15:52:10 -08001137 * Set the events's period in nanoseconds for a given sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -08001138 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001139 * What the period_ns parameter means depends on the specified
Mathias Agopiana4557722012-11-28 17:21:55 -08001140 * sensor's trigger mode:
1141 *
1142 * continuous: setDelay() sets the sampling rate.
1143 * on-change: setDelay() limits the delivery rate of events
1144 * one-shot: setDelay() is ignored. it has no effect.
1145 * special: see specific sensor type definitions
1146 *
1147 * For continuous and on-change sensors, if the requested value is
1148 * less than sensor_t::minDelay, then it's silently clamped to
1149 * sensor_t::minDelay unless sensor_t::minDelay is 0, in which
1150 * case it is clamped to >= 1ms.
1151 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001152 * setDelay will not be called when the sensor is in batching mode.
1153 * In this case, batch() will be called with the new period.
1154 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001155 * @return 0 if successful, < 0 on error
1156 */
1157 int (*setDelay)(struct sensors_poll_device_t *dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -08001158 int handle, int64_t period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -08001159
1160 /**
1161 * Returns an array of sensor data.
1162 * This function must block until events are available.
1163 *
1164 * return the number of events read on success, or -errno in case
1165 * of an error.
1166 *
1167 * The number of events returned in data must be less or equal
Etienne Le Grand28f04112013-03-27 18:59:10 -07001168 * to the "count" argument.
Mathias Agopiana4557722012-11-28 17:21:55 -08001169 *
1170 * This function shall never return 0 (no event).
1171 */
1172 int (*poll)(struct sensors_poll_device_t *dev,
1173 sensors_event_t* data, int count);
1174 };
1175 };
1176
Mathias Agopiana4557722012-11-28 17:21:55 -08001177
1178 /*
Mathias Agopian1144bea2013-01-29 15:52:10 -08001179 * Enables batch mode for the given sensor and sets the delay between events
Mathias Agopiana4557722012-11-28 17:21:55 -08001180 *
1181 * A timeout value of zero disables batch mode for the given sensor.
1182 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001183 * The period_ns parameter is equivalent to calling setDelay() -- this
1184 * function both enables or disables the batch mode AND sets the events's
1185 * period in nanosecond. See setDelay() above for a detailed explanation of
1186 * the period_ns parameter.
1187 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001188 * BATCH MODE:
1189 * -----------
1190 * In non-batch mode, all sensor events must be reported as soon as they
1191 * are detected. For example, an accelerometer activated at 50Hz will
1192 * trigger interrupts 50 times per second.
1193 * While in batch mode, sensor events do not need to be reported as soon
1194 * as they are detected. They can be temporarily stored in batches and
1195 * reported in batches, as long as no event is delayed by more than
1196 * "timeout" nanoseconds. That is, all events since the previous batch
1197 * are recorded and returned all at once. This allows to reduce the amount
1198 * of interrupts sent to the SoC, and allow the SoC to switch to a lower
1199 * power state (Idle) while the sensor is capturing and batching data.
Mathias Agopiana4557722012-11-28 17:21:55 -08001200 *
1201 * setDelay() is not affected and it behaves as usual.
1202 *
1203 * Each event has a timestamp associated with it, the timestamp
1204 * must be accurate and correspond to the time at which the event
1205 * physically happened.
1206 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001207 * Batching does not modify the behavior of poll(): batches from different
1208 * sensors can be interleaved and split. As usual, all events from the same
1209 * sensor are time-ordered.
1210 *
1211 * BEHAVIOUR OUTSIDE OF SUSPEND MODE:
1212 * ----------------------------------
1213 *
1214 * When the SoC is awake (not in suspend mode), events must be reported in
1215 * batches at least every "timeout". No event shall be dropped or lost.
Mathias Agopiana4557722012-11-28 17:21:55 -08001216 * If internal h/w FIFOs fill-up before the timeout, then events are
Etienne Le Grand28f04112013-03-27 18:59:10 -07001217 * reported at that point to ensure no event is lost.
Mathias Agopian1144bea2013-01-29 15:52:10 -08001218 *
1219 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001220 * NORMAL BEHAVIOR IN SUSPEND MODE:
1221 * ---------------------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001222 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001223 * By default, batch mode doesn't significantly change the interaction with
1224 * suspend mode. That is, sensors must continue to allow the SoC to
Mathias Agopiana4557722012-11-28 17:21:55 -08001225 * go into suspend mode and sensors must stay active to fill their
Etienne Le Grand28f04112013-03-27 18:59:10 -07001226 * internal FIFO. In this mode, when the FIFO fills up, it shall wrap
Mathias Agopiana4557722012-11-28 17:21:55 -08001227 * around (basically behave like a circular buffer, overwriting events).
1228 * As soon as the SoC comes out of suspend mode, a batch is produced with
1229 * as much as the recent history as possible, and batch operation
1230 * resumes as usual.
1231 *
1232 * The behavior described above allows applications to record the recent
1233 * history of a set of sensor while keeping the SoC into suspend. It
1234 * also allows the hardware to not have to rely on a wake-up interrupt line.
1235 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001236 * WAKE_UPON_FIFO_FULL BEHAVIOR IN SUSPEND MODE:
1237 * ----------------------------------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001238 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001239 * There are cases, however, where an application cannot afford to lose
1240 * any events, even when the device goes into suspend mode.
1241 * For a given rate, if a sensor has the capability to store at least 10
1242 * seconds worth of events in its FIFO and is able to wake up the Soc, it
1243 * can implement an optional secondary mode: the WAKE_UPON_FIFO_FULL mode.
1244 *
1245 * The caller will set the SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag to
1246 * activate this mode. If the sensor does not support this mode, batch()
1247 * will fail when the flag is set.
1248 *
1249 * When running with the WAKE_UPON_FIFO_FULL flag set, no events can be
1250 * lost. When the FIFO is getting full, the sensor must wake up the SoC from
1251 * suspend and return a batch before the FIFO fills-up.
1252 * Depending on the device, it might take a few miliseconds for the SoC to
1253 * entirely come out of suspend and start flushing the FIFO. Enough head
1254 * room must be allocated in the FIFO to allow the device to entirely come
1255 * out of suspend without the FIFO overflowing (no events shall be lost).
1256 *
1257 * Implementing the WAKE_UPON_FIFO_FULL mode is optional.
1258 * If the hardware cannot support this mode, or if the physical
Mathias Agopiana4557722012-11-28 17:21:55 -08001259 * FIFO is so small that the device would never be allowed to go into
Mathias Agopian1144bea2013-01-29 15:52:10 -08001260 * suspend for at least 10 seconds, then this function MUST fail when
1261 * the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is set, regardless of
1262 * the value of the timeout parameter.
Mathias Agopiana4557722012-11-28 17:21:55 -08001263 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001264 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001265 * DRY RUN:
1266 * --------
Mathias Agopiana4557722012-11-28 17:21:55 -08001267 *
1268 * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns
Mathias Agopian1144bea2013-01-29 15:52:10 -08001269 * without modifying the batch mode or the event period and has no side
1270 * effects, but returns errors as usual (as it would if this flag was
1271 * not set). This flag is used to check if batch mode is available for a
1272 * given configuration -- in particular for a given sensor at a given rate.
1273 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001274 *
1275 * Return values:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001276 * --------------
1277 *
1278 * Because sensors must be independent, the return value must not depend
1279 * on the state of the system (whether another sensor is on or not),
1280 * nor on whether the flag SENSORS_BATCH_DRY_RUN is set (in other words,
1281 * if a batch call with SENSORS_BATCH_DRY_RUN is successful,
1282 * the same call without SENSORS_BATCH_DRY_RUN must succeed as well).
Mathias Agopiana4557722012-11-28 17:21:55 -08001283 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001284 * When timeout is not 0:
1285 * If successful, 0 is returned.
1286 * If the specified sensor doesn't support batch mode, return -EINVAL.
1287 * If the specified sensor's trigger-mode is one-shot, return -EINVAL.
1288 * If WAKE_UPON_FIFO_FULL is specified and the specified sensor's internal
1289 * FIFO is too small to store at least 10 seconds worth of data at the
1290 * given rate, -EINVAL is returned. Note that as stated above, this has to
1291 * be determined at compile time, and not based on the state of the
1292 * system.
1293 * If some other constraints above cannot be satisfied, return -EINVAL.
Mathias Agopiana4557722012-11-28 17:21:55 -08001294 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001295 * Note: the timeout parameter, when > 0, has no impact on whether this
1296 * function succeeds or fails.
1297 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001298 * When timeout is 0:
1299 * The caller will never set the wake_upon_fifo_full flag.
1300 * The function must succeed, and batch mode must be deactivated.
1301 *
1302 * Independently of whether DRY_RUN is specified, When the call to batch()
1303 * fails, no state should be changed. In particular, a failed call to
1304 * batch() should not change the rate of the sensor. Example:
1305 * setDelay(..., 10ms)
1306 * batch(..., 20ms, ...) fails
1307 * rate should stay 10ms.
Mathias Agopiana4557722012-11-28 17:21:55 -08001308 *
1309 *
1310 * IMPLEMENTATION NOTES:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001311 * ---------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001312 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001313 * Batch mode, if supported, should happen at the hardware level,
Mathias Agopiana4557722012-11-28 17:21:55 -08001314 * typically using hardware FIFOs. In particular, it SHALL NOT be
1315 * implemented in the HAL, as this would be counter productive.
1316 * The goal here is to save significant amounts of power.
1317 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001318 * In some implementations, events from several sensors can share the
1319 * same physical FIFO. In that case, all events in the FIFO can be sent and
1320 * processed by the HAL as soon as one batch must be reported.
1321 * For example, if the following sensors are activated:
1322 * - accelerometer batched with timeout = 20s
1323 * - gyroscope batched with timeout = 5s
1324 * then the accelerometer batches can be reported at the same time the
1325 * gyroscope batches are reported (every 5 seconds)
1326 *
1327 * Batch mode can be enabled or disabled at any time, in particular
1328 * while the specified sensor is already enabled, and this shall not
Mathias Agopiana4557722012-11-28 17:21:55 -08001329 * result in the loss of events.
1330 *
Etienne Le Grandca858142013-02-26 19:17:20 -08001331 * COMPARATIVE IMPORTANCE OF BATCHING FOR DIFFERENT SENSORS:
1332 * ---------------------------------------------------------
1333 *
1334 * On platforms on which hardware fifo size is limited, the system designers
1335 * might have to choose how much fifo to reserve for each sensor. To help
Etienne Le Grand28f04112013-03-27 18:59:10 -07001336 * with this choice, here is a list of applications made possible when
Etienne Le Grandca858142013-02-26 19:17:20 -08001337 * batching is implemented on the different sensors.
1338 *
1339 * High value: Low power pedestrian dead reckoning
1340 * Target batching time: 20 seconds to 1 minute
1341 * Sensors to batch:
1342 * - Step detector
1343 * - Rotation vector or game rotation vector at 5Hz
Etienne Le Grand28f04112013-03-27 18:59:10 -07001344 * Gives us step and heading while letting the SoC go to Suspend.
Etienne Le Grandca858142013-02-26 19:17:20 -08001345 *
1346 * High value: Medium power activity/gesture recognition
1347 * Target batching time: 3 seconds
1348 * Sensors to batch: accelerometer between 20Hz and 50Hz
1349 * Allows recognizing arbitrary activities and gestures without having
Etienne Le Grand28f04112013-03-27 18:59:10 -07001350 * to keep the SoC fully awake while the data is collected.
Etienne Le Grandca858142013-02-26 19:17:20 -08001351 *
1352 * Medium-high value: Interrupt load reduction
1353 * Target batching time: < 1 second
1354 * Sensors to batch: any high frequency sensor.
1355 * If the gyroscope is set at 800Hz, even batching just 10 gyro events can
1356 * reduce the number of interrupts from 800/second to 80/second.
1357 *
1358 * Medium value: Continuous low frequency data collection
1359 * Target batching time: > 1 minute
1360 * Sensors to batch: barometer, humidity sensor, other low frequency
1361 * sensors.
1362 * Allows creating monitoring applications at low power.
1363 *
1364 * Medium value: Continuous full-sensors collection
1365 * Target batching time: > 1 minute
1366 * Sensors to batch: all, at high frequencies
Etienne Le Grand28f04112013-03-27 18:59:10 -07001367 * Allows full collection of sensor data while leaving the SoC in
Etienne Le Grandca858142013-02-26 19:17:20 -08001368 * suspend mode. Only to consider if fifo space is not an issue.
Etienne Le Grand28f04112013-03-27 18:59:10 -07001369 *
1370 * In each of the cases above, if WAKE_UPON_FIFO_FULL is implemented, the
1371 * applications might decide to let the SoC go to suspend, allowing for even
1372 * more power savings.
Mathias Agopiana4557722012-11-28 17:21:55 -08001373 */
1374 int (*batch)(struct sensors_poll_device_1* dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -08001375 int handle, int flags, int64_t period_ns, int64_t timeout);
Mathias Agopiana4557722012-11-28 17:21:55 -08001376
Mathias Agopian16671c52013-07-24 21:07:40 -07001377 /*
1378 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
1379 * to the end of the "batch mode" FIFO for the specified sensor and flushes
1380 * the FIFO; those events are delivered as usual (i.e.: as if the batch
1381 * timeout had expired) and removed from the FIFO.
1382 *
1383 * See the META_DATA_FLUSH_COMPLETE section for details about the
1384 * META_DATA_FLUSH_COMPLETE event.
1385 *
1386 * The flush happens asynchronously (i.e.: this function must return
1387 * immediately).
1388 *
1389 * If the implementation uses a single FIFO for several sensors, that
1390 * FIFO is flushed and the META_DATA_FLUSH_COMPLETE event is added only
1391 * for the specified sensor.
1392 *
1393 * If the specified sensor wasn't in batch mode, flush succeeds and
1394 * promptly sends a META_DATA_FLUSH_COMPLETE event for that sensor.
1395 *
1396 * If the FIFO was empty at the time of the call, flush returns
1397 * 0 (success) and promptly sends a META_DATA_FLUSH_COMPLETE event
1398 * for that sensor.
1399 *
1400 * If the specified sensor wasn't enabled, flush returns -EINVAL.
1401 *
1402 * return 0 on success, negative errno code otherwise.
1403 */
1404 int (*flush)(struct sensors_poll_device_1* dev, int handle);
1405
Mathias Agopiana4557722012-11-28 17:21:55 -08001406 void (*reserved_procs[8])(void);
1407
1408} sensors_poll_device_1_t;
1409
1410
1411
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001412/** convenience API for opening and closing a device */
1413
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001414static inline int sensors_open(const struct hw_module_t* module,
1415 struct sensors_poll_device_t** device) {
1416 return module->methods->open(module,
1417 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1418}
1419
1420static inline int sensors_close(struct sensors_poll_device_t* device) {
1421 return device->common.close(&device->common);
1422}
1423
Mathias Agopiana4557722012-11-28 17:21:55 -08001424static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001425 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001426 return module->methods->open(module,
1427 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1428}
1429
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001430static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001431 return device->common.close(&device->common);
1432}
1433
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001434__END_DECLS
1435
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001436#endif // ANDROID_SENSORS_INTERFACE_H