blob: 418c348042641c1418eb951498a957ca8cf4b04c [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
807 * event. The event should be generated no faster than every period_ns passed
808 * to setDelay() or to batch(). See the definition of the on-change trigger
809 * mode for more information.
810 *
Aravind Akellab20f1a32014-04-07 22:46:01 +0000811 * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
812 */
813#define SENSOR_TYPE_HEART_RATE (21)
814#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
Mathias Agopiana4557722012-11-28 17:21:55 -0800815
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800816/**
817 * Values returned by the accelerometer in various locations in the universe.
818 * all values are in SI units (m/s^2)
819 */
820#define GRAVITY_SUN (275.0f)
821#define GRAVITY_EARTH (9.80665f)
822
823/** Maximum magnetic field on Earth's surface */
824#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
825
826/** Minimum magnetic field on Earth's surface */
827#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
828
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800829/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700830 * Possible values of the status field of sensor events.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800831 */
Etienne Le Grand7b361582014-05-16 11:08:28 -0700832#define SENSOR_STATUS_NO_CONTACT -1
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800833#define SENSOR_STATUS_UNRELIABLE 0
834#define SENSOR_STATUS_ACCURACY_LOW 1
835#define SENSOR_STATUS_ACCURACY_MEDIUM 2
836#define SENSOR_STATUS_ACCURACY_HIGH 3
837
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800838/**
839 * sensor event data
840 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800841typedef struct {
842 union {
843 float v[3];
844 struct {
845 float x;
846 float y;
847 float z;
848 };
849 struct {
850 float azimuth;
851 float pitch;
852 float roll;
853 };
854 };
855 int8_t status;
856 uint8_t reserved[3];
857} sensors_vec_t;
858
859/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800860 * uncalibrated gyroscope and magnetometer event data
861 */
862typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700863 union {
864 float uncalib[3];
865 struct {
866 float x_uncalib;
867 float y_uncalib;
868 float z_uncalib;
869 };
870 };
871 union {
872 float bias[3];
873 struct {
874 float x_bias;
875 float y_bias;
876 float z_bias;
877 };
878 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800879} uncalibrated_event_t;
880
Mathias Agopian16671c52013-07-24 21:07:40 -0700881typedef struct meta_data_event {
882 int32_t what;
883 int32_t sensor;
884} meta_data_event_t;
885
Etienne Le Grandca858142013-02-26 19:17:20 -0800886/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700887 * Heart rate event data
888 */
889typedef struct {
890 // Heart rate in beats per minute.
891 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
892 float bpm;
893 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
894 int8_t status;
895} heart_rate_event_t;
896
897/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800898 * Union of the various types of sensor data
899 * that can be returned.
900 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700901typedef struct sensors_event_t {
902 /* must be sizeof(struct sensors_event_t) */
903 int32_t version;
904
905 /* sensor identifier */
906 int32_t sensor;
907
908 /* sensor type */
909 int32_t type;
910
911 /* reserved */
912 int32_t reserved0;
913
914 /* time is in nanosecond */
915 int64_t timestamp;
916
917 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700918 union {
919 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700920
Mathias Agopian27e16682013-07-08 14:00:54 -0700921 /* acceleration values are in meter per second per second (m/s^2) */
922 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700923
Mathias Agopian27e16682013-07-08 14:00:54 -0700924 /* magnetic vector values are in micro-Tesla (uT) */
925 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700926
Mathias Agopian27e16682013-07-08 14:00:54 -0700927 /* orientation values are in degrees */
928 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700929
Mathias Agopian27e16682013-07-08 14:00:54 -0700930 /* gyroscope values are in rad/s */
931 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700932
Mathias Agopian27e16682013-07-08 14:00:54 -0700933 /* temperature is in degrees centigrade (Celsius) */
934 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700935
Mathias Agopian27e16682013-07-08 14:00:54 -0700936 /* distance in centimeters */
937 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700938
Mathias Agopian27e16682013-07-08 14:00:54 -0700939 /* light in SI lux units */
940 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700941
Mathias Agopian27e16682013-07-08 14:00:54 -0700942 /* pressure in hectopascal (hPa) */
943 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100944
Mathias Agopian27e16682013-07-08 14:00:54 -0700945 /* relative humidity in percent */
946 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800947
Mathias Agopian27e16682013-07-08 14:00:54 -0700948 /* uncalibrated gyroscope values are in rad/s */
949 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800950
Mathias Agopian27e16682013-07-08 14:00:54 -0700951 /* uncalibrated magnetometer values are in micro-Teslas */
952 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700953
Etienne Le Grand7b361582014-05-16 11:08:28 -0700954 /* heart rate data containing value in bpm and status */
955 heart_rate_event_t heart_rate;
Aravind Akellab20f1a32014-04-07 22:46:01 +0000956
Mathias Agopian16671c52013-07-24 21:07:40 -0700957 /* this is a special event. see SENSOR_TYPE_META_DATA above.
958 * sensors_meta_data_event_t events are all reported with a type of
959 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
960 */
961 meta_data_event_t meta_data;
Mathias Agopian27e16682013-07-08 14:00:54 -0700962 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800963
Mathias Agopian27e16682013-07-08 14:00:54 -0700964 union {
965 uint64_t data[8];
966
967 /* step-counter */
968 uint64_t step_counter;
969 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700970 };
Mathias Agopian27e16682013-07-08 14:00:54 -0700971 uint32_t reserved1[4];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700972} sensors_event_t;
973
974
Mathias Agopian16671c52013-07-24 21:07:40 -0700975/* see SENSOR_TYPE_META_DATA */
976typedef sensors_event_t sensors_meta_data_event_t;
977
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700978
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800979struct sensor_t;
980
981/**
982 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
983 * and the fields of this data structure must begin with hw_module_t
984 * followed by module specific information.
985 */
986struct sensors_module_t {
987 struct hw_module_t common;
988
989 /**
990 * Enumerate all available sensors. The list is returned in "list".
991 * @return number of sensors in the list
992 */
993 int (*get_sensors_list)(struct sensors_module_t* module,
994 struct sensor_t const** list);
995};
996
997struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800998
999 /* Name of this sensor.
1000 * All sensors of the same "type" must have a different "name".
1001 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001002 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -08001003
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001004 /* vendor of the hardware part */
1005 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -08001006
Mathias Agopiane9eaf372011-11-07 21:32:34 -08001007 /* version of the hardware part + driver. The value of this field
1008 * must increase when the driver is updated in a way that changes the
1009 * output of this sensor. This is important for fused sensors when the
1010 * fusion algorithm is updated.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001011 */
1012 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -08001013
1014 /* handle that identifies this sensors. This handle is used to reference
1015 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001016 */
1017 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -08001018
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001019 /* this sensor's type. */
1020 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -08001021
1022 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001023 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -08001024
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001025 /* smallest difference between two values reported by this sensor */
1026 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -08001027
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001028 /* rough estimate of this sensor's power consumption in mA */
1029 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -08001030
1031 /* this value depends on the trigger mode:
1032 *
1033 * continuous: minimum sample period allowed in microseconds
1034 * on-change : 0
1035 * one-shot :-1
1036 * special : 0, unless otherwise noted
1037 */
Mathias Agopian1511e202010-07-29 15:33:22 -07001038 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -08001039
Mathias Agopian16671c52013-07-24 21:07:40 -07001040 /* number of events reserved for this sensor in the batch mode FIFO.
1041 * If there is a dedicated FIFO for this sensor, then this is the
1042 * size of this FIFO. If the FIFO is shared with other sensors,
1043 * this is the size reserved for that sensor and it can be zero.
1044 */
1045 uint32_t fifoReservedEventCount;
1046
1047 /* maximum number of events of this sensor that could be batched.
1048 * This is especially relevant when the FIFO is shared between
1049 * several sensors; this value is then set to the size of that FIFO.
1050 */
1051 uint32_t fifoMaxEventCount;
1052
Aravind Akellab20f1a32014-04-07 22:46:01 +00001053 /* type of this sensor as a string. Set to corresponding
1054 * SENSOR_STRING_TYPE_*.
1055 * When defining an OEM specific sensor or sensor manufacturer specific
1056 * sensor, use your reserve domain name as a prefix.
1057 * ex: com.google.glass.onheaddetector
1058 * For sensors of known type, the android framework might overwrite this
1059 * string automatically.
1060 */
1061 const char* stringType;
1062
1063 /* permission required to see this sensor, register to it and receive data.
1064 * Set to "" if no permission is required. Some sensor types like the
1065 * heart rate monitor have a mandatory require_permission.
1066 * For sensors that always require a specific permission, like the heart
1067 * rate monitor, the android framework might overwrite this string
1068 * automatically.
1069 */
1070 const char* requiredPermission;
1071
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001072 /* reserved fields, must be zero */
Aravind Akellab20f1a32014-04-07 22:46:01 +00001073 void* reserved[4];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001074};
1075
1076
Mathias Agopiana4557722012-11-28 17:21:55 -08001077/*
1078 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
1079 * and is present for backward binary and source compatibility.
1080 * (see documentation of the hooks in struct sensors_poll_device_1 below)
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001081 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001082struct sensors_poll_device_t {
1083 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001084 int (*activate)(struct sensors_poll_device_t *dev,
1085 int handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001086 int (*setDelay)(struct sensors_poll_device_t *dev,
1087 int handle, int64_t ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001088 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001089 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001090};
1091
Mathias Agopiana4557722012-11-28 17:21:55 -08001092/*
1093 * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
1094 */
1095typedef struct sensors_poll_device_1 {
1096 union {
1097 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
1098 * and can be down-cast to it
1099 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001100 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -08001101
1102 struct {
1103 struct hw_device_t common;
1104
1105 /* Activate/de-activate one sensor.
1106 *
1107 * handle is the handle of the sensor to change.
1108 * enabled set to 1 to enable, or 0 to disable the sensor.
1109 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001110 * if enabled is set to 1, the sensor is activated even if
1111 * setDelay() wasn't called before. In this case, a default rate
1112 * should be used.
1113 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001114 * unless otherwise noted in the sensor types definitions, an
1115 * activated sensor never prevents the SoC to go into suspend
1116 * mode; that is, the HAL shall not hold a partial wake-lock on
1117 * behalf of applications.
1118 *
1119 * one-shot sensors de-activate themselves automatically upon
1120 * receiving an event and they must still accept to be deactivated
1121 * through a call to activate(..., ..., 0).
1122 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001123 * if "enabled" is 1 and the sensor is already activated, this
Mathias Agopiana4557722012-11-28 17:21:55 -08001124 * function is a no-op and succeeds.
1125 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001126 * if "enabled" is 0 and the sensor is already de-activated,
Mathias Agopiana4557722012-11-28 17:21:55 -08001127 * this function is a no-op and succeeds.
1128 *
1129 * return 0 on success, negative errno code otherwise
1130 */
1131 int (*activate)(struct sensors_poll_device_t *dev,
1132 int handle, int enabled);
1133
1134 /**
Mathias Agopian1144bea2013-01-29 15:52:10 -08001135 * Set the events's period in nanoseconds for a given sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -08001136 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001137 * What the period_ns parameter means depends on the specified
Mathias Agopiana4557722012-11-28 17:21:55 -08001138 * sensor's trigger mode:
1139 *
1140 * continuous: setDelay() sets the sampling rate.
1141 * on-change: setDelay() limits the delivery rate of events
1142 * one-shot: setDelay() is ignored. it has no effect.
1143 * special: see specific sensor type definitions
1144 *
1145 * For continuous and on-change sensors, if the requested value is
1146 * less than sensor_t::minDelay, then it's silently clamped to
1147 * sensor_t::minDelay unless sensor_t::minDelay is 0, in which
1148 * case it is clamped to >= 1ms.
1149 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001150 * setDelay will not be called when the sensor is in batching mode.
1151 * In this case, batch() will be called with the new period.
1152 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001153 * @return 0 if successful, < 0 on error
1154 */
1155 int (*setDelay)(struct sensors_poll_device_t *dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -08001156 int handle, int64_t period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -08001157
1158 /**
1159 * Returns an array of sensor data.
1160 * This function must block until events are available.
1161 *
1162 * return the number of events read on success, or -errno in case
1163 * of an error.
1164 *
1165 * The number of events returned in data must be less or equal
Etienne Le Grand28f04112013-03-27 18:59:10 -07001166 * to the "count" argument.
Mathias Agopiana4557722012-11-28 17:21:55 -08001167 *
1168 * This function shall never return 0 (no event).
1169 */
1170 int (*poll)(struct sensors_poll_device_t *dev,
1171 sensors_event_t* data, int count);
1172 };
1173 };
1174
Mathias Agopiana4557722012-11-28 17:21:55 -08001175
1176 /*
Mathias Agopian1144bea2013-01-29 15:52:10 -08001177 * Enables batch mode for the given sensor and sets the delay between events
Mathias Agopiana4557722012-11-28 17:21:55 -08001178 *
1179 * A timeout value of zero disables batch mode for the given sensor.
1180 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001181 * The period_ns parameter is equivalent to calling setDelay() -- this
1182 * function both enables or disables the batch mode AND sets the events's
1183 * period in nanosecond. See setDelay() above for a detailed explanation of
1184 * the period_ns parameter.
1185 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001186 * BATCH MODE:
1187 * -----------
1188 * In non-batch mode, all sensor events must be reported as soon as they
1189 * are detected. For example, an accelerometer activated at 50Hz will
1190 * trigger interrupts 50 times per second.
1191 * While in batch mode, sensor events do not need to be reported as soon
1192 * as they are detected. They can be temporarily stored in batches and
1193 * reported in batches, as long as no event is delayed by more than
1194 * "timeout" nanoseconds. That is, all events since the previous batch
1195 * are recorded and returned all at once. This allows to reduce the amount
1196 * of interrupts sent to the SoC, and allow the SoC to switch to a lower
1197 * power state (Idle) while the sensor is capturing and batching data.
Mathias Agopiana4557722012-11-28 17:21:55 -08001198 *
1199 * setDelay() is not affected and it behaves as usual.
1200 *
1201 * Each event has a timestamp associated with it, the timestamp
1202 * must be accurate and correspond to the time at which the event
1203 * physically happened.
1204 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001205 * Batching does not modify the behavior of poll(): batches from different
1206 * sensors can be interleaved and split. As usual, all events from the same
1207 * sensor are time-ordered.
1208 *
1209 * BEHAVIOUR OUTSIDE OF SUSPEND MODE:
1210 * ----------------------------------
1211 *
1212 * When the SoC is awake (not in suspend mode), events must be reported in
1213 * batches at least every "timeout". No event shall be dropped or lost.
Mathias Agopiana4557722012-11-28 17:21:55 -08001214 * If internal h/w FIFOs fill-up before the timeout, then events are
Etienne Le Grand28f04112013-03-27 18:59:10 -07001215 * reported at that point to ensure no event is lost.
Mathias Agopian1144bea2013-01-29 15:52:10 -08001216 *
1217 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001218 * NORMAL BEHAVIOR IN SUSPEND MODE:
1219 * ---------------------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001220 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001221 * By default, batch mode doesn't significantly change the interaction with
1222 * suspend mode. That is, sensors must continue to allow the SoC to
Mathias Agopiana4557722012-11-28 17:21:55 -08001223 * go into suspend mode and sensors must stay active to fill their
Etienne Le Grand28f04112013-03-27 18:59:10 -07001224 * internal FIFO. In this mode, when the FIFO fills up, it shall wrap
Mathias Agopiana4557722012-11-28 17:21:55 -08001225 * around (basically behave like a circular buffer, overwriting events).
1226 * As soon as the SoC comes out of suspend mode, a batch is produced with
1227 * as much as the recent history as possible, and batch operation
1228 * resumes as usual.
1229 *
1230 * The behavior described above allows applications to record the recent
1231 * history of a set of sensor while keeping the SoC into suspend. It
1232 * also allows the hardware to not have to rely on a wake-up interrupt line.
1233 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001234 * WAKE_UPON_FIFO_FULL BEHAVIOR IN SUSPEND MODE:
1235 * ----------------------------------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001236 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001237 * There are cases, however, where an application cannot afford to lose
1238 * any events, even when the device goes into suspend mode.
1239 * For a given rate, if a sensor has the capability to store at least 10
1240 * seconds worth of events in its FIFO and is able to wake up the Soc, it
1241 * can implement an optional secondary mode: the WAKE_UPON_FIFO_FULL mode.
1242 *
1243 * The caller will set the SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag to
1244 * activate this mode. If the sensor does not support this mode, batch()
1245 * will fail when the flag is set.
1246 *
1247 * When running with the WAKE_UPON_FIFO_FULL flag set, no events can be
1248 * lost. When the FIFO is getting full, the sensor must wake up the SoC from
1249 * suspend and return a batch before the FIFO fills-up.
1250 * Depending on the device, it might take a few miliseconds for the SoC to
1251 * entirely come out of suspend and start flushing the FIFO. Enough head
1252 * room must be allocated in the FIFO to allow the device to entirely come
1253 * out of suspend without the FIFO overflowing (no events shall be lost).
1254 *
1255 * Implementing the WAKE_UPON_FIFO_FULL mode is optional.
1256 * If the hardware cannot support this mode, or if the physical
Mathias Agopiana4557722012-11-28 17:21:55 -08001257 * FIFO is so small that the device would never be allowed to go into
Mathias Agopian1144bea2013-01-29 15:52:10 -08001258 * suspend for at least 10 seconds, then this function MUST fail when
1259 * the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is set, regardless of
1260 * the value of the timeout parameter.
Mathias Agopiana4557722012-11-28 17:21:55 -08001261 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001262 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001263 * DRY RUN:
1264 * --------
Mathias Agopiana4557722012-11-28 17:21:55 -08001265 *
1266 * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns
Mathias Agopian1144bea2013-01-29 15:52:10 -08001267 * without modifying the batch mode or the event period and has no side
1268 * effects, but returns errors as usual (as it would if this flag was
1269 * not set). This flag is used to check if batch mode is available for a
1270 * given configuration -- in particular for a given sensor at a given rate.
1271 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001272 *
1273 * Return values:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001274 * --------------
1275 *
1276 * Because sensors must be independent, the return value must not depend
1277 * on the state of the system (whether another sensor is on or not),
1278 * nor on whether the flag SENSORS_BATCH_DRY_RUN is set (in other words,
1279 * if a batch call with SENSORS_BATCH_DRY_RUN is successful,
1280 * the same call without SENSORS_BATCH_DRY_RUN must succeed as well).
Mathias Agopiana4557722012-11-28 17:21:55 -08001281 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001282 * When timeout is not 0:
1283 * If successful, 0 is returned.
1284 * If the specified sensor doesn't support batch mode, return -EINVAL.
1285 * If the specified sensor's trigger-mode is one-shot, return -EINVAL.
1286 * If WAKE_UPON_FIFO_FULL is specified and the specified sensor's internal
1287 * FIFO is too small to store at least 10 seconds worth of data at the
1288 * given rate, -EINVAL is returned. Note that as stated above, this has to
1289 * be determined at compile time, and not based on the state of the
1290 * system.
1291 * If some other constraints above cannot be satisfied, return -EINVAL.
Mathias Agopiana4557722012-11-28 17:21:55 -08001292 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001293 * Note: the timeout parameter, when > 0, has no impact on whether this
1294 * function succeeds or fails.
1295 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001296 * When timeout is 0:
1297 * The caller will never set the wake_upon_fifo_full flag.
1298 * The function must succeed, and batch mode must be deactivated.
1299 *
1300 * Independently of whether DRY_RUN is specified, When the call to batch()
1301 * fails, no state should be changed. In particular, a failed call to
1302 * batch() should not change the rate of the sensor. Example:
1303 * setDelay(..., 10ms)
1304 * batch(..., 20ms, ...) fails
1305 * rate should stay 10ms.
Mathias Agopiana4557722012-11-28 17:21:55 -08001306 *
1307 *
1308 * IMPLEMENTATION NOTES:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001309 * ---------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001310 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001311 * Batch mode, if supported, should happen at the hardware level,
Mathias Agopiana4557722012-11-28 17:21:55 -08001312 * typically using hardware FIFOs. In particular, it SHALL NOT be
1313 * implemented in the HAL, as this would be counter productive.
1314 * The goal here is to save significant amounts of power.
1315 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001316 * In some implementations, events from several sensors can share the
1317 * same physical FIFO. In that case, all events in the FIFO can be sent and
1318 * processed by the HAL as soon as one batch must be reported.
1319 * For example, if the following sensors are activated:
1320 * - accelerometer batched with timeout = 20s
1321 * - gyroscope batched with timeout = 5s
1322 * then the accelerometer batches can be reported at the same time the
1323 * gyroscope batches are reported (every 5 seconds)
1324 *
1325 * Batch mode can be enabled or disabled at any time, in particular
1326 * while the specified sensor is already enabled, and this shall not
Mathias Agopiana4557722012-11-28 17:21:55 -08001327 * result in the loss of events.
1328 *
Etienne Le Grandca858142013-02-26 19:17:20 -08001329 * COMPARATIVE IMPORTANCE OF BATCHING FOR DIFFERENT SENSORS:
1330 * ---------------------------------------------------------
1331 *
1332 * On platforms on which hardware fifo size is limited, the system designers
1333 * might have to choose how much fifo to reserve for each sensor. To help
Etienne Le Grand28f04112013-03-27 18:59:10 -07001334 * with this choice, here is a list of applications made possible when
Etienne Le Grandca858142013-02-26 19:17:20 -08001335 * batching is implemented on the different sensors.
1336 *
1337 * High value: Low power pedestrian dead reckoning
1338 * Target batching time: 20 seconds to 1 minute
1339 * Sensors to batch:
1340 * - Step detector
1341 * - Rotation vector or game rotation vector at 5Hz
Etienne Le Grand28f04112013-03-27 18:59:10 -07001342 * Gives us step and heading while letting the SoC go to Suspend.
Etienne Le Grandca858142013-02-26 19:17:20 -08001343 *
1344 * High value: Medium power activity/gesture recognition
1345 * Target batching time: 3 seconds
1346 * Sensors to batch: accelerometer between 20Hz and 50Hz
1347 * Allows recognizing arbitrary activities and gestures without having
Etienne Le Grand28f04112013-03-27 18:59:10 -07001348 * to keep the SoC fully awake while the data is collected.
Etienne Le Grandca858142013-02-26 19:17:20 -08001349 *
1350 * Medium-high value: Interrupt load reduction
1351 * Target batching time: < 1 second
1352 * Sensors to batch: any high frequency sensor.
1353 * If the gyroscope is set at 800Hz, even batching just 10 gyro events can
1354 * reduce the number of interrupts from 800/second to 80/second.
1355 *
1356 * Medium value: Continuous low frequency data collection
1357 * Target batching time: > 1 minute
1358 * Sensors to batch: barometer, humidity sensor, other low frequency
1359 * sensors.
1360 * Allows creating monitoring applications at low power.
1361 *
1362 * Medium value: Continuous full-sensors collection
1363 * Target batching time: > 1 minute
1364 * Sensors to batch: all, at high frequencies
Etienne Le Grand28f04112013-03-27 18:59:10 -07001365 * Allows full collection of sensor data while leaving the SoC in
Etienne Le Grandca858142013-02-26 19:17:20 -08001366 * suspend mode. Only to consider if fifo space is not an issue.
Etienne Le Grand28f04112013-03-27 18:59:10 -07001367 *
1368 * In each of the cases above, if WAKE_UPON_FIFO_FULL is implemented, the
1369 * applications might decide to let the SoC go to suspend, allowing for even
1370 * more power savings.
Mathias Agopiana4557722012-11-28 17:21:55 -08001371 */
1372 int (*batch)(struct sensors_poll_device_1* dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -08001373 int handle, int flags, int64_t period_ns, int64_t timeout);
Mathias Agopiana4557722012-11-28 17:21:55 -08001374
Mathias Agopian16671c52013-07-24 21:07:40 -07001375 /*
1376 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
1377 * to the end of the "batch mode" FIFO for the specified sensor and flushes
1378 * the FIFO; those events are delivered as usual (i.e.: as if the batch
1379 * timeout had expired) and removed from the FIFO.
1380 *
1381 * See the META_DATA_FLUSH_COMPLETE section for details about the
1382 * META_DATA_FLUSH_COMPLETE event.
1383 *
1384 * The flush happens asynchronously (i.e.: this function must return
1385 * immediately).
1386 *
1387 * If the implementation uses a single FIFO for several sensors, that
1388 * FIFO is flushed and the META_DATA_FLUSH_COMPLETE event is added only
1389 * for the specified sensor.
1390 *
1391 * If the specified sensor wasn't in batch mode, flush succeeds and
1392 * promptly sends a META_DATA_FLUSH_COMPLETE event for that sensor.
1393 *
1394 * If the FIFO was empty at the time of the call, flush returns
1395 * 0 (success) and promptly sends a META_DATA_FLUSH_COMPLETE event
1396 * for that sensor.
1397 *
1398 * If the specified sensor wasn't enabled, flush returns -EINVAL.
1399 *
1400 * return 0 on success, negative errno code otherwise.
1401 */
1402 int (*flush)(struct sensors_poll_device_1* dev, int handle);
1403
Mathias Agopiana4557722012-11-28 17:21:55 -08001404 void (*reserved_procs[8])(void);
1405
1406} sensors_poll_device_1_t;
1407
1408
1409
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001410/** convenience API for opening and closing a device */
1411
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001412static inline int sensors_open(const struct hw_module_t* module,
1413 struct sensors_poll_device_t** device) {
1414 return module->methods->open(module,
1415 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1416}
1417
1418static inline int sensors_close(struct sensors_poll_device_t* device) {
1419 return device->common.close(&device->common);
1420}
1421
Mathias Agopiana4557722012-11-28 17:21:55 -08001422static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001423 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001424 return module->methods->open(module,
1425 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1426}
1427
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001428static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001429 return device->common.close(&device->common);
1430}
1431
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001432__END_DECLS
1433
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001434#endif // ANDROID_SENSORS_INTERFACE_H