blob: ec68b2b2c41c834eea7ed410717772af1a94e22a [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 Akella477fbd52014-04-07 22:46:01 +000036#define SENSORS_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION_2(1, 2, SENSORS_HEADER_VERSION)
Aravind Akella6242f322014-02-28 18:46:19 -080037#define SENSORS_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION_2(1, 3, SENSORS_HEADER_VERSION)
Mathias Agopian56f66cc2012-11-08 15:57:38 -080038
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080039/**
Clay Murphy8db1fb42013-12-19 09:58:28 -080040 * Please see the Sensors section of source.android.com for an
41 * introduction to and detailed descriptions of Android sensor types:
42 * http://source.android.com/devices/sensors/index.html
43 */
44
45/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080046 * The id of this module
47 */
48#define SENSORS_HARDWARE_MODULE_ID "sensors"
49
50/**
51 * Name of the sensors device to open
52 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -070053#define SENSORS_HARDWARE_POLL "poll"
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080054
55/**
56 * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
57 * A Handle identifies a given sensors. The handle is used to activate
58 * and/or deactivate sensors.
59 * In this version of the API there can only be 256 handles.
60 */
61#define SENSORS_HANDLE_BASE 0
62#define SENSORS_HANDLE_BITS 8
63#define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS)
64
65
Mathias Agopiana4557722012-11-28 17:21:55 -080066/*
Aravind Akella6242f322014-02-28 18:46:19 -080067 * **** Deprecated *****
Mathias Agopiana4557722012-11-28 17:21:55 -080068 * flags for (*batch)()
69 * Availability: SENSORS_DEVICE_API_VERSION_1_0
Aravind Akella6242f322014-02-28 18:46:19 -080070 * see (*batch)() documentation for details.
71 * Deprecated as of SENSORS_DEVICE_API_VERSION_1_3.
72 * WAKE_UP_* sensors replace WAKE_UPON_FIFO_FULL concept.
Mathias Agopiana4557722012-11-28 17:21:55 -080073 */
74enum {
75 SENSORS_BATCH_DRY_RUN = 0x00000001,
76 SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
77};
78
Mathias Agopian16671c52013-07-24 21:07:40 -070079/*
80 * what field for meta_data_event_t
81 */
82enum {
83 /* a previous flush operation has completed */
Mathias Agopianaf32a8d2013-08-06 20:33:38 -070084 META_DATA_FLUSH_COMPLETE = 1,
85 META_DATA_VERSION /* always last, leave auto-assigned */
Mathias Agopian16671c52013-07-24 21:07:40 -070086};
87
Mathias Agopiana4557722012-11-28 17:21:55 -080088/*
Aravind Akella477fbd52014-04-07 22:46:01 +000089 * The permission to use for body sensors (like heart rate monitors).
90 * See sensor types for more details on what sensors should require this
91 * permission.
92 */
93#define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS"
94
95/*
Aravind Akella6242f322014-02-28 18:46:19 -080096 * Availability: SENSORS_DEVICE_API_VERSION_1_3
97 * Sensor flags used in sensor_t.flags.
98 */
99enum {
100 /*
101 * Whether this sensor wakes up the AP from suspend mode when data is available.
102 */
Aravind Akellac841efd2014-06-03 19:21:35 -0700103 SENSOR_FLAG_WAKE_UP = 1U << 0,
104 /*
105 * Reporting modes for various sensors. Each sensor will have exactly one of these modes set.
106 * The least significant 2nd, 3rd and 4th bits are used to represent four possible reporting
107 * modes.
108 */
109 SENSOR_FLAG_CONTINUOUS_MODE = 0, // 0000
110 SENSOR_FLAG_ON_CHANGE_MODE = 0x2, // 0010
111 SENSOR_FLAG_ONE_SHOT_MODE = 0x4, // 0100
112 SENSOR_FLAG_SPECIAL_REPORTING_MODE = 0x6 // 0110
Aravind Akella6242f322014-02-28 18:46:19 -0800113};
114
115/*
Aravind Akellac841efd2014-06-03 19:21:35 -0700116 * Mask and shift for reporting mode sensor flags defined above.
117 */
118#define REPORTING_MODE_MASK (0xE)
119#define REPORTING_MODE_SHIFT (1)
120
121/*
Mathias Agopiana4557722012-11-28 17:21:55 -0800122 * Sensor type
123 *
124 * Each sensor has a type which defines what this sensor measures and how
Clay Murphy8db1fb42013-12-19 09:58:28 -0800125 * measures are reported. See the Base sensors and Composite sensors lists
126 * for complete descriptions:
127 * http://source.android.com/devices/sensors/base_triggers.html
128 * http://source.android.com/devices/sensors/composite_sensors.html
Mathias Agopian1599ec62013-08-19 14:34:47 -0700129 *
130 * Device manufacturers (OEMs) can define their own sensor types, for
131 * their private use by applications or services provided by them. Such
132 * sensor types are specific to an OEM and can't be exposed in the SDK.
133 * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE.
Aravind Akella477fbd52014-04-07 22:46:01 +0000134 *
135 * All sensors defined outside of the device private range must correspond to
136 * a type defined in this file, and must satisfy the characteristics listed in
137 * the description of the sensor type.
138 *
139 * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also
140 * has a stringType.
141 * - StringType of sensors inside of the device private range MUST be prefixed
142 * by the sensor provider's or OEM reverse domain name. In particular, they
143 * cannot use the "android.sensor" prefix.
144 * - StringType of sensors outside of the device private range MUST correspond
145 * to the one defined in this file (starting with "android.sensor").
146 * For example, accelerometers must have
147 * type=SENSOR_TYPE_ACCELEROMETER and
148 * stringType=SENSOR_STRING_TYPE_ACCELEROMETER
149 *
150 * When android introduces a new sensor type that can replace an OEM-defined
151 * sensor type, the OEM must use the official sensor type and stringType on
152 * versions of the HAL that support this new official sensor type.
153 *
154 * Example (made up): Suppose Google's Glass team wants to surface a sensor
155 * detecting that Glass is on a head.
156 * - Such a sensor is not officially supported in android KitKat
157 * - Glass devices launching on KitKat can implement a sensor with
158 * type = 0x10001 and stringType = "com.google.glass.onheaddetector"
159 * - In L android release, if android decides to define
160 * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR,
161 * those types should replace the Glass-team-specific types in all future
162 * launches.
163 * - When launching glass on the L release, Google should now use the official
164 * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType.
165 * - This way, all applications can now use this sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800166 */
167
168/*
Mathias Agopian1599ec62013-08-19 14:34:47 -0700169 * Base for device manufacturers private sensor types.
170 * These sensor types can't be exposed in the SDK.
171 */
172#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000
173
174/*
Mathias Agopian16671c52013-07-24 21:07:40 -0700175 * SENSOR_TYPE_META_DATA
Aravind Akellac841efd2014-06-03 19:21:35 -0700176 * reporting-mode: n/a
Mathias Agopian16671c52013-07-24 21:07:40 -0700177 * wake-up sensor: n/a
178 *
179 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
180 *
181 * SENSOR_TYPE_META_DATA is a special token used to populate the
182 * sensors_meta_data_event structure. It doesn't correspond to a physical
183 * sensor. sensors_meta_data_event are special, they exist only inside
184 * the HAL and are generated spontaneously, as opposed to be related to
185 * a physical sensor.
186 *
Mathias Agopianaf32a8d2013-08-06 20:33:38 -0700187 * sensors_meta_data_event_t.version must be META_DATA_VERSION
188 * sensors_meta_data_event_t.sensor must be 0
189 * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
190 * sensors_meta_data_event_t.reserved must be 0
191 * sensors_meta_data_event_t.timestamp must be 0
Mathias Agopian16671c52013-07-24 21:07:40 -0700192 *
193 * The payload is a meta_data_event_t, where:
194 * meta_data_event_t.what can take the following values:
195 *
196 * META_DATA_FLUSH_COMPLETE
197 * This event indicates that a previous (*flush)() call has completed for the sensor
198 * handle specified in meta_data_event_t.sensor.
199 * see (*flush)() for more details
200 *
201 * All other values for meta_data_event_t.what are reserved and
202 * must not be used.
203 *
204 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000205#define SENSOR_TYPE_META_DATA (0)
Mathias Agopian16671c52013-07-24 21:07:40 -0700206
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800207/*
208 * SENSOR_TYPE_ACCELEROMETER
Aravind Akellac841efd2014-06-03 19:21:35 -0700209 * reporting-mode: continuous
Mathias Agopiana4557722012-11-28 17:21:55 -0800210 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800211 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800212 * All values are in SI units (m/s^2) and measure the acceleration of the
213 * device minus the force of gravity.
214 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800215 */
216#define SENSOR_TYPE_ACCELEROMETER (1)
Aravind Akella477fbd52014-04-07 22:46:01 +0000217#define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800218
219/*
220 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akellac841efd2014-06-03 19:21:35 -0700221 * reporting-mode: continuous
Mathias Agopiana4557722012-11-28 17:21:55 -0800222 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800223 *
224 * All values are in micro-Tesla (uT) and measure the geomagnetic
225 * field in the X, Y and Z axis.
226 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800227 */
228#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
229#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akella477fbd52014-04-07 22:46:01 +0000230#define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800231
232/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800233 * SENSOR_TYPE_ORIENTATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700234 * reporting-mode: continuous
Mathias Agopiana4557722012-11-28 17:21:55 -0800235 * wake-up sensor: no
Clay Murphy8db1fb42013-12-19 09:58:28 -0800236 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800237 * All values are angles in degrees.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800238 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700239 * Orientation sensors return sensor events for all 3 axes at a constant
240 * rate defined by setDelay().
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800241 */
242#define SENSOR_TYPE_ORIENTATION (3)
Aravind Akella477fbd52014-04-07 22:46:01 +0000243#define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800244
245/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800246 * SENSOR_TYPE_GYROSCOPE
Aravind Akellac841efd2014-06-03 19:21:35 -0700247 * reporting-mode: continuous
Mathias Agopiana4557722012-11-28 17:21:55 -0800248 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800249 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700250 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800251 * around the X, Y and Z axis.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800252 */
253#define SENSOR_TYPE_GYROSCOPE (4)
Aravind Akella477fbd52014-04-07 22:46:01 +0000254#define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800255
256/*
257 * SENSOR_TYPE_LIGHT
Aravind Akellac841efd2014-06-03 19:21:35 -0700258 * reporting-mode: on-change
Mathias Agopiana4557722012-11-28 17:21:55 -0800259 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800260 *
261 * The light sensor value is returned in SI lux units.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800262 */
263#define SENSOR_TYPE_LIGHT (5)
Aravind Akella477fbd52014-04-07 22:46:01 +0000264#define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800265
266/*
267 * SENSOR_TYPE_PRESSURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700268 * reporting-mode: continuous
Mathias Agopiana4557722012-11-28 17:21:55 -0800269 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800270 *
271 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800272 */
273#define SENSOR_TYPE_PRESSURE (6)
Aravind Akella477fbd52014-04-07 22:46:01 +0000274#define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800275
276/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
277#define SENSOR_TYPE_TEMPERATURE (7)
Aravind Akella477fbd52014-04-07 22:46:01 +0000278#define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800279
280/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800281 * SENSOR_TYPE_PROXIMITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700282 * reporting-mode: on-change
Aravind Akella6242f322014-02-28 18:46:19 -0800283 * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
Mike Lockwooda2414312009-11-03 10:29:50 -0500284 *
Clay Murphy8db1fb42013-12-19 09:58:28 -0800285 * The value corresponds to the distance to the nearest object in centimeters.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800286 */
287#define SENSOR_TYPE_PROXIMITY (8)
Aravind Akella477fbd52014-04-07 22:46:01 +0000288#define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800289
290/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800291 * SENSOR_TYPE_GRAVITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700292 * reporting-mode: continuous
Mathias Agopiana4557722012-11-28 17:21:55 -0800293 * wake-up sensor: no
Mathias Agopian42b743c2010-11-22 15:55:32 -0800294 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800295 * A gravity output indicates the direction of and magnitude of gravity in
Clay Murphy8db1fb42013-12-19 09:58:28 -0800296 * the devices's coordinates.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800297 */
298#define SENSOR_TYPE_GRAVITY (9)
Aravind Akella477fbd52014-04-07 22:46:01 +0000299#define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800300
301/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800302 * SENSOR_TYPE_LINEAR_ACCELERATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700303 * reporting-mode: continuous
Mathias Agopiana4557722012-11-28 17:21:55 -0800304 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800305 *
306 * Indicates the linear acceleration of the device in device coordinates,
307 * not including gravity.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800308 */
309#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
Aravind Akella477fbd52014-04-07 22:46:01 +0000310#define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800311
312
313/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800314 * SENSOR_TYPE_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700315 * reporting-mode: continuous
Mathias Agopiana4557722012-11-28 17:21:55 -0800316 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800317 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700318 * The rotation vector symbolizes the orientation of the device relative to the
Clay Murphy8db1fb42013-12-19 09:58:28 -0800319 * East-North-Up coordinates frame.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800320 */
321#define SENSOR_TYPE_ROTATION_VECTOR (11)
Aravind Akella477fbd52014-04-07 22:46:01 +0000322#define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800323
324/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800325 * SENSOR_TYPE_RELATIVE_HUMIDITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700326 * reporting-mode: on-change
Mathias Agopiana4557722012-11-28 17:21:55 -0800327 * wake-up sensor: no
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100328 *
329 * A relative humidity sensor measures relative ambient air humidity and
330 * returns a value in percent.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800331 */
332#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
Aravind Akella477fbd52014-04-07 22:46:01 +0000333#define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800334
335/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800336 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700337 * reporting-mode: on-change
Mathias Agopiana4557722012-11-28 17:21:55 -0800338 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700339 *
340 * The ambient (room) temperature in degree Celsius.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800341 */
342#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
Aravind Akella477fbd52014-04-07 22:46:01 +0000343#define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800344
345/*
346 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700347 * reporting-mode: continuous
Mathias Agopiana4557722012-11-28 17:21:55 -0800348 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700349 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800350 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
351 * reported separately instead of being included in the measurement.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800352 */
353#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
Aravind Akella477fbd52014-04-07 22:46:01 +0000354#define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800355
356/*
357 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700358 * reporting-mode: continuous
Mathias Agopiana4557722012-11-28 17:21:55 -0800359 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800360 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800361 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
Clay Murphy8db1fb42013-12-19 09:58:28 -0800362 * field.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800363 */
364#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
Aravind Akella477fbd52014-04-07 22:46:01 +0000365#define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800366
367/*
368 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700369 * reporting-mode: continuous
Mathias Agopiana4557722012-11-28 17:21:55 -0800370 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800371 *
372 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800373 * around the X, Y and Z axis.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800374 */
375#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
Aravind Akella477fbd52014-04-07 22:46:01 +0000376#define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800377
Mathias Agopiana4557722012-11-28 17:21:55 -0800378/*
379 * SENSOR_TYPE_SIGNIFICANT_MOTION
Aravind Akellac841efd2014-06-03 19:21:35 -0700380 * reporting-mode: one-shot
Aravind Akella6242f322014-02-28 18:46:19 -0800381 * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
Mathias Agopiana4557722012-11-28 17:21:55 -0800382 *
383 * A sensor of this type triggers an event each time significant motion
384 * is detected and automatically disables itself.
385 * The only allowed value to return is 1.0.
Mathias Agopiana4557722012-11-28 17:21:55 -0800386 */
387
388#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
Aravind Akella477fbd52014-04-07 22:46:01 +0000389#define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
Mathias Agopiana4557722012-11-28 17:21:55 -0800390
391/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800392 * SENSOR_TYPE_STEP_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700393 * reporting-mode: special
Mathias Agopiana4557722012-11-28 17:21:55 -0800394 * wake-up sensor: no
395 *
396 * A sensor of this type triggers an event each time a step is taken
Clay Murphy8db1fb42013-12-19 09:58:28 -0800397 * by the user. The only allowed value to return is 1.0 and an event
398 * is generated for each step.
Mathias Agopiana4557722012-11-28 17:21:55 -0800399 */
400
Mathias Agopian2f276f52013-01-28 17:54:41 -0800401#define SENSOR_TYPE_STEP_DETECTOR (18)
Aravind Akella477fbd52014-04-07 22:46:01 +0000402#define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
Mathias Agopiana4557722012-11-28 17:21:55 -0800403
404
405/*
406 * SENSOR_TYPE_STEP_COUNTER
Aravind Akellac841efd2014-06-03 19:21:35 -0700407 * reporting-mode: on-change
Mathias Agopiana4557722012-11-28 17:21:55 -0800408 * wake-up sensor: no
409 *
410 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800411 * the last reboot while activated. The value is returned as a uint64_t and is
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700412 * reset to zero only on a system / android reboot.
Mathias Agopiana4557722012-11-28 17:21:55 -0800413 */
414
415#define SENSOR_TYPE_STEP_COUNTER (19)
Aravind Akella477fbd52014-04-07 22:46:01 +0000416#define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
Mathias Agopiana4557722012-11-28 17:21:55 -0800417
Etienne Le Grandca858142013-02-26 19:17:20 -0800418/*
419 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700420 * reporting-mode: continuous
Etienne Le Grandca858142013-02-26 19:17:20 -0800421 * wake-up sensor: no
422 *
423 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
424 * of using a gyroscope.
Etienne Le Grandca858142013-02-26 19:17:20 -0800425 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000426#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
427#define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
428
429/*
430 * SENSOR_TYPE_HEART_RATE
Aravind Akellac841efd2014-06-03 19:21:35 -0700431 * reporting-mode: on-change
Aravind Akella477fbd52014-04-07 22:46:01 +0000432 * wake-up sensor: no
433 *
Etienne Le Grand7b361582014-05-16 11:08:28 -0700434 * A sensor of this type returns the current heart rate.
435 * The events contain the current heart rate in beats per minute (BPM) and the
436 * status of the sensor during the measurement. See heart_rate_event_t for more
437 * details.
438 *
439 * Because this sensor is on-change, events must be generated when and only
440 * when heart_rate.bpm or heart_rate.status have changed since the last
441 * event. The event should be generated no faster than every period_ns passed
Aravind Akellac841efd2014-06-03 19:21:35 -0700442 * to setDelay() or to batch(). See the definition of the on-change reporting
Etienne Le Grand7b361582014-05-16 11:08:28 -0700443 * mode for more information.
444 *
Aravind Akella477fbd52014-04-07 22:46:01 +0000445 * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
446 */
447#define SENSOR_TYPE_HEART_RATE (21)
448#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
Mathias Agopiana4557722012-11-28 17:21:55 -0800449
Aravind Akella6242f322014-02-28 18:46:19 -0800450/*
451 * SENSOR_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR
452 * Same as proximity_sensor but does not wake up the AP from suspend mode.
453 * wake-up sensor: no
454 */
455#define SENSOR_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR (22)
456#define SENSOR_STRING_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR "android.sensor.non_wake_up_proximity_sensor"
457
458/*
459 * The sensors below are wake_up variants of the base sensor types defined
460 * above. When registered in batch mode, these sensors will wake up the AP when
Aravind Akellaf895c682014-04-30 11:46:09 -0700461 * their FIFOs are full or when the batch timeout expires. A separate FIFO has
462 * to be maintained for wake up sensors and non wake up sensors. The non wake-up
463 * sensors need to overwrite their FIFOs when they are full till the AP wakes up
464 * and the wake-up sensors will wake-up the AP when their FIFOs are full or when
465 * the batch timeout expires without losing events.
466 * Note: Sensors of type SENSOR_TYPE_PROXIMITY are also wake up sensors and
467 * should be treated as such. Wake-up one-shot sensors like SIGNIFICANT_MOTION
468 * cannot be batched, hence the text about batch above doesn't apply to them.
Aravind Akella6242f322014-02-28 18:46:19 -0800469 *
470 * Define these sensors only if:
471 * 1) batching is supported.
472 * 2) wake-up and non wake-up variants of each sensor can be activated at
473 * different rates.
474 *
475 * wake-up sensor: yes
476 * Set SENSOR_FLAG_WAKE_UP flag for all these sensors.
477 */
478#define SENSOR_TYPE_WAKE_UP_ACCELEROMETER (23)
479#define SENSOR_STRING_TYPE_WAKE_UP_ACCELEROMETER "android.sensor.wake_up_accelerometer"
480
481#define SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD (24)
482#define SENSOR_STRING_TYPE_WAKE_UP_MAGNETIC_FIELD "android.sensor.wake_up_magnetic_field"
483
484#define SENSOR_TYPE_WAKE_UP_ORIENTATION (25)
485#define SENSOR_STRING_TYPE_WAKE_UP_ORIENTATION "android.sensor.wake_up_orientation"
486
487#define SENSOR_TYPE_WAKE_UP_GYROSCOPE (26)
488#define SENSOR_STRING_TYPE_WAKE_UP_GYROSCOPE "android.sensor.wake_up_gyroscope"
489
490#define SENSOR_TYPE_WAKE_UP_LIGHT (27)
491#define SENSOR_STRING_TYPE_WAKE_UP_LIGHT "android.sensor.wake_up_light"
492
493#define SENSOR_TYPE_WAKE_UP_PRESSURE (28)
494#define SENSOR_STRING_TYPE_WAKE_UP_PRESSURE "android.sensor.wake_up_pressure"
495
496#define SENSOR_TYPE_WAKE_UP_GRAVITY (29)
497#define SENSOR_STRING_TYPE_WAKE_UP_GRAVITY "android.sensor.wake_up_gravity"
498
499#define SENSOR_TYPE_WAKE_UP_LINEAR_ACCELERATION (30)
500#define SENSOR_STRING_TYPE_WAKE_UP_LINEAR_ACCELERATION "android.sensor.wake_up_linear_acceleration"
501
502#define SENSOR_TYPE_WAKE_UP_ROTATION_VECTOR (31)
503#define SENSOR_STRING_TYPE_WAKE_UP_ROTATION_VECTOR "android.sensor.wake_up_rotation_vector"
504
505#define SENSOR_TYPE_WAKE_UP_RELATIVE_HUMIDITY (32)
506#define SENSOR_STRING_TYPE_WAKE_UP_RELATIVE_HUMIDITY "android.sensor.wake_up_relative_humidity"
507
508#define SENSOR_TYPE_WAKE_UP_AMBIENT_TEMPERATURE (33)
509#define SENSOR_STRING_TYPE_WAKE_UP_AMBIENT_TEMPERATURE "android.sensor.wake_up_ambient_temperature"
510
511#define SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED (34)
512#define SENSOR_STRING_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.wake_up_magnetic_field_uncalibrated"
513
514#define SENSOR_TYPE_WAKE_UP_GAME_ROTATION_VECTOR (35)
515#define SENSOR_STRING_TYPE_WAKE_UP_GAME_ROTATION_VECTOR "android.sensor.wake_up_game_rotation_vector"
516
517#define SENSOR_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED (36)
518#define SENSOR_STRING_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED "android.sensor.wake_up_gyroscope_uncalibrated"
519
520#define SENSOR_TYPE_WAKE_UP_STEP_DETECTOR (37)
521#define SENSOR_STRING_TYPE_WAKE_UP_STEP_DETECTOR "android.sensor.wake_up_step_detector"
522
523#define SENSOR_TYPE_WAKE_UP_STEP_COUNTER (38)
524#define SENSOR_STRING_TYPE_WAKE_UP_STEP_COUNTER "android.sensor.wake_up_step_counter"
525
526#define SENSOR_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR (39)
527#define SENSOR_STRING_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.wake_up_geomagnetic_rotation_vector"
528
529#define SENSOR_TYPE_WAKE_UP_HEART_RATE (40)
530#define SENSOR_STRING_TYPE_WAKE_UP_HEART_RATE "android.sensor.wake_up_heart_rate"
531
Aravind Akellaf895c682014-04-30 11:46:09 -0700532/*
533 * SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700534 * reporting-mode: special (setDelay has no impact)
Aravind Akellaf895c682014-04-30 11:46:09 -0700535 * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
536 *
537 * A sensor of this type generates an event each time a tilt event is detected. A tilt event
538 * should be generated if the direction of the 2-seconds window average gravity changed by at least
Etienne Le Grand53017ef2014-05-28 15:42:48 -0700539 * 35 degrees since the activation or the last trigger of the sensor.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700540 * reference_estimated_gravity = average of accelerometer measurements over the first
Etienne Le Grand53017ef2014-05-28 15:42:48 -0700541 * 1 second after activation or the estimated gravity at the last
542 * trigger.
Aravind Akellaf895c682014-04-30 11:46:09 -0700543 * current_estimated_gravity = average of accelerometer measurements over the last 2 seconds.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700544 * trigger when angle (reference_estimated_gravity, current_estimated_gravity) > 35 degrees
Aravind Akellaf895c682014-04-30 11:46:09 -0700545 *
546 * Large accelerations without a change in phone orientation should not trigger a tilt event.
547 * For example, a sharp turn or strong acceleration while driving a car should not trigger a tilt
548 * event, even though the angle of the average acceleration might vary by more than 35 degrees.
549 *
550 * Typically, this sensor is implemented with the help of only an accelerometer. Other sensors can
551 * be used as well if they do not increase the power consumption significantly. This is a low power
552 * sensor that should allow the AP to go into suspend mode. Do not emulate this sensor in the HAL.
553 * Like other wake up sensors, the driver is expected to a hold a wake_lock with a timeout of 200 ms
554 * while reporting this event. The only allowed return value is 1.0.
555 */
556#define SENSOR_TYPE_WAKE_UP_TILT_DETECTOR (41)
557#define SENSOR_STRING_TYPE_WAKE_UP_TILT_DETECTOR "android.sensor.wake_up_tilt_detector"
558
Etienne Le Grandba123122014-05-05 18:20:42 -0700559/*
560 * SENSOR_TYPE_WAKE_GESTURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700561 * reporting-mode: one-shot
Etienne Le Grandba123122014-05-05 18:20:42 -0700562 * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
563 *
564 * A sensor enabling waking up the device based on a device specific motion.
565 *
566 * When this sensor triggers, the device behaves as if the power button was
567 * pressed, turning the screen on. This behavior (turning on the screen when
568 * this sensor triggers) might be deactivated by the user in the device
569 * settings. Changes in settings do not impact the behavior of the sensor:
570 * only whether the framework turns the screen on when it triggers.
571 *
572 * The actual gesture to be detected is not specified, and can be chosen by
573 * the manufacturer of the device.
574 * This sensor must be low power, as it is likely to be activated 24/7.
575 * The only allowed value to return is 1.0.
576 */
577#define SENSOR_TYPE_WAKE_GESTURE (42)
578#define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture"
579
Jeff Brown8df2feb2014-07-17 15:11:51 -0700580/*
581 * SENSOR_TYPE_GLANCE_GESTURE
582 * reporting-mode: one-shot
583 * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
584 *
585 * A sensor enabling briefly turning the screen on to enable the user to
586 * glance content on screen based on a specific motion. The device should
587 * turn the screen off after a few moments.
588 *
589 * When this sensor triggers, the device turns the screen on momentarily
590 * to allow the user to glance notifications or other content while the
591 * device remains locked in a non-interactive state (dozing). This behavior
592 * (briefly turning on the screen when this sensor triggers) might be deactivated
593 * by the user in the device settings. Changes in settings do not impact the
594 * behavior of the sensor: only whether the framework briefly turns the screen on
595 * when it triggers.
596 *
597 * The actual gesture to be detected is not specified, and can be chosen by
598 * the manufacturer of the device.
599 * This sensor must be low power, as it is likely to be activated 24/7.
600 * The only allowed value to return is 1.0.
601 */
602#define SENSOR_TYPE_GLANCE_GESTURE (43)
603#define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture"
604
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800605/**
Aravind Akella952471e2014-07-17 12:40:54 -0700606 * SENSOR_TYPE_PICK_UP_GESTURE
607 * reporting-mode: one-shot
608 * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
609 *
610 * A sensor of this type triggers when the device is picked up regardless of wherever is was
611 * before (desk, pocket, bag). The only allowed return value is 1.0.
612 * This sensor de-activates itself immediately after it triggers.
613 */
614#define SENSOR_TYPE_PICK_UP_GESTURE (43)
615#define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture"
616
617/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800618 * Values returned by the accelerometer in various locations in the universe.
619 * all values are in SI units (m/s^2)
620 */
621#define GRAVITY_SUN (275.0f)
622#define GRAVITY_EARTH (9.80665f)
623
624/** Maximum magnetic field on Earth's surface */
625#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
626
627/** Minimum magnetic field on Earth's surface */
628#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
629
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800630/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700631 * Possible values of the status field of sensor events.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800632 */
Etienne Le Grand7b361582014-05-16 11:08:28 -0700633#define SENSOR_STATUS_NO_CONTACT -1
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800634#define SENSOR_STATUS_UNRELIABLE 0
635#define SENSOR_STATUS_ACCURACY_LOW 1
636#define SENSOR_STATUS_ACCURACY_MEDIUM 2
637#define SENSOR_STATUS_ACCURACY_HIGH 3
638
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800639/**
640 * sensor event data
641 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800642typedef struct {
643 union {
644 float v[3];
645 struct {
646 float x;
647 float y;
648 float z;
649 };
650 struct {
651 float azimuth;
652 float pitch;
653 float roll;
654 };
655 };
656 int8_t status;
657 uint8_t reserved[3];
658} sensors_vec_t;
659
660/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800661 * uncalibrated gyroscope and magnetometer event data
662 */
663typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700664 union {
665 float uncalib[3];
666 struct {
667 float x_uncalib;
668 float y_uncalib;
669 float z_uncalib;
670 };
671 };
672 union {
673 float bias[3];
674 struct {
675 float x_bias;
676 float y_bias;
677 float z_bias;
678 };
679 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800680} uncalibrated_event_t;
681
Mathias Agopian16671c52013-07-24 21:07:40 -0700682typedef struct meta_data_event {
683 int32_t what;
684 int32_t sensor;
685} meta_data_event_t;
686
Etienne Le Grandca858142013-02-26 19:17:20 -0800687/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700688 * Heart rate event data
689 */
690typedef struct {
691 // Heart rate in beats per minute.
692 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
693 float bpm;
694 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
695 int8_t status;
696} heart_rate_event_t;
697
698/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800699 * Union of the various types of sensor data
700 * that can be returned.
701 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700702typedef struct sensors_event_t {
703 /* must be sizeof(struct sensors_event_t) */
704 int32_t version;
705
706 /* sensor identifier */
707 int32_t sensor;
708
709 /* sensor type */
710 int32_t type;
711
712 /* reserved */
713 int32_t reserved0;
714
715 /* time is in nanosecond */
716 int64_t timestamp;
717
718 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700719 union {
720 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700721
Mathias Agopian27e16682013-07-08 14:00:54 -0700722 /* acceleration values are in meter per second per second (m/s^2) */
723 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700724
Mathias Agopian27e16682013-07-08 14:00:54 -0700725 /* magnetic vector values are in micro-Tesla (uT) */
726 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700727
Mathias Agopian27e16682013-07-08 14:00:54 -0700728 /* orientation values are in degrees */
729 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700730
Mathias Agopian27e16682013-07-08 14:00:54 -0700731 /* gyroscope values are in rad/s */
732 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700733
Mathias Agopian27e16682013-07-08 14:00:54 -0700734 /* temperature is in degrees centigrade (Celsius) */
735 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700736
Mathias Agopian27e16682013-07-08 14:00:54 -0700737 /* distance in centimeters */
738 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700739
Mathias Agopian27e16682013-07-08 14:00:54 -0700740 /* light in SI lux units */
741 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700742
Mathias Agopian27e16682013-07-08 14:00:54 -0700743 /* pressure in hectopascal (hPa) */
744 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100745
Mathias Agopian27e16682013-07-08 14:00:54 -0700746 /* relative humidity in percent */
747 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800748
Mathias Agopian27e16682013-07-08 14:00:54 -0700749 /* uncalibrated gyroscope values are in rad/s */
750 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800751
Mathias Agopian27e16682013-07-08 14:00:54 -0700752 /* uncalibrated magnetometer values are in micro-Teslas */
753 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700754
Etienne Le Grand7b361582014-05-16 11:08:28 -0700755 /* heart rate data containing value in bpm and status */
756 heart_rate_event_t heart_rate;
Aravind Akella477fbd52014-04-07 22:46:01 +0000757
Mathias Agopian16671c52013-07-24 21:07:40 -0700758 /* this is a special event. see SENSOR_TYPE_META_DATA above.
759 * sensors_meta_data_event_t events are all reported with a type of
760 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
761 */
762 meta_data_event_t meta_data;
Mathias Agopian27e16682013-07-08 14:00:54 -0700763 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800764
Mathias Agopian27e16682013-07-08 14:00:54 -0700765 union {
766 uint64_t data[8];
767
768 /* step-counter */
769 uint64_t step_counter;
770 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700771 };
Aravind Akella6242f322014-02-28 18:46:19 -0800772
773 /* Reserved flags for internal use. Set to zero. */
774 uint32_t flags;
775
776 uint32_t reserved1[3];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700777} sensors_event_t;
778
779
Mathias Agopian16671c52013-07-24 21:07:40 -0700780/* see SENSOR_TYPE_META_DATA */
781typedef sensors_event_t sensors_meta_data_event_t;
782
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700783
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800784struct sensor_t;
785
786/**
787 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
788 * and the fields of this data structure must begin with hw_module_t
789 * followed by module specific information.
790 */
791struct sensors_module_t {
792 struct hw_module_t common;
793
794 /**
795 * Enumerate all available sensors. The list is returned in "list".
796 * @return number of sensors in the list
797 */
798 int (*get_sensors_list)(struct sensors_module_t* module,
799 struct sensor_t const** list);
800};
801
802struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800803
804 /* Name of this sensor.
805 * All sensors of the same "type" must have a different "name".
806 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800807 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800808
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800809 /* vendor of the hardware part */
810 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800811
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800812 /* version of the hardware part + driver. The value of this field
813 * must increase when the driver is updated in a way that changes the
814 * output of this sensor. This is important for fused sensors when the
815 * fusion algorithm is updated.
Aravind Akella6242f322014-02-28 18:46:19 -0800816 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800817 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800818
819 /* handle that identifies this sensors. This handle is used to reference
820 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800821 */
822 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800823
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800824 /* this sensor's type. */
825 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800826
827 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800828 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800829
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800830 /* smallest difference between two values reported by this sensor */
831 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800832
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800833 /* rough estimate of this sensor's power consumption in mA */
834 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800835
Aravind Akellac841efd2014-06-03 19:21:35 -0700836 /* this value depends on the reporting mode:
Mathias Agopiana4557722012-11-28 17:21:55 -0800837 *
838 * continuous: minimum sample period allowed in microseconds
839 * on-change : 0
840 * one-shot :-1
841 * special : 0, unless otherwise noted
842 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700843 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800844
Mathias Agopian16671c52013-07-24 21:07:40 -0700845 /* number of events reserved for this sensor in the batch mode FIFO.
846 * If there is a dedicated FIFO for this sensor, then this is the
847 * size of this FIFO. If the FIFO is shared with other sensors,
848 * this is the size reserved for that sensor and it can be zero.
849 */
850 uint32_t fifoReservedEventCount;
851
852 /* maximum number of events of this sensor that could be batched.
853 * This is especially relevant when the FIFO is shared between
854 * several sensors; this value is then set to the size of that FIFO.
855 */
856 uint32_t fifoMaxEventCount;
857
Aravind Akella477fbd52014-04-07 22:46:01 +0000858 /* type of this sensor as a string. Set to corresponding
859 * SENSOR_STRING_TYPE_*.
860 * When defining an OEM specific sensor or sensor manufacturer specific
861 * sensor, use your reserve domain name as a prefix.
862 * ex: com.google.glass.onheaddetector
863 * For sensors of known type, the android framework might overwrite this
864 * string automatically.
865 */
866 const char* stringType;
867
868 /* permission required to see this sensor, register to it and receive data.
869 * Set to "" if no permission is required. Some sensor types like the
870 * heart rate monitor have a mandatory require_permission.
871 * For sensors that always require a specific permission, like the heart
872 * rate monitor, the android framework might overwrite this string
873 * automatically.
874 */
875 const char* requiredPermission;
876
Aravind Akella6242f322014-02-28 18:46:19 -0800877 /* This value is defined only for continuous mode sensors. It is the delay between two
878 * sensor events corresponding to the lowest frequency that this sensor supports. When
879 * lower frequencies are requested through batch()/setDelay() the events will be generated
880 * at this frequency instead. It can be used by the framework or applications to estimate
881 * when the batch FIFO may be full.
Aravind Akellac841efd2014-06-03 19:21:35 -0700882 *
883 * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
884 * continuous: maximum sampling period allowed in microseconds.
885 * on-change, one-shot, special : 0
886 * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit
887 * on 64 bit architectures only for binary compatibility reasons.
Aravind Akella6242f322014-02-28 18:46:19 -0800888 * Availability: SENSORS_DEVICE_API_VERSION_1_3
889 */
890 #ifdef __LP64__
891 int64_t maxDelay;
892 #else
893 int32_t maxDelay;
894 #endif
895
Aravind Akellac841efd2014-06-03 19:21:35 -0700896 /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.
897 * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.
898 * Availability: SENSORS_DEVICE_API_VERSION_1_3
899 */
Aravind Akella6242f322014-02-28 18:46:19 -0800900 #ifdef __LP64__
901 uint64_t flags;
902 #else
903 uint32_t flags;
904 #endif
905
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800906 /* reserved fields, must be zero */
Aravind Akella6242f322014-02-28 18:46:19 -0800907 void* reserved[2];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800908};
909
910
Mathias Agopiana4557722012-11-28 17:21:55 -0800911/*
912 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
913 * and is present for backward binary and source compatibility.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800914 * See the Sensors HAL interface section for complete descriptions of the
915 * following functions:
916 * http://source.android.com/devices/sensors/index.html#hal
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800917 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700918struct sensors_poll_device_t {
919 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700920 int (*activate)(struct sensors_poll_device_t *dev,
921 int handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700922 int (*setDelay)(struct sensors_poll_device_t *dev,
923 int handle, int64_t ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700924 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700925 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700926};
927
Mathias Agopiana4557722012-11-28 17:21:55 -0800928/*
929 * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
930 */
931typedef struct sensors_poll_device_1 {
932 union {
933 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
934 * and can be down-cast to it
935 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800936 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -0800937
938 struct {
939 struct hw_device_t common;
940
Clay Murphy8db1fb42013-12-19 09:58:28 -0800941 /* Activate/de-activate one sensor. Return 0 on success, negative
Mathias Agopiana4557722012-11-28 17:21:55 -0800942 *
943 * handle is the handle of the sensor to change.
944 * enabled set to 1 to enable, or 0 to disable the sensor.
945 *
Clay Murphy8db1fb42013-12-19 09:58:28 -0800946 * Return 0 on success, negative errno code otherwise.
Mathias Agopiana4557722012-11-28 17:21:55 -0800947 */
948 int (*activate)(struct sensors_poll_device_t *dev,
949 int handle, int enabled);
950
951 /**
Aravind Akella6242f322014-02-28 18:46:19 -0800952 * Set the events's period in nanoseconds for a given sensor. If
953 * period_ns > max_delay it will be truncated to max_delay and if
954 * period_ns < min_delay it will be replaced by min_delay.
Mathias Agopiana4557722012-11-28 17:21:55 -0800955 */
956 int (*setDelay)(struct sensors_poll_device_t *dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -0800957 int handle, int64_t period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -0800958
959 /**
960 * Returns an array of sensor data.
Mathias Agopiana4557722012-11-28 17:21:55 -0800961 */
962 int (*poll)(struct sensors_poll_device_t *dev,
963 sensors_event_t* data, int count);
964 };
965 };
966
Mathias Agopiana4557722012-11-28 17:21:55 -0800967
968 /*
Clay Murphy8db1fb42013-12-19 09:58:28 -0800969 * Enables batch mode for the given sensor and sets the delay between events.
970 * See the Batching sensor results page for details:
971 * http://source.android.com/devices/sensors/batching.html
Mathias Agopiana4557722012-11-28 17:21:55 -0800972 */
973 int (*batch)(struct sensors_poll_device_1* dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -0800974 int handle, int flags, int64_t period_ns, int64_t timeout);
Mathias Agopiana4557722012-11-28 17:21:55 -0800975
Mathias Agopian16671c52013-07-24 21:07:40 -0700976 /*
977 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
978 * to the end of the "batch mode" FIFO for the specified sensor and flushes
Aravind Akellac841efd2014-06-03 19:21:35 -0700979 * the FIFO. If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero),
980 * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the
981 * event stream. This applies to all sensors other than ONE_SHOT sensors.
Mathias Agopian16671c52013-07-24 21:07:40 -0700982 */
983 int (*flush)(struct sensors_poll_device_1* dev, int handle);
984
Mathias Agopiana4557722012-11-28 17:21:55 -0800985 void (*reserved_procs[8])(void);
986
987} sensors_poll_device_1_t;
988
989
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800990/** convenience API for opening and closing a device */
991
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700992static inline int sensors_open(const struct hw_module_t* module,
993 struct sensors_poll_device_t** device) {
994 return module->methods->open(module,
995 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
996}
997
998static inline int sensors_close(struct sensors_poll_device_t* device) {
999 return device->common.close(&device->common);
1000}
1001
Mathias Agopiana4557722012-11-28 17:21:55 -08001002static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001003 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001004 return module->methods->open(module,
1005 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1006}
1007
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001008static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001009 return device->common.close(&device->common);
1010}
1011
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001012__END_DECLS
1013
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001014#endif // ANDROID_SENSORS_INTERFACE_H