blob: b8b550fb4d96cf0d017d5bfc4ba1dffe751ee0eb [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)
Ashutosh Joshi6507f502015-04-03 16:22:32 -070038#define SENSORS_DEVICE_API_VERSION_1_4 HARDWARE_DEVICE_API_VERSION_2(1, 4, SENSORS_HEADER_VERSION)
Mathias Agopian56f66cc2012-11-08 15:57:38 -080039
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080040/**
Clay Murphy8db1fb42013-12-19 09:58:28 -080041 * Please see the Sensors section of source.android.com for an
42 * introduction to and detailed descriptions of Android sensor types:
43 * http://source.android.com/devices/sensors/index.html
44 */
45
46/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080047 * The id of this module
48 */
49#define SENSORS_HARDWARE_MODULE_ID "sensors"
50
51/**
52 * Name of the sensors device to open
53 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -070054#define SENSORS_HARDWARE_POLL "poll"
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080055
56/**
57 * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
58 * A Handle identifies a given sensors. The handle is used to activate
59 * and/or deactivate sensors.
60 * In this version of the API there can only be 256 handles.
61 */
62#define SENSORS_HANDLE_BASE 0
63#define SENSORS_HANDLE_BITS 8
64#define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS)
65
66
Mathias Agopiana4557722012-11-28 17:21:55 -080067/*
Aravind Akella6242f322014-02-28 18:46:19 -080068 * **** Deprecated *****
Mathias Agopiana4557722012-11-28 17:21:55 -080069 * flags for (*batch)()
70 * Availability: SENSORS_DEVICE_API_VERSION_1_0
Aravind Akella6242f322014-02-28 18:46:19 -080071 * see (*batch)() documentation for details.
72 * Deprecated as of SENSORS_DEVICE_API_VERSION_1_3.
73 * WAKE_UP_* sensors replace WAKE_UPON_FIFO_FULL concept.
Mathias Agopiana4557722012-11-28 17:21:55 -080074 */
75enum {
76 SENSORS_BATCH_DRY_RUN = 0x00000001,
77 SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
78};
79
Mathias Agopian16671c52013-07-24 21:07:40 -070080/*
81 * what field for meta_data_event_t
82 */
83enum {
84 /* a previous flush operation has completed */
Mathias Agopianaf32a8d2013-08-06 20:33:38 -070085 META_DATA_FLUSH_COMPLETE = 1,
86 META_DATA_VERSION /* always last, leave auto-assigned */
Mathias Agopian16671c52013-07-24 21:07:40 -070087};
88
Mathias Agopiana4557722012-11-28 17:21:55 -080089/*
Aravind Akella477fbd52014-04-07 22:46:01 +000090 * The permission to use for body sensors (like heart rate monitors).
91 * See sensor types for more details on what sensors should require this
92 * permission.
93 */
94#define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS"
95
96/*
Ashutosh Joshi6507f502015-04-03 16:22:32 -070097 * Availability: SENSORS_DEVICE_API_VERSION_1_4
Ashutosh Joshi050f2e42015-04-15 13:56:53 -070098 * Sensor HAL modes used in set_operation_mode method
Ashutosh Joshi6507f502015-04-03 16:22:32 -070099 */
100enum {
101 /*
102 * Operating modes for the HAL.
103 */
104
105 /*
106 * Normal mode operation. This is the default state of operation.
107 * The HAL shall initialize into this mode on device startup.
108 */
109 SENSOR_HAL_NORMAL_MODE = 0,
110
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700111 /*
112 * Loopback mode. In this mode, the device shall not source data from the
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700113 * physical sensors as it would in normal mode. Instead sensor data is
114 * injected by the sensor service.
115 */
116 SENSOR_HAL_LOOPBACK_MODE = 0x1
117};
118
119/*
Aravind Akella6242f322014-02-28 18:46:19 -0800120 * Availability: SENSORS_DEVICE_API_VERSION_1_3
121 * Sensor flags used in sensor_t.flags.
122 */
123enum {
124 /*
Aravind Akella110d2f22014-09-04 15:36:31 -0700125 * Whether this sensor wakes up the AP from suspend mode when data is available. Whenever
126 * sensor events are delivered from a wake_up sensor, the driver needs to hold a wake_lock till
127 * the events are read by the SensorService i.e till sensors_poll_device_t.poll() is called the
128 * next time. Once poll is called again it means events have been read by the SensorService, the
129 * driver can safely release the wake_lock. SensorService will continue to hold a wake_lock till
130 * the app actually reads the events.
Aravind Akella6242f322014-02-28 18:46:19 -0800131 */
Aravind Akellac841efd2014-06-03 19:21:35 -0700132 SENSOR_FLAG_WAKE_UP = 1U << 0,
133 /*
134 * Reporting modes for various sensors. Each sensor will have exactly one of these modes set.
135 * The least significant 2nd, 3rd and 4th bits are used to represent four possible reporting
136 * modes.
137 */
138 SENSOR_FLAG_CONTINUOUS_MODE = 0, // 0000
139 SENSOR_FLAG_ON_CHANGE_MODE = 0x2, // 0010
140 SENSOR_FLAG_ONE_SHOT_MODE = 0x4, // 0100
141 SENSOR_FLAG_SPECIAL_REPORTING_MODE = 0x6 // 0110
Aravind Akella6242f322014-02-28 18:46:19 -0800142};
143
144/*
Aravind Akellac841efd2014-06-03 19:21:35 -0700145 * Mask and shift for reporting mode sensor flags defined above.
146 */
147#define REPORTING_MODE_MASK (0xE)
148#define REPORTING_MODE_SHIFT (1)
149
150/*
Mathias Agopiana4557722012-11-28 17:21:55 -0800151 * Sensor type
152 *
153 * Each sensor has a type which defines what this sensor measures and how
Clay Murphy8db1fb42013-12-19 09:58:28 -0800154 * measures are reported. See the Base sensors and Composite sensors lists
155 * for complete descriptions:
156 * http://source.android.com/devices/sensors/base_triggers.html
157 * http://source.android.com/devices/sensors/composite_sensors.html
Mathias Agopian1599ec62013-08-19 14:34:47 -0700158 *
159 * Device manufacturers (OEMs) can define their own sensor types, for
160 * their private use by applications or services provided by them. Such
161 * sensor types are specific to an OEM and can't be exposed in the SDK.
162 * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE.
Aravind Akella477fbd52014-04-07 22:46:01 +0000163 *
164 * All sensors defined outside of the device private range must correspond to
165 * a type defined in this file, and must satisfy the characteristics listed in
166 * the description of the sensor type.
167 *
168 * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also
169 * has a stringType.
170 * - StringType of sensors inside of the device private range MUST be prefixed
171 * by the sensor provider's or OEM reverse domain name. In particular, they
172 * cannot use the "android.sensor" prefix.
173 * - StringType of sensors outside of the device private range MUST correspond
174 * to the one defined in this file (starting with "android.sensor").
175 * For example, accelerometers must have
176 * type=SENSOR_TYPE_ACCELEROMETER and
177 * stringType=SENSOR_STRING_TYPE_ACCELEROMETER
178 *
179 * When android introduces a new sensor type that can replace an OEM-defined
180 * sensor type, the OEM must use the official sensor type and stringType on
181 * versions of the HAL that support this new official sensor type.
182 *
183 * Example (made up): Suppose Google's Glass team wants to surface a sensor
184 * detecting that Glass is on a head.
185 * - Such a sensor is not officially supported in android KitKat
186 * - Glass devices launching on KitKat can implement a sensor with
187 * type = 0x10001 and stringType = "com.google.glass.onheaddetector"
188 * - In L android release, if android decides to define
189 * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR,
190 * those types should replace the Glass-team-specific types in all future
191 * launches.
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700192 * - When launching Glass on the L release, Google should now use the official
Aravind Akella477fbd52014-04-07 22:46:01 +0000193 * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType.
194 * - This way, all applications can now use this sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800195 */
196
197/*
Mathias Agopian1599ec62013-08-19 14:34:47 -0700198 * Base for device manufacturers private sensor types.
199 * These sensor types can't be exposed in the SDK.
200 */
201#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000
202
203/*
Mathias Agopian16671c52013-07-24 21:07:40 -0700204 * SENSOR_TYPE_META_DATA
Aravind Akellac841efd2014-06-03 19:21:35 -0700205 * reporting-mode: n/a
Mathias Agopian16671c52013-07-24 21:07:40 -0700206 * wake-up sensor: n/a
207 *
208 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
209 *
210 * SENSOR_TYPE_META_DATA is a special token used to populate the
211 * sensors_meta_data_event structure. It doesn't correspond to a physical
212 * sensor. sensors_meta_data_event are special, they exist only inside
213 * the HAL and are generated spontaneously, as opposed to be related to
214 * a physical sensor.
215 *
Mathias Agopianaf32a8d2013-08-06 20:33:38 -0700216 * sensors_meta_data_event_t.version must be META_DATA_VERSION
217 * sensors_meta_data_event_t.sensor must be 0
218 * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
219 * sensors_meta_data_event_t.reserved must be 0
220 * sensors_meta_data_event_t.timestamp must be 0
Mathias Agopian16671c52013-07-24 21:07:40 -0700221 *
222 * The payload is a meta_data_event_t, where:
223 * meta_data_event_t.what can take the following values:
224 *
225 * META_DATA_FLUSH_COMPLETE
226 * This event indicates that a previous (*flush)() call has completed for the sensor
227 * handle specified in meta_data_event_t.sensor.
228 * see (*flush)() for more details
229 *
230 * All other values for meta_data_event_t.what are reserved and
231 * must not be used.
232 *
233 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000234#define SENSOR_TYPE_META_DATA (0)
Mathias Agopian16671c52013-07-24 21:07:40 -0700235
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800236/*
Aravind Akella9057e122014-07-28 18:01:37 -0700237 * Wake up sensors.
238 * Each sensor may have either or both a wake-up and a non-wake variant.
239 * When registered in batch mode, wake-up sensors will wake up the AP when
240 * their FIFOs are full or when the batch timeout expires. A separate FIFO has
241 * to be maintained for wake up sensors and non wake up sensors. The non wake-up
242 * sensors need to overwrite their FIFOs when they are full till the AP wakes up
243 * and the wake-up sensors will wake-up the AP when their FIFOs are full or when
244 * the batch timeout expires without losing events. Wake-up and non wake-up variants
245 * of each sensor can be activated at different rates independently of each other.
246 *
247 * Note: Proximity sensor and significant motion sensor which were defined in previous
248 * releases are also wake-up sensors and should be treated as such. Wake-up one-shot
249 * sensors like SIGNIFICANT_MOTION cannot be batched, hence the text about batch above
250 * doesn't apply to them. See the definitions of SENSOR_TYPE_PROXIMITY and
251 * SENSOR_TYPE_SIGNIFICANT_MOTION for more info.
252 *
253 * Set SENSOR_FLAG_WAKE_UP flag for all wake-up sensors.
254 *
255 * For example, A device can have two sensors both of SENSOR_TYPE_ACCELEROMETER and
256 * one of them can be a wake_up sensor (with SENSOR_FLAG_WAKE_UP flag set) and the other
257 * can be a regular non wake_up sensor. Both of these sensors must be activated/deactivated
258 * independently of the other.
259 */
260
261/*
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800262 * SENSOR_TYPE_ACCELEROMETER
Aravind Akellac841efd2014-06-03 19:21:35 -0700263 * reporting-mode: continuous
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800264 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800265 * All values are in SI units (m/s^2) and measure the acceleration of the
266 * device minus the force of gravity.
267 *
Aravind Akella9057e122014-07-28 18:01:37 -0700268 * Implement the non-wake-up version of this sensor and implement the wake-up
269 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800270 */
271#define SENSOR_TYPE_ACCELEROMETER (1)
Aravind Akella477fbd52014-04-07 22:46:01 +0000272#define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800273
274/*
275 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akellac841efd2014-06-03 19:21:35 -0700276 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800277 *
278 * All values are in micro-Tesla (uT) and measure the geomagnetic
279 * field in the X, Y and Z axis.
280 *
Aravind Akella9057e122014-07-28 18:01:37 -0700281 * Implement the non-wake-up version of this sensor and implement the wake-up
282 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800283 */
284#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
285#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akella477fbd52014-04-07 22:46:01 +0000286#define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800287
288/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800289 * SENSOR_TYPE_ORIENTATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700290 * reporting-mode: continuous
Clay Murphy8db1fb42013-12-19 09:58:28 -0800291 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800292 * All values are angles in degrees.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800293 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700294 * Orientation sensors return sensor events for all 3 axes at a constant
295 * rate defined by setDelay().
Aravind Akella9057e122014-07-28 18:01:37 -0700296 *
297 * Implement the non-wake-up version of this sensor and implement the wake-up
298 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800299 */
300#define SENSOR_TYPE_ORIENTATION (3)
Aravind Akella477fbd52014-04-07 22:46:01 +0000301#define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800302
303/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800304 * SENSOR_TYPE_GYROSCOPE
Aravind Akellac841efd2014-06-03 19:21:35 -0700305 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800306 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700307 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800308 * around the X, Y and Z axis.
Aravind Akella9057e122014-07-28 18:01:37 -0700309 *
310 * Implement the non-wake-up version of this sensor and implement the wake-up
311 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800312 */
313#define SENSOR_TYPE_GYROSCOPE (4)
Aravind Akella477fbd52014-04-07 22:46:01 +0000314#define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800315
316/*
317 * SENSOR_TYPE_LIGHT
Aravind Akellac841efd2014-06-03 19:21:35 -0700318 * reporting-mode: on-change
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800319 *
320 * The light sensor value is returned in SI lux units.
Aravind Akella9057e122014-07-28 18:01:37 -0700321 *
322 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800323 */
324#define SENSOR_TYPE_LIGHT (5)
Aravind Akella477fbd52014-04-07 22:46:01 +0000325#define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800326
327/*
328 * SENSOR_TYPE_PRESSURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700329 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800330 *
331 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Aravind Akella9057e122014-07-28 18:01:37 -0700332 *
333 * Implement the non-wake-up version of this sensor and implement the wake-up
334 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800335 */
336#define SENSOR_TYPE_PRESSURE (6)
Aravind Akella477fbd52014-04-07 22:46:01 +0000337#define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800338
339/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
340#define SENSOR_TYPE_TEMPERATURE (7)
Aravind Akella477fbd52014-04-07 22:46:01 +0000341#define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800342
343/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800344 * SENSOR_TYPE_PROXIMITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700345 * reporting-mode: on-change
Mike Lockwooda2414312009-11-03 10:29:50 -0500346 *
Aravind Akella9057e122014-07-28 18:01:37 -0700347 * The proximity sensor which turns the screen off and back on during calls is the
348 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
349 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
350 * SENSOR_FLAG_WAKE_UP.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800351 * The value corresponds to the distance to the nearest object in centimeters.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800352 */
353#define SENSOR_TYPE_PROXIMITY (8)
Aravind Akella477fbd52014-04-07 22:46:01 +0000354#define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800355
356/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800357 * SENSOR_TYPE_GRAVITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700358 * reporting-mode: continuous
Mathias Agopian42b743c2010-11-22 15:55:32 -0800359 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800360 * A gravity output indicates the direction of and magnitude of gravity in
Clay Murphy8db1fb42013-12-19 09:58:28 -0800361 * the devices's coordinates.
Aravind Akella9057e122014-07-28 18:01:37 -0700362 *
363 * Implement the non-wake-up version of this sensor and implement the wake-up
364 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800365 */
366#define SENSOR_TYPE_GRAVITY (9)
Aravind Akella477fbd52014-04-07 22:46:01 +0000367#define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800368
369/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800370 * SENSOR_TYPE_LINEAR_ACCELERATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700371 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800372 *
373 * Indicates the linear acceleration of the device in device coordinates,
374 * not including gravity.
Aravind Akella9057e122014-07-28 18:01:37 -0700375 *
376 * Implement the non-wake-up version of this sensor and implement the wake-up
377 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800378 */
379#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
Aravind Akella477fbd52014-04-07 22:46:01 +0000380#define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800381
382
383/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800384 * SENSOR_TYPE_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700385 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800386 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700387 * The rotation vector symbolizes the orientation of the device relative to the
Clay Murphy8db1fb42013-12-19 09:58:28 -0800388 * East-North-Up coordinates frame.
Aravind Akella9057e122014-07-28 18:01:37 -0700389 *
390 * Implement the non-wake-up version of this sensor and implement the wake-up
391 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800392 */
393#define SENSOR_TYPE_ROTATION_VECTOR (11)
Aravind Akella477fbd52014-04-07 22:46:01 +0000394#define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800395
396/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800397 * SENSOR_TYPE_RELATIVE_HUMIDITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700398 * reporting-mode: on-change
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100399 *
400 * A relative humidity sensor measures relative ambient air humidity and
401 * returns a value in percent.
Aravind Akella9057e122014-07-28 18:01:37 -0700402 *
403 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800404 */
405#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
Aravind Akella477fbd52014-04-07 22:46:01 +0000406#define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800407
408/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800409 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700410 * reporting-mode: on-change
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700411 *
412 * The ambient (room) temperature in degree Celsius.
Aravind Akella9057e122014-07-28 18:01:37 -0700413 *
414 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800415 */
416#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
Aravind Akella477fbd52014-04-07 22:46:01 +0000417#define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800418
419/*
420 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700421 * reporting-mode: continuous
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700422 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800423 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
424 * reported separately instead of being included in the measurement.
Aravind Akella9057e122014-07-28 18:01:37 -0700425 *
426 * Implement the non-wake-up version of this sensor and implement the wake-up
427 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800428 */
429#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
Aravind Akella477fbd52014-04-07 22:46:01 +0000430#define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800431
432/*
433 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700434 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800435 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800436 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
Clay Murphy8db1fb42013-12-19 09:58:28 -0800437 * field.
Aravind Akella9057e122014-07-28 18:01:37 -0700438 *
439 * Implement the non-wake-up version of this sensor and implement the wake-up
440 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800441 */
442#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
Aravind Akella477fbd52014-04-07 22:46:01 +0000443#define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800444
445/*
446 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700447 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800448 *
449 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800450 * around the X, Y and Z axis.
Aravind Akella9057e122014-07-28 18:01:37 -0700451 *
452 * Implement the non-wake-up version of this sensor and implement the wake-up
453 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800454 */
455#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
Aravind Akella477fbd52014-04-07 22:46:01 +0000456#define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800457
Mathias Agopiana4557722012-11-28 17:21:55 -0800458/*
459 * SENSOR_TYPE_SIGNIFICANT_MOTION
Aravind Akellac841efd2014-06-03 19:21:35 -0700460 * reporting-mode: one-shot
Mathias Agopiana4557722012-11-28 17:21:55 -0800461 *
462 * A sensor of this type triggers an event each time significant motion
463 * is detected and automatically disables itself.
Aravind Akella9057e122014-07-28 18:01:37 -0700464 * For Significant Motion sensor to be useful, it must be defined as a
465 * wake-up sensor. (set SENSOR_FLAG_WAKE_UP). Implement the wake-up significant motion
466 * sensor. A non wake-up version is not useful.
Mathias Agopiana4557722012-11-28 17:21:55 -0800467 * The only allowed value to return is 1.0.
Mathias Agopiana4557722012-11-28 17:21:55 -0800468 */
469
470#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
Aravind Akella477fbd52014-04-07 22:46:01 +0000471#define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
Mathias Agopiana4557722012-11-28 17:21:55 -0800472
473/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800474 * SENSOR_TYPE_STEP_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700475 * reporting-mode: special
Mathias Agopiana4557722012-11-28 17:21:55 -0800476 *
477 * A sensor of this type triggers an event each time a step is taken
Clay Murphy8db1fb42013-12-19 09:58:28 -0800478 * by the user. The only allowed value to return is 1.0 and an event
479 * is generated for each step.
Aravind Akella9057e122014-07-28 18:01:37 -0700480 *
481 * Both wake-up and non wake-up versions are useful.
Mathias Agopiana4557722012-11-28 17:21:55 -0800482 */
483
Mathias Agopian2f276f52013-01-28 17:54:41 -0800484#define SENSOR_TYPE_STEP_DETECTOR (18)
Aravind Akella477fbd52014-04-07 22:46:01 +0000485#define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
Mathias Agopiana4557722012-11-28 17:21:55 -0800486
487
488/*
489 * SENSOR_TYPE_STEP_COUNTER
Aravind Akellac841efd2014-06-03 19:21:35 -0700490 * reporting-mode: on-change
Mathias Agopiana4557722012-11-28 17:21:55 -0800491 *
492 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800493 * the last reboot while activated. The value is returned as a uint64_t and is
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700494 * reset to zero only on a system / android reboot.
Aravind Akella9057e122014-07-28 18:01:37 -0700495 *
496 * Implement the non-wake-up version of this sensor and implement the wake-up
497 * version if the system possesses a wake up fifo.
Mathias Agopiana4557722012-11-28 17:21:55 -0800498 */
499
500#define SENSOR_TYPE_STEP_COUNTER (19)
Aravind Akella477fbd52014-04-07 22:46:01 +0000501#define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
Mathias Agopiana4557722012-11-28 17:21:55 -0800502
Etienne Le Grandca858142013-02-26 19:17:20 -0800503/*
504 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700505 * reporting-mode: continuous
Etienne Le Grandca858142013-02-26 19:17:20 -0800506 *
507 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
508 * of using a gyroscope.
Aravind Akella9057e122014-07-28 18:01:37 -0700509 *
510 * Implement the non-wake-up version of this sensor and implement the wake-up
511 * version if the system possesses a wake up fifo.
Etienne Le Grandca858142013-02-26 19:17:20 -0800512 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000513#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
514#define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
515
516/*
517 * SENSOR_TYPE_HEART_RATE
Aravind Akellac841efd2014-06-03 19:21:35 -0700518 * reporting-mode: on-change
Aravind Akella477fbd52014-04-07 22:46:01 +0000519 *
Etienne Le Grand7b361582014-05-16 11:08:28 -0700520 * A sensor of this type returns the current heart rate.
521 * The events contain the current heart rate in beats per minute (BPM) and the
522 * status of the sensor during the measurement. See heart_rate_event_t for more
523 * details.
524 *
525 * Because this sensor is on-change, events must be generated when and only
526 * when heart_rate.bpm or heart_rate.status have changed since the last
Vinod Krishnan74279e32014-08-28 15:25:13 -0700527 * event. In particular, upon the first activation, unless the device is known
528 * to not be on the body, the status field of the first event must be set to
529 * SENSOR_STATUS_UNRELIABLE. The event should be generated no faster than every
530 * period_ns passed to setDelay() or to batch().
Griff Hazenf0f67e62014-08-28 17:02:50 -0700531 * See the definition of the on-change reporting mode for more information.
Etienne Le Grand7b361582014-05-16 11:08:28 -0700532 *
Aravind Akella477fbd52014-04-07 22:46:01 +0000533 * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
Aravind Akella9057e122014-07-28 18:01:37 -0700534 *
535 * Both wake-up and non wake-up versions are useful.
Aravind Akella477fbd52014-04-07 22:46:01 +0000536 */
537#define SENSOR_TYPE_HEART_RATE (21)
538#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
Mathias Agopiana4557722012-11-28 17:21:55 -0800539
Aravind Akella6242f322014-02-28 18:46:19 -0800540/*
Aravind Akellaf895c682014-04-30 11:46:09 -0700541 * SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700542 * reporting-mode: special (setDelay has no impact)
Aravind Akellaf895c682014-04-30 11:46:09 -0700543 *
544 * A sensor of this type generates an event each time a tilt event is detected. A tilt event
545 * 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 -0700546 * 35 degrees since the activation or the last trigger of the sensor.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700547 * reference_estimated_gravity = average of accelerometer measurements over the first
Etienne Le Grand53017ef2014-05-28 15:42:48 -0700548 * 1 second after activation or the estimated gravity at the last
549 * trigger.
Aravind Akellaf895c682014-04-30 11:46:09 -0700550 * current_estimated_gravity = average of accelerometer measurements over the last 2 seconds.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700551 * trigger when angle (reference_estimated_gravity, current_estimated_gravity) > 35 degrees
Aravind Akellaf895c682014-04-30 11:46:09 -0700552 *
553 * Large accelerations without a change in phone orientation should not trigger a tilt event.
554 * For example, a sharp turn or strong acceleration while driving a car should not trigger a tilt
555 * event, even though the angle of the average acceleration might vary by more than 35 degrees.
556 *
557 * Typically, this sensor is implemented with the help of only an accelerometer. Other sensors can
558 * be used as well if they do not increase the power consumption significantly. This is a low power
559 * sensor that should allow the AP to go into suspend mode. Do not emulate this sensor in the HAL.
560 * Like other wake up sensors, the driver is expected to a hold a wake_lock with a timeout of 200 ms
561 * while reporting this event. The only allowed return value is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700562 *
563 * Implement only the wake-up version of this sensor.
Aravind Akellaf895c682014-04-30 11:46:09 -0700564 */
Aravind Akella9057e122014-07-28 18:01:37 -0700565#define SENSOR_TYPE_TILT_DETECTOR (22)
566#define SENSOR_STRING_TYPE_TILT_DETECTOR "android.sensor.tilt_detector"
Aravind Akellaf895c682014-04-30 11:46:09 -0700567
Etienne Le Grandba123122014-05-05 18:20:42 -0700568/*
569 * SENSOR_TYPE_WAKE_GESTURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700570 * reporting-mode: one-shot
Etienne Le Grandba123122014-05-05 18:20:42 -0700571 *
572 * A sensor enabling waking up the device based on a device specific motion.
573 *
574 * When this sensor triggers, the device behaves as if the power button was
575 * pressed, turning the screen on. This behavior (turning on the screen when
576 * this sensor triggers) might be deactivated by the user in the device
577 * settings. Changes in settings do not impact the behavior of the sensor:
578 * only whether the framework turns the screen on when it triggers.
579 *
580 * The actual gesture to be detected is not specified, and can be chosen by
581 * the manufacturer of the device.
582 * This sensor must be low power, as it is likely to be activated 24/7.
583 * The only allowed value to return is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700584 *
585 * Implement only the wake-up version of this sensor.
Etienne Le Grandba123122014-05-05 18:20:42 -0700586 */
Aravind Akella9057e122014-07-28 18:01:37 -0700587#define SENSOR_TYPE_WAKE_GESTURE (23)
Etienne Le Grandba123122014-05-05 18:20:42 -0700588#define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture"
589
Jeff Brown8df2feb2014-07-17 15:11:51 -0700590/*
591 * SENSOR_TYPE_GLANCE_GESTURE
592 * reporting-mode: one-shot
Jeff Brown8df2feb2014-07-17 15:11:51 -0700593 *
594 * A sensor enabling briefly turning the screen on to enable the user to
595 * glance content on screen based on a specific motion. The device should
596 * turn the screen off after a few moments.
597 *
598 * When this sensor triggers, the device turns the screen on momentarily
599 * to allow the user to glance notifications or other content while the
600 * device remains locked in a non-interactive state (dozing). This behavior
601 * (briefly turning on the screen when this sensor triggers) might be deactivated
602 * by the user in the device settings. Changes in settings do not impact the
603 * behavior of the sensor: only whether the framework briefly turns the screen on
604 * when it triggers.
605 *
606 * The actual gesture to be detected is not specified, and can be chosen by
607 * the manufacturer of the device.
608 * This sensor must be low power, as it is likely to be activated 24/7.
609 * The only allowed value to return is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700610 *
611 * Implement only the wake-up version of this sensor.
Jeff Brown8df2feb2014-07-17 15:11:51 -0700612 */
Aravind Akella9057e122014-07-28 18:01:37 -0700613#define SENSOR_TYPE_GLANCE_GESTURE (24)
Jeff Brown8df2feb2014-07-17 15:11:51 -0700614#define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture"
615
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800616/**
Aravind Akella952471e2014-07-17 12:40:54 -0700617 * SENSOR_TYPE_PICK_UP_GESTURE
618 * reporting-mode: one-shot
Aravind Akella952471e2014-07-17 12:40:54 -0700619 *
620 * A sensor of this type triggers when the device is picked up regardless of wherever is was
621 * before (desk, pocket, bag). The only allowed return value is 1.0.
622 * This sensor de-activates itself immediately after it triggers.
Aravind Akella9057e122014-07-28 18:01:37 -0700623 *
624 * Implement only the wake-up version of this sensor.
Aravind Akella952471e2014-07-17 12:40:54 -0700625 */
Aravind Akella9057e122014-07-28 18:01:37 -0700626#define SENSOR_TYPE_PICK_UP_GESTURE (25)
Aravind Akella952471e2014-07-17 12:40:54 -0700627#define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture"
628
Nick Vaccaroadbfbb72015-01-13 12:14:28 -0800629/*
630 * SENSOR_TYPE_WRIST_TILT_GESTURE
631 * trigger-mode: special
632 * wake-up sensor: yes
633 *
634 * A sensor of this type triggers an event each time a tilt of the wrist-worn
635 * device is detected.
636 *
637 * This sensor must be low power, as it is likely to be activated 24/7.
638 * The only allowed value to return is 1.0.
639 *
640 * Implement only the wake-up version of this sensor.
641 */
642#define SENSOR_TYPE_WRIST_TILT_GESTURE (26)
643#define SENSOR_STRING_TYPE_WRIST_TILT_GESTURE "android.sensor.wrist_tilt_gesture"
644
Aravind Akella952471e2014-07-17 12:40:54 -0700645/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800646 * Values returned by the accelerometer in various locations in the universe.
647 * all values are in SI units (m/s^2)
648 */
649#define GRAVITY_SUN (275.0f)
650#define GRAVITY_EARTH (9.80665f)
651
652/** Maximum magnetic field on Earth's surface */
653#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
654
655/** Minimum magnetic field on Earth's surface */
656#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
657
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800658/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700659 * Possible values of the status field of sensor events.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800660 */
Etienne Le Grand7b361582014-05-16 11:08:28 -0700661#define SENSOR_STATUS_NO_CONTACT -1
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800662#define SENSOR_STATUS_UNRELIABLE 0
663#define SENSOR_STATUS_ACCURACY_LOW 1
664#define SENSOR_STATUS_ACCURACY_MEDIUM 2
665#define SENSOR_STATUS_ACCURACY_HIGH 3
666
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800667/**
668 * sensor event data
669 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800670typedef struct {
671 union {
672 float v[3];
673 struct {
674 float x;
675 float y;
676 float z;
677 };
678 struct {
679 float azimuth;
680 float pitch;
681 float roll;
682 };
683 };
684 int8_t status;
685 uint8_t reserved[3];
686} sensors_vec_t;
687
688/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800689 * uncalibrated gyroscope and magnetometer event data
690 */
691typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700692 union {
693 float uncalib[3];
694 struct {
695 float x_uncalib;
696 float y_uncalib;
697 float z_uncalib;
698 };
699 };
700 union {
701 float bias[3];
702 struct {
703 float x_bias;
704 float y_bias;
705 float z_bias;
706 };
707 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800708} uncalibrated_event_t;
709
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700710/**
711 * Meta data event data
712 */
Mathias Agopian16671c52013-07-24 21:07:40 -0700713typedef struct meta_data_event {
714 int32_t what;
715 int32_t sensor;
716} meta_data_event_t;
717
Etienne Le Grandca858142013-02-26 19:17:20 -0800718/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700719 * Heart rate event data
720 */
721typedef struct {
722 // Heart rate in beats per minute.
723 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
724 float bpm;
725 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700726 // Note that this value should only be set for sensors that explicitly define
727 // the meaning of this field. This field is not piped through the framework
728 // for other sensors.
Etienne Le Grand7b361582014-05-16 11:08:28 -0700729 int8_t status;
730} heart_rate_event_t;
731
732/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800733 * Union of the various types of sensor data
734 * that can be returned.
735 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700736typedef struct sensors_event_t {
737 /* must be sizeof(struct sensors_event_t) */
738 int32_t version;
739
740 /* sensor identifier */
741 int32_t sensor;
742
743 /* sensor type */
744 int32_t type;
745
746 /* reserved */
747 int32_t reserved0;
748
749 /* time is in nanosecond */
750 int64_t timestamp;
751
752 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700753 union {
754 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700755
Mathias Agopian27e16682013-07-08 14:00:54 -0700756 /* acceleration values are in meter per second per second (m/s^2) */
757 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700758
Mathias Agopian27e16682013-07-08 14:00:54 -0700759 /* magnetic vector values are in micro-Tesla (uT) */
760 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700761
Mathias Agopian27e16682013-07-08 14:00:54 -0700762 /* orientation values are in degrees */
763 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700764
Mathias Agopian27e16682013-07-08 14:00:54 -0700765 /* gyroscope values are in rad/s */
766 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700767
Mathias Agopian27e16682013-07-08 14:00:54 -0700768 /* temperature is in degrees centigrade (Celsius) */
769 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700770
Mathias Agopian27e16682013-07-08 14:00:54 -0700771 /* distance in centimeters */
772 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700773
Mathias Agopian27e16682013-07-08 14:00:54 -0700774 /* light in SI lux units */
775 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700776
Mathias Agopian27e16682013-07-08 14:00:54 -0700777 /* pressure in hectopascal (hPa) */
778 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100779
Mathias Agopian27e16682013-07-08 14:00:54 -0700780 /* relative humidity in percent */
781 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800782
Mathias Agopian27e16682013-07-08 14:00:54 -0700783 /* uncalibrated gyroscope values are in rad/s */
784 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800785
Mathias Agopian27e16682013-07-08 14:00:54 -0700786 /* uncalibrated magnetometer values are in micro-Teslas */
787 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700788
Etienne Le Grand7b361582014-05-16 11:08:28 -0700789 /* heart rate data containing value in bpm and status */
790 heart_rate_event_t heart_rate;
Aravind Akella477fbd52014-04-07 22:46:01 +0000791
Mathias Agopian16671c52013-07-24 21:07:40 -0700792 /* this is a special event. see SENSOR_TYPE_META_DATA above.
793 * sensors_meta_data_event_t events are all reported with a type of
794 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
795 */
796 meta_data_event_t meta_data;
Mathias Agopian27e16682013-07-08 14:00:54 -0700797 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800798
Mathias Agopian27e16682013-07-08 14:00:54 -0700799 union {
800 uint64_t data[8];
801
802 /* step-counter */
803 uint64_t step_counter;
804 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700805 };
Aravind Akella6242f322014-02-28 18:46:19 -0800806
807 /* Reserved flags for internal use. Set to zero. */
808 uint32_t flags;
809
810 uint32_t reserved1[3];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700811} sensors_event_t;
812
813
Mathias Agopian16671c52013-07-24 21:07:40 -0700814/* see SENSOR_TYPE_META_DATA */
815typedef sensors_event_t sensors_meta_data_event_t;
816
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700817
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800818struct sensor_t;
819
820/**
821 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
822 * and the fields of this data structure must begin with hw_module_t
823 * followed by module specific information.
824 */
825struct sensors_module_t {
826 struct hw_module_t common;
827
828 /**
829 * Enumerate all available sensors. The list is returned in "list".
830 * @return number of sensors in the list
831 */
832 int (*get_sensors_list)(struct sensors_module_t* module,
833 struct sensor_t const** list);
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700834
835 /**
836 * Place the module in a specific mode. The following modes are defined
837 *
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700838 * 0 - Normal operation. Default state of the module.
839 * 1 - Loopback mode. Data is injected for the the supported
840 * sensors by the sensor service in this mode.
841 * @return 0 on success
842 * -EINVAL if requested mode is not supported
843 * -EPERM if operation is not allowed
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700844 */
845 int (*set_operation_mode)(unsigned int mode);
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800846};
847
848struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800849
850 /* Name of this sensor.
851 * All sensors of the same "type" must have a different "name".
852 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800853 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800854
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800855 /* vendor of the hardware part */
856 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800857
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800858 /* version of the hardware part + driver. The value of this field
859 * must increase when the driver is updated in a way that changes the
860 * output of this sensor. This is important for fused sensors when the
861 * fusion algorithm is updated.
Aravind Akella6242f322014-02-28 18:46:19 -0800862 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800863 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800864
865 /* handle that identifies this sensors. This handle is used to reference
866 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800867 */
868 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800869
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800870 /* this sensor's type. */
871 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800872
873 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800874 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800875
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800876 /* smallest difference between two values reported by this sensor */
877 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800878
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800879 /* rough estimate of this sensor's power consumption in mA */
880 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800881
Aravind Akellac841efd2014-06-03 19:21:35 -0700882 /* this value depends on the reporting mode:
Mathias Agopiana4557722012-11-28 17:21:55 -0800883 *
884 * continuous: minimum sample period allowed in microseconds
885 * on-change : 0
886 * one-shot :-1
887 * special : 0, unless otherwise noted
888 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700889 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800890
Mathias Agopian16671c52013-07-24 21:07:40 -0700891 /* number of events reserved for this sensor in the batch mode FIFO.
892 * If there is a dedicated FIFO for this sensor, then this is the
893 * size of this FIFO. If the FIFO is shared with other sensors,
894 * this is the size reserved for that sensor and it can be zero.
895 */
896 uint32_t fifoReservedEventCount;
897
898 /* maximum number of events of this sensor that could be batched.
899 * This is especially relevant when the FIFO is shared between
900 * several sensors; this value is then set to the size of that FIFO.
901 */
902 uint32_t fifoMaxEventCount;
903
Aravind Akella477fbd52014-04-07 22:46:01 +0000904 /* type of this sensor as a string. Set to corresponding
905 * SENSOR_STRING_TYPE_*.
906 * When defining an OEM specific sensor or sensor manufacturer specific
907 * sensor, use your reserve domain name as a prefix.
908 * ex: com.google.glass.onheaddetector
909 * For sensors of known type, the android framework might overwrite this
910 * string automatically.
911 */
912 const char* stringType;
913
914 /* permission required to see this sensor, register to it and receive data.
915 * Set to "" if no permission is required. Some sensor types like the
916 * heart rate monitor have a mandatory require_permission.
917 * For sensors that always require a specific permission, like the heart
918 * rate monitor, the android framework might overwrite this string
919 * automatically.
920 */
921 const char* requiredPermission;
922
Aravind Akella110d2f22014-09-04 15:36:31 -0700923 /* This value is defined only for continuous mode and on-change sensors. It is the delay between
924 * two sensor events corresponding to the lowest frequency that this sensor supports. When lower
925 * frequencies are requested through batch()/setDelay() the events will be generated at this
926 * frequency instead. It can be used by the framework or applications to estimate when the batch
927 * FIFO may be full.
Aravind Akellac841efd2014-06-03 19:21:35 -0700928 *
929 * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
Aravind Akella110d2f22014-09-04 15:36:31 -0700930 * continuous, on-change: maximum sampling period allowed in microseconds.
931 * one-shot, special : 0
Aravind Akellac841efd2014-06-03 19:21:35 -0700932 * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit
933 * on 64 bit architectures only for binary compatibility reasons.
Aravind Akella6242f322014-02-28 18:46:19 -0800934 * Availability: SENSORS_DEVICE_API_VERSION_1_3
935 */
936 #ifdef __LP64__
937 int64_t maxDelay;
938 #else
939 int32_t maxDelay;
940 #endif
941
Aravind Akellac841efd2014-06-03 19:21:35 -0700942 /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.
943 * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.
944 * Availability: SENSORS_DEVICE_API_VERSION_1_3
945 */
Aravind Akella6242f322014-02-28 18:46:19 -0800946 #ifdef __LP64__
947 uint64_t flags;
948 #else
949 uint32_t flags;
950 #endif
951
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800952 /* reserved fields, must be zero */
Aravind Akella6242f322014-02-28 18:46:19 -0800953 void* reserved[2];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800954};
955
956
Mathias Agopiana4557722012-11-28 17:21:55 -0800957/*
958 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
959 * and is present for backward binary and source compatibility.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800960 * See the Sensors HAL interface section for complete descriptions of the
961 * following functions:
962 * http://source.android.com/devices/sensors/index.html#hal
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800963 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700964struct sensors_poll_device_t {
965 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700966 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700967 int sensor_handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700968 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700969 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700970 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700971 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700972};
973
Mathias Agopiana4557722012-11-28 17:21:55 -0800974/*
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700975 * struct sensors_poll_device_1 is used in HAL versions >= SENSORS_DEVICE_API_VERSION_1_0
Mathias Agopiana4557722012-11-28 17:21:55 -0800976 */
977typedef struct sensors_poll_device_1 {
978 union {
979 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
980 * and can be down-cast to it
981 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800982 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -0800983
984 struct {
985 struct hw_device_t common;
986
Clay Murphy8db1fb42013-12-19 09:58:28 -0800987 /* Activate/de-activate one sensor. Return 0 on success, negative
Mathias Agopiana4557722012-11-28 17:21:55 -0800988 *
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700989 * sensor_handle is the handle of the sensor to change.
Mathias Agopiana4557722012-11-28 17:21:55 -0800990 * enabled set to 1 to enable, or 0 to disable the sensor.
991 *
Clay Murphy8db1fb42013-12-19 09:58:28 -0800992 * Return 0 on success, negative errno code otherwise.
Mathias Agopiana4557722012-11-28 17:21:55 -0800993 */
994 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700995 int sensor_handle, int enabled);
Mathias Agopiana4557722012-11-28 17:21:55 -0800996
997 /**
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700998 * Set the events's period in nanoseconds for a given sensor.
999 * If sampling_period_ns > max_delay it will be truncated to
1000 * max_delay and if sampling_period_ns < min_delay it will be
1001 * replaced by min_delay.
Mathias Agopiana4557722012-11-28 17:21:55 -08001002 */
1003 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001004 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -08001005
1006 /**
1007 * Returns an array of sensor data.
Mathias Agopiana4557722012-11-28 17:21:55 -08001008 */
1009 int (*poll)(struct sensors_poll_device_t *dev,
1010 sensors_event_t* data, int count);
1011 };
1012 };
1013
Mathias Agopiana4557722012-11-28 17:21:55 -08001014
1015 /*
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001016 * Sets a sensor’s parameters, including sampling frequency and maximum
1017 * report latency. This function can be called while the sensor is
1018 * activated, in which case it must not cause any sensor measurements to
1019 * be lost: transitioning from one sampling rate to the other cannot cause
1020 * lost events, nor can transitioning from a high maximum report latency to
1021 * a low maximum report latency.
Clay Murphy8db1fb42013-12-19 09:58:28 -08001022 * See the Batching sensor results page for details:
1023 * http://source.android.com/devices/sensors/batching.html
Mathias Agopiana4557722012-11-28 17:21:55 -08001024 */
1025 int (*batch)(struct sensors_poll_device_1* dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001026 int sensor_handle, int flags, int64_t sampling_period_ns,
1027 int64_t max_report_latency_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -08001028
Mathias Agopian16671c52013-07-24 21:07:40 -07001029 /*
1030 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
1031 * to the end of the "batch mode" FIFO for the specified sensor and flushes
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001032 * the FIFO.
1033 * If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero),
Aravind Akellac841efd2014-06-03 19:21:35 -07001034 * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001035 * event stream. This applies to all sensors other than one-shot sensors.
1036 * If the sensor is a one-shot sensor, flush must return -EINVAL and not generate
1037 * any flush complete metadata.
Aravind Akellaa7f2cda2014-08-21 16:31:14 -07001038 * If the sensor is not active at the time flush() is called, flush() should return
1039 * -EINVAL.
Mathias Agopian16671c52013-07-24 21:07:40 -07001040 */
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001041 int (*flush)(struct sensors_poll_device_1* dev, int sensor_handle);
Mathias Agopian16671c52013-07-24 21:07:40 -07001042
Ashutosh Joshi6507f502015-04-03 16:22:32 -07001043 /*
Ashutosh Joshi050f2e42015-04-15 13:56:53 -07001044 * Inject a single sensor sample to be to this device.
1045 * data points to the sensor event to be injected
1046 * @return 0 on success
1047 * -EPERM if operation is not allowed
1048 * -EINVAL if sensor event cannot be injected
Ashutosh Joshi6507f502015-04-03 16:22:32 -07001049 */
1050 int (*inject_sensor_data)(struct sensors_poll_device_1 *dev, const sensors_event_t *data);
1051
1052 void (*reserved_procs[7])(void);
Mathias Agopiana4557722012-11-28 17:21:55 -08001053
1054} sensors_poll_device_1_t;
1055
1056
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001057/** convenience API for opening and closing a device */
1058
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001059static inline int sensors_open(const struct hw_module_t* module,
1060 struct sensors_poll_device_t** device) {
1061 return module->methods->open(module,
1062 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1063}
1064
1065static inline int sensors_close(struct sensors_poll_device_t* device) {
1066 return device->common.close(&device->common);
1067}
1068
Mathias Agopiana4557722012-11-28 17:21:55 -08001069static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001070 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001071 return module->methods->open(module,
1072 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1073}
1074
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001075static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001076 return device->common.close(&device->common);
1077}
1078
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001079__END_DECLS
1080
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001081#endif // ANDROID_SENSORS_INTERFACE_H