blob: e917c0a8502c5fe79fae9be76a939eb370bec25c [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 /*
Aravind Akella110d2f22014-09-04 15:36:31 -0700101 * Whether this sensor wakes up the AP from suspend mode when data is available. Whenever
102 * sensor events are delivered from a wake_up sensor, the driver needs to hold a wake_lock till
103 * the events are read by the SensorService i.e till sensors_poll_device_t.poll() is called the
104 * next time. Once poll is called again it means events have been read by the SensorService, the
105 * driver can safely release the wake_lock. SensorService will continue to hold a wake_lock till
106 * the app actually reads the events.
Aravind Akella6242f322014-02-28 18:46:19 -0800107 */
Aravind Akellac841efd2014-06-03 19:21:35 -0700108 SENSOR_FLAG_WAKE_UP = 1U << 0,
109 /*
110 * Reporting modes for various sensors. Each sensor will have exactly one of these modes set.
111 * The least significant 2nd, 3rd and 4th bits are used to represent four possible reporting
112 * modes.
113 */
114 SENSOR_FLAG_CONTINUOUS_MODE = 0, // 0000
115 SENSOR_FLAG_ON_CHANGE_MODE = 0x2, // 0010
116 SENSOR_FLAG_ONE_SHOT_MODE = 0x4, // 0100
117 SENSOR_FLAG_SPECIAL_REPORTING_MODE = 0x6 // 0110
Aravind Akella6242f322014-02-28 18:46:19 -0800118};
119
120/*
Aravind Akellac841efd2014-06-03 19:21:35 -0700121 * Mask and shift for reporting mode sensor flags defined above.
122 */
123#define REPORTING_MODE_MASK (0xE)
124#define REPORTING_MODE_SHIFT (1)
125
126/*
Mathias Agopiana4557722012-11-28 17:21:55 -0800127 * Sensor type
128 *
129 * Each sensor has a type which defines what this sensor measures and how
Clay Murphy8db1fb42013-12-19 09:58:28 -0800130 * measures are reported. See the Base sensors and Composite sensors lists
131 * for complete descriptions:
132 * http://source.android.com/devices/sensors/base_triggers.html
133 * http://source.android.com/devices/sensors/composite_sensors.html
Mathias Agopian1599ec62013-08-19 14:34:47 -0700134 *
135 * Device manufacturers (OEMs) can define their own sensor types, for
136 * their private use by applications or services provided by them. Such
137 * sensor types are specific to an OEM and can't be exposed in the SDK.
138 * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE.
Aravind Akella477fbd52014-04-07 22:46:01 +0000139 *
140 * All sensors defined outside of the device private range must correspond to
141 * a type defined in this file, and must satisfy the characteristics listed in
142 * the description of the sensor type.
143 *
144 * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also
145 * has a stringType.
146 * - StringType of sensors inside of the device private range MUST be prefixed
147 * by the sensor provider's or OEM reverse domain name. In particular, they
148 * cannot use the "android.sensor" prefix.
149 * - StringType of sensors outside of the device private range MUST correspond
150 * to the one defined in this file (starting with "android.sensor").
151 * For example, accelerometers must have
152 * type=SENSOR_TYPE_ACCELEROMETER and
153 * stringType=SENSOR_STRING_TYPE_ACCELEROMETER
154 *
155 * When android introduces a new sensor type that can replace an OEM-defined
156 * sensor type, the OEM must use the official sensor type and stringType on
157 * versions of the HAL that support this new official sensor type.
158 *
159 * Example (made up): Suppose Google's Glass team wants to surface a sensor
160 * detecting that Glass is on a head.
161 * - Such a sensor is not officially supported in android KitKat
162 * - Glass devices launching on KitKat can implement a sensor with
163 * type = 0x10001 and stringType = "com.google.glass.onheaddetector"
164 * - In L android release, if android decides to define
165 * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR,
166 * those types should replace the Glass-team-specific types in all future
167 * launches.
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700168 * - When launching Glass on the L release, Google should now use the official
Aravind Akella477fbd52014-04-07 22:46:01 +0000169 * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType.
170 * - This way, all applications can now use this sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800171 */
172
173/*
Mathias Agopian1599ec62013-08-19 14:34:47 -0700174 * Base for device manufacturers private sensor types.
175 * These sensor types can't be exposed in the SDK.
176 */
177#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000
178
179/*
Mathias Agopian16671c52013-07-24 21:07:40 -0700180 * SENSOR_TYPE_META_DATA
Aravind Akellac841efd2014-06-03 19:21:35 -0700181 * reporting-mode: n/a
Mathias Agopian16671c52013-07-24 21:07:40 -0700182 * wake-up sensor: n/a
183 *
184 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
185 *
186 * SENSOR_TYPE_META_DATA is a special token used to populate the
187 * sensors_meta_data_event structure. It doesn't correspond to a physical
188 * sensor. sensors_meta_data_event are special, they exist only inside
189 * the HAL and are generated spontaneously, as opposed to be related to
190 * a physical sensor.
191 *
Mathias Agopianaf32a8d2013-08-06 20:33:38 -0700192 * sensors_meta_data_event_t.version must be META_DATA_VERSION
193 * sensors_meta_data_event_t.sensor must be 0
194 * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
195 * sensors_meta_data_event_t.reserved must be 0
196 * sensors_meta_data_event_t.timestamp must be 0
Mathias Agopian16671c52013-07-24 21:07:40 -0700197 *
198 * The payload is a meta_data_event_t, where:
199 * meta_data_event_t.what can take the following values:
200 *
201 * META_DATA_FLUSH_COMPLETE
202 * This event indicates that a previous (*flush)() call has completed for the sensor
203 * handle specified in meta_data_event_t.sensor.
204 * see (*flush)() for more details
205 *
206 * All other values for meta_data_event_t.what are reserved and
207 * must not be used.
208 *
209 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000210#define SENSOR_TYPE_META_DATA (0)
Mathias Agopian16671c52013-07-24 21:07:40 -0700211
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800212/*
Aravind Akella9057e122014-07-28 18:01:37 -0700213 * Wake up sensors.
214 * Each sensor may have either or both a wake-up and a non-wake variant.
215 * When registered in batch mode, wake-up sensors will wake up the AP when
216 * their FIFOs are full or when the batch timeout expires. A separate FIFO has
217 * to be maintained for wake up sensors and non wake up sensors. The non wake-up
218 * sensors need to overwrite their FIFOs when they are full till the AP wakes up
219 * and the wake-up sensors will wake-up the AP when their FIFOs are full or when
220 * the batch timeout expires without losing events. Wake-up and non wake-up variants
221 * of each sensor can be activated at different rates independently of each other.
222 *
223 * Note: Proximity sensor and significant motion sensor which were defined in previous
224 * releases are also wake-up sensors and should be treated as such. Wake-up one-shot
225 * sensors like SIGNIFICANT_MOTION cannot be batched, hence the text about batch above
226 * doesn't apply to them. See the definitions of SENSOR_TYPE_PROXIMITY and
227 * SENSOR_TYPE_SIGNIFICANT_MOTION for more info.
228 *
229 * Set SENSOR_FLAG_WAKE_UP flag for all wake-up sensors.
230 *
231 * For example, A device can have two sensors both of SENSOR_TYPE_ACCELEROMETER and
232 * one of them can be a wake_up sensor (with SENSOR_FLAG_WAKE_UP flag set) and the other
233 * can be a regular non wake_up sensor. Both of these sensors must be activated/deactivated
234 * independently of the other.
235 */
236
237/*
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800238 * SENSOR_TYPE_ACCELEROMETER
Aravind Akellac841efd2014-06-03 19:21:35 -0700239 * reporting-mode: continuous
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800240 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800241 * All values are in SI units (m/s^2) and measure the acceleration of the
242 * device minus the force of gravity.
243 *
Aravind Akella9057e122014-07-28 18:01:37 -0700244 * Implement the non-wake-up version of this sensor and implement the wake-up
245 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800246 */
247#define SENSOR_TYPE_ACCELEROMETER (1)
Aravind Akella477fbd52014-04-07 22:46:01 +0000248#define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800249
250/*
251 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akellac841efd2014-06-03 19:21:35 -0700252 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800253 *
254 * All values are in micro-Tesla (uT) and measure the geomagnetic
255 * field in the X, Y and Z axis.
256 *
Aravind Akella9057e122014-07-28 18:01:37 -0700257 * Implement the non-wake-up version of this sensor and implement the wake-up
258 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800259 */
260#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
261#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akella477fbd52014-04-07 22:46:01 +0000262#define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800263
264/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800265 * SENSOR_TYPE_ORIENTATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700266 * reporting-mode: continuous
Clay Murphy8db1fb42013-12-19 09:58:28 -0800267 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800268 * All values are angles in degrees.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800269 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700270 * Orientation sensors return sensor events for all 3 axes at a constant
271 * rate defined by setDelay().
Aravind Akella9057e122014-07-28 18:01:37 -0700272 *
273 * Implement the non-wake-up version of this sensor and implement the wake-up
274 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800275 */
276#define SENSOR_TYPE_ORIENTATION (3)
Aravind Akella477fbd52014-04-07 22:46:01 +0000277#define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800278
279/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800280 * SENSOR_TYPE_GYROSCOPE
Aravind Akellac841efd2014-06-03 19:21:35 -0700281 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800282 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700283 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800284 * around the X, Y and Z axis.
Aravind Akella9057e122014-07-28 18:01:37 -0700285 *
286 * Implement the non-wake-up version of this sensor and implement the wake-up
287 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800288 */
289#define SENSOR_TYPE_GYROSCOPE (4)
Aravind Akella477fbd52014-04-07 22:46:01 +0000290#define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800291
292/*
293 * SENSOR_TYPE_LIGHT
Aravind Akellac841efd2014-06-03 19:21:35 -0700294 * reporting-mode: on-change
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800295 *
296 * The light sensor value is returned in SI lux units.
Aravind Akella9057e122014-07-28 18:01:37 -0700297 *
298 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800299 */
300#define SENSOR_TYPE_LIGHT (5)
Aravind Akella477fbd52014-04-07 22:46:01 +0000301#define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800302
303/*
304 * SENSOR_TYPE_PRESSURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700305 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800306 *
307 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Aravind Akella9057e122014-07-28 18:01:37 -0700308 *
309 * Implement the non-wake-up version of this sensor and implement the wake-up
310 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800311 */
312#define SENSOR_TYPE_PRESSURE (6)
Aravind Akella477fbd52014-04-07 22:46:01 +0000313#define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800314
315/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
316#define SENSOR_TYPE_TEMPERATURE (7)
Aravind Akella477fbd52014-04-07 22:46:01 +0000317#define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800318
319/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800320 * SENSOR_TYPE_PROXIMITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700321 * reporting-mode: on-change
Mike Lockwooda2414312009-11-03 10:29:50 -0500322 *
Aravind Akella9057e122014-07-28 18:01:37 -0700323 * The proximity sensor which turns the screen off and back on during calls is the
324 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
325 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
326 * SENSOR_FLAG_WAKE_UP.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800327 * The value corresponds to the distance to the nearest object in centimeters.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800328 */
329#define SENSOR_TYPE_PROXIMITY (8)
Aravind Akella477fbd52014-04-07 22:46:01 +0000330#define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800331
332/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800333 * SENSOR_TYPE_GRAVITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700334 * reporting-mode: continuous
Mathias Agopian42b743c2010-11-22 15:55:32 -0800335 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800336 * A gravity output indicates the direction of and magnitude of gravity in
Clay Murphy8db1fb42013-12-19 09:58:28 -0800337 * the devices's coordinates.
Aravind Akella9057e122014-07-28 18:01:37 -0700338 *
339 * Implement the non-wake-up version of this sensor and implement the wake-up
340 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800341 */
342#define SENSOR_TYPE_GRAVITY (9)
Aravind Akella477fbd52014-04-07 22:46:01 +0000343#define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800344
345/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800346 * SENSOR_TYPE_LINEAR_ACCELERATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700347 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800348 *
349 * Indicates the linear acceleration of the device in device coordinates,
350 * not including gravity.
Aravind Akella9057e122014-07-28 18:01:37 -0700351 *
352 * Implement the non-wake-up version of this sensor and implement the wake-up
353 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800354 */
355#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
Aravind Akella477fbd52014-04-07 22:46:01 +0000356#define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800357
358
359/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800360 * SENSOR_TYPE_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700361 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800362 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700363 * The rotation vector symbolizes the orientation of the device relative to the
Clay Murphy8db1fb42013-12-19 09:58:28 -0800364 * East-North-Up coordinates frame.
Aravind Akella9057e122014-07-28 18:01:37 -0700365 *
366 * Implement the non-wake-up version of this sensor and implement the wake-up
367 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800368 */
369#define SENSOR_TYPE_ROTATION_VECTOR (11)
Aravind Akella477fbd52014-04-07 22:46:01 +0000370#define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800371
372/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800373 * SENSOR_TYPE_RELATIVE_HUMIDITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700374 * reporting-mode: on-change
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100375 *
376 * A relative humidity sensor measures relative ambient air humidity and
377 * returns a value in percent.
Aravind Akella9057e122014-07-28 18:01:37 -0700378 *
379 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800380 */
381#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
Aravind Akella477fbd52014-04-07 22:46:01 +0000382#define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800383
384/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800385 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700386 * reporting-mode: on-change
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700387 *
388 * The ambient (room) temperature in degree Celsius.
Aravind Akella9057e122014-07-28 18:01:37 -0700389 *
390 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800391 */
392#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
Aravind Akella477fbd52014-04-07 22:46:01 +0000393#define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800394
395/*
396 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700397 * reporting-mode: continuous
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700398 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800399 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
400 * reported separately instead of being included in the measurement.
Aravind Akella9057e122014-07-28 18:01:37 -0700401 *
402 * Implement the non-wake-up version of this sensor and implement the wake-up
403 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800404 */
405#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
Aravind Akella477fbd52014-04-07 22:46:01 +0000406#define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800407
408/*
409 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700410 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800411 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800412 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
Clay Murphy8db1fb42013-12-19 09:58:28 -0800413 * field.
Aravind Akella9057e122014-07-28 18:01:37 -0700414 *
415 * Implement the non-wake-up version of this sensor and implement the wake-up
416 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800417 */
418#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
Aravind Akella477fbd52014-04-07 22:46:01 +0000419#define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800420
421/*
422 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700423 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800424 *
425 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800426 * around the X, Y and Z axis.
Aravind Akella9057e122014-07-28 18:01:37 -0700427 *
428 * Implement the non-wake-up version of this sensor and implement the wake-up
429 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800430 */
431#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
Aravind Akella477fbd52014-04-07 22:46:01 +0000432#define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800433
Mathias Agopiana4557722012-11-28 17:21:55 -0800434/*
435 * SENSOR_TYPE_SIGNIFICANT_MOTION
Aravind Akellac841efd2014-06-03 19:21:35 -0700436 * reporting-mode: one-shot
Mathias Agopiana4557722012-11-28 17:21:55 -0800437 *
438 * A sensor of this type triggers an event each time significant motion
439 * is detected and automatically disables itself.
Aravind Akella9057e122014-07-28 18:01:37 -0700440 * For Significant Motion sensor to be useful, it must be defined as a
441 * wake-up sensor. (set SENSOR_FLAG_WAKE_UP). Implement the wake-up significant motion
442 * sensor. A non wake-up version is not useful.
Mathias Agopiana4557722012-11-28 17:21:55 -0800443 * The only allowed value to return is 1.0.
Mathias Agopiana4557722012-11-28 17:21:55 -0800444 */
445
446#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
Aravind Akella477fbd52014-04-07 22:46:01 +0000447#define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
Mathias Agopiana4557722012-11-28 17:21:55 -0800448
449/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800450 * SENSOR_TYPE_STEP_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700451 * reporting-mode: special
Mathias Agopiana4557722012-11-28 17:21:55 -0800452 *
453 * A sensor of this type triggers an event each time a step is taken
Clay Murphy8db1fb42013-12-19 09:58:28 -0800454 * by the user. The only allowed value to return is 1.0 and an event
455 * is generated for each step.
Aravind Akella9057e122014-07-28 18:01:37 -0700456 *
457 * Both wake-up and non wake-up versions are useful.
Mathias Agopiana4557722012-11-28 17:21:55 -0800458 */
459
Mathias Agopian2f276f52013-01-28 17:54:41 -0800460#define SENSOR_TYPE_STEP_DETECTOR (18)
Aravind Akella477fbd52014-04-07 22:46:01 +0000461#define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
Mathias Agopiana4557722012-11-28 17:21:55 -0800462
463
464/*
465 * SENSOR_TYPE_STEP_COUNTER
Aravind Akellac841efd2014-06-03 19:21:35 -0700466 * reporting-mode: on-change
Mathias Agopiana4557722012-11-28 17:21:55 -0800467 *
468 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800469 * the last reboot while activated. The value is returned as a uint64_t and is
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700470 * reset to zero only on a system / android reboot.
Aravind Akella9057e122014-07-28 18:01:37 -0700471 *
472 * Implement the non-wake-up version of this sensor and implement the wake-up
473 * version if the system possesses a wake up fifo.
Mathias Agopiana4557722012-11-28 17:21:55 -0800474 */
475
476#define SENSOR_TYPE_STEP_COUNTER (19)
Aravind Akella477fbd52014-04-07 22:46:01 +0000477#define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
Mathias Agopiana4557722012-11-28 17:21:55 -0800478
Etienne Le Grandca858142013-02-26 19:17:20 -0800479/*
480 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700481 * reporting-mode: continuous
Etienne Le Grandca858142013-02-26 19:17:20 -0800482 *
483 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
484 * of using a gyroscope.
Aravind Akella9057e122014-07-28 18:01:37 -0700485 *
486 * Implement the non-wake-up version of this sensor and implement the wake-up
487 * version if the system possesses a wake up fifo.
Etienne Le Grandca858142013-02-26 19:17:20 -0800488 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000489#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
490#define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
491
492/*
493 * SENSOR_TYPE_HEART_RATE
Aravind Akellac841efd2014-06-03 19:21:35 -0700494 * reporting-mode: on-change
Aravind Akella477fbd52014-04-07 22:46:01 +0000495 *
Etienne Le Grand7b361582014-05-16 11:08:28 -0700496 * A sensor of this type returns the current heart rate.
497 * The events contain the current heart rate in beats per minute (BPM) and the
498 * status of the sensor during the measurement. See heart_rate_event_t for more
499 * details.
500 *
501 * Because this sensor is on-change, events must be generated when and only
502 * when heart_rate.bpm or heart_rate.status have changed since the last
Vinod Krishnan74279e32014-08-28 15:25:13 -0700503 * event. In particular, upon the first activation, unless the device is known
504 * to not be on the body, the status field of the first event must be set to
505 * SENSOR_STATUS_UNRELIABLE. The event should be generated no faster than every
506 * period_ns passed to setDelay() or to batch().
Griff Hazenf0f67e62014-08-28 17:02:50 -0700507 * See the definition of the on-change reporting mode for more information.
Etienne Le Grand7b361582014-05-16 11:08:28 -0700508 *
Aravind Akella477fbd52014-04-07 22:46:01 +0000509 * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
Aravind Akella9057e122014-07-28 18:01:37 -0700510 *
511 * Both wake-up and non wake-up versions are useful.
Aravind Akella477fbd52014-04-07 22:46:01 +0000512 */
513#define SENSOR_TYPE_HEART_RATE (21)
514#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
Mathias Agopiana4557722012-11-28 17:21:55 -0800515
Aravind Akella6242f322014-02-28 18:46:19 -0800516/*
Aravind Akellaf895c682014-04-30 11:46:09 -0700517 * SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700518 * reporting-mode: special (setDelay has no impact)
Aravind Akellaf895c682014-04-30 11:46:09 -0700519 *
520 * A sensor of this type generates an event each time a tilt event is detected. A tilt event
521 * 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 -0700522 * 35 degrees since the activation or the last trigger of the sensor.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700523 * reference_estimated_gravity = average of accelerometer measurements over the first
Etienne Le Grand53017ef2014-05-28 15:42:48 -0700524 * 1 second after activation or the estimated gravity at the last
525 * trigger.
Aravind Akellaf895c682014-04-30 11:46:09 -0700526 * current_estimated_gravity = average of accelerometer measurements over the last 2 seconds.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700527 * trigger when angle (reference_estimated_gravity, current_estimated_gravity) > 35 degrees
Aravind Akellaf895c682014-04-30 11:46:09 -0700528 *
529 * Large accelerations without a change in phone orientation should not trigger a tilt event.
530 * For example, a sharp turn or strong acceleration while driving a car should not trigger a tilt
531 * event, even though the angle of the average acceleration might vary by more than 35 degrees.
532 *
533 * Typically, this sensor is implemented with the help of only an accelerometer. Other sensors can
534 * be used as well if they do not increase the power consumption significantly. This is a low power
535 * sensor that should allow the AP to go into suspend mode. Do not emulate this sensor in the HAL.
536 * Like other wake up sensors, the driver is expected to a hold a wake_lock with a timeout of 200 ms
537 * while reporting this event. The only allowed return value is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700538 *
539 * Implement only the wake-up version of this sensor.
Aravind Akellaf895c682014-04-30 11:46:09 -0700540 */
Aravind Akella9057e122014-07-28 18:01:37 -0700541#define SENSOR_TYPE_TILT_DETECTOR (22)
542#define SENSOR_STRING_TYPE_TILT_DETECTOR "android.sensor.tilt_detector"
Aravind Akellaf895c682014-04-30 11:46:09 -0700543
Etienne Le Grandba123122014-05-05 18:20:42 -0700544/*
545 * SENSOR_TYPE_WAKE_GESTURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700546 * reporting-mode: one-shot
Etienne Le Grandba123122014-05-05 18:20:42 -0700547 *
548 * A sensor enabling waking up the device based on a device specific motion.
549 *
550 * When this sensor triggers, the device behaves as if the power button was
551 * pressed, turning the screen on. This behavior (turning on the screen when
552 * this sensor triggers) might be deactivated by the user in the device
553 * settings. Changes in settings do not impact the behavior of the sensor:
554 * only whether the framework turns the screen on when it triggers.
555 *
556 * The actual gesture to be detected is not specified, and can be chosen by
557 * the manufacturer of the device.
558 * This sensor must be low power, as it is likely to be activated 24/7.
559 * The only allowed value to return is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700560 *
561 * Implement only the wake-up version of this sensor.
Etienne Le Grandba123122014-05-05 18:20:42 -0700562 */
Aravind Akella9057e122014-07-28 18:01:37 -0700563#define SENSOR_TYPE_WAKE_GESTURE (23)
Etienne Le Grandba123122014-05-05 18:20:42 -0700564#define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture"
565
Jeff Brown8df2feb2014-07-17 15:11:51 -0700566/*
567 * SENSOR_TYPE_GLANCE_GESTURE
568 * reporting-mode: one-shot
Jeff Brown8df2feb2014-07-17 15:11:51 -0700569 *
570 * A sensor enabling briefly turning the screen on to enable the user to
571 * glance content on screen based on a specific motion. The device should
572 * turn the screen off after a few moments.
573 *
574 * When this sensor triggers, the device turns the screen on momentarily
575 * to allow the user to glance notifications or other content while the
576 * device remains locked in a non-interactive state (dozing). This behavior
577 * (briefly turning on the screen when this sensor triggers) might be deactivated
578 * by the user in the device settings. Changes in settings do not impact the
579 * behavior of the sensor: only whether the framework briefly turns the screen on
580 * when it triggers.
581 *
582 * The actual gesture to be detected is not specified, and can be chosen by
583 * the manufacturer of the device.
584 * This sensor must be low power, as it is likely to be activated 24/7.
585 * The only allowed value to return is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700586 *
587 * Implement only the wake-up version of this sensor.
Jeff Brown8df2feb2014-07-17 15:11:51 -0700588 */
Aravind Akella9057e122014-07-28 18:01:37 -0700589#define SENSOR_TYPE_GLANCE_GESTURE (24)
Jeff Brown8df2feb2014-07-17 15:11:51 -0700590#define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture"
591
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800592/**
Aravind Akella952471e2014-07-17 12:40:54 -0700593 * SENSOR_TYPE_PICK_UP_GESTURE
594 * reporting-mode: one-shot
Aravind Akella952471e2014-07-17 12:40:54 -0700595 *
596 * A sensor of this type triggers when the device is picked up regardless of wherever is was
597 * before (desk, pocket, bag). The only allowed return value is 1.0.
598 * This sensor de-activates itself immediately after it triggers.
Aravind Akella9057e122014-07-28 18:01:37 -0700599 *
600 * Implement only the wake-up version of this sensor.
Aravind Akella952471e2014-07-17 12:40:54 -0700601 */
Aravind Akella9057e122014-07-28 18:01:37 -0700602#define SENSOR_TYPE_PICK_UP_GESTURE (25)
Aravind Akella952471e2014-07-17 12:40:54 -0700603#define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture"
604
Nick Vaccaroadbfbb72015-01-13 12:14:28 -0800605/*
606 * SENSOR_TYPE_WRIST_TILT_GESTURE
607 * trigger-mode: special
608 * wake-up sensor: yes
609 *
610 * A sensor of this type triggers an event each time a tilt of the wrist-worn
611 * device is detected.
612 *
613 * This sensor must be low power, as it is likely to be activated 24/7.
614 * The only allowed value to return is 1.0.
615 *
616 * Implement only the wake-up version of this sensor.
617 */
618#define SENSOR_TYPE_WRIST_TILT_GESTURE (26)
619#define SENSOR_STRING_TYPE_WRIST_TILT_GESTURE "android.sensor.wrist_tilt_gesture"
620
Aravind Akella952471e2014-07-17 12:40:54 -0700621/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800622 * Values returned by the accelerometer in various locations in the universe.
623 * all values are in SI units (m/s^2)
624 */
625#define GRAVITY_SUN (275.0f)
626#define GRAVITY_EARTH (9.80665f)
627
628/** Maximum magnetic field on Earth's surface */
629#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
630
631/** Minimum magnetic field on Earth's surface */
632#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
633
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800634/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700635 * Possible values of the status field of sensor events.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800636 */
Etienne Le Grand7b361582014-05-16 11:08:28 -0700637#define SENSOR_STATUS_NO_CONTACT -1
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800638#define SENSOR_STATUS_UNRELIABLE 0
639#define SENSOR_STATUS_ACCURACY_LOW 1
640#define SENSOR_STATUS_ACCURACY_MEDIUM 2
641#define SENSOR_STATUS_ACCURACY_HIGH 3
642
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800643/**
644 * sensor event data
645 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800646typedef struct {
647 union {
648 float v[3];
649 struct {
650 float x;
651 float y;
652 float z;
653 };
654 struct {
655 float azimuth;
656 float pitch;
657 float roll;
658 };
659 };
660 int8_t status;
661 uint8_t reserved[3];
662} sensors_vec_t;
663
664/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800665 * uncalibrated gyroscope and magnetometer event data
666 */
667typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700668 union {
669 float uncalib[3];
670 struct {
671 float x_uncalib;
672 float y_uncalib;
673 float z_uncalib;
674 };
675 };
676 union {
677 float bias[3];
678 struct {
679 float x_bias;
680 float y_bias;
681 float z_bias;
682 };
683 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800684} uncalibrated_event_t;
685
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700686/**
687 * Meta data event data
688 */
Mathias Agopian16671c52013-07-24 21:07:40 -0700689typedef struct meta_data_event {
690 int32_t what;
691 int32_t sensor;
692} meta_data_event_t;
693
Etienne Le Grandca858142013-02-26 19:17:20 -0800694/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700695 * Heart rate event data
696 */
697typedef struct {
698 // Heart rate in beats per minute.
699 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
700 float bpm;
701 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700702 // Note that this value should only be set for sensors that explicitly define
703 // the meaning of this field. This field is not piped through the framework
704 // for other sensors.
Etienne Le Grand7b361582014-05-16 11:08:28 -0700705 int8_t status;
706} heart_rate_event_t;
707
708/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800709 * Union of the various types of sensor data
710 * that can be returned.
711 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700712typedef struct sensors_event_t {
713 /* must be sizeof(struct sensors_event_t) */
714 int32_t version;
715
716 /* sensor identifier */
717 int32_t sensor;
718
719 /* sensor type */
720 int32_t type;
721
722 /* reserved */
723 int32_t reserved0;
724
725 /* time is in nanosecond */
726 int64_t timestamp;
727
728 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700729 union {
730 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700731
Mathias Agopian27e16682013-07-08 14:00:54 -0700732 /* acceleration values are in meter per second per second (m/s^2) */
733 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700734
Mathias Agopian27e16682013-07-08 14:00:54 -0700735 /* magnetic vector values are in micro-Tesla (uT) */
736 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700737
Mathias Agopian27e16682013-07-08 14:00:54 -0700738 /* orientation values are in degrees */
739 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700740
Mathias Agopian27e16682013-07-08 14:00:54 -0700741 /* gyroscope values are in rad/s */
742 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700743
Mathias Agopian27e16682013-07-08 14:00:54 -0700744 /* temperature is in degrees centigrade (Celsius) */
745 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700746
Mathias Agopian27e16682013-07-08 14:00:54 -0700747 /* distance in centimeters */
748 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700749
Mathias Agopian27e16682013-07-08 14:00:54 -0700750 /* light in SI lux units */
751 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700752
Mathias Agopian27e16682013-07-08 14:00:54 -0700753 /* pressure in hectopascal (hPa) */
754 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100755
Mathias Agopian27e16682013-07-08 14:00:54 -0700756 /* relative humidity in percent */
757 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800758
Mathias Agopian27e16682013-07-08 14:00:54 -0700759 /* uncalibrated gyroscope values are in rad/s */
760 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800761
Mathias Agopian27e16682013-07-08 14:00:54 -0700762 /* uncalibrated magnetometer values are in micro-Teslas */
763 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700764
Etienne Le Grand7b361582014-05-16 11:08:28 -0700765 /* heart rate data containing value in bpm and status */
766 heart_rate_event_t heart_rate;
Aravind Akella477fbd52014-04-07 22:46:01 +0000767
Mathias Agopian16671c52013-07-24 21:07:40 -0700768 /* this is a special event. see SENSOR_TYPE_META_DATA above.
769 * sensors_meta_data_event_t events are all reported with a type of
770 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
771 */
772 meta_data_event_t meta_data;
Mathias Agopian27e16682013-07-08 14:00:54 -0700773 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800774
Mathias Agopian27e16682013-07-08 14:00:54 -0700775 union {
776 uint64_t data[8];
777
778 /* step-counter */
779 uint64_t step_counter;
780 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700781 };
Aravind Akella6242f322014-02-28 18:46:19 -0800782
783 /* Reserved flags for internal use. Set to zero. */
784 uint32_t flags;
785
786 uint32_t reserved1[3];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700787} sensors_event_t;
788
789
Mathias Agopian16671c52013-07-24 21:07:40 -0700790/* see SENSOR_TYPE_META_DATA */
791typedef sensors_event_t sensors_meta_data_event_t;
792
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700793
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800794struct sensor_t;
795
796/**
797 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
798 * and the fields of this data structure must begin with hw_module_t
799 * followed by module specific information.
800 */
801struct sensors_module_t {
802 struct hw_module_t common;
803
804 /**
805 * Enumerate all available sensors. The list is returned in "list".
806 * @return number of sensors in the list
807 */
808 int (*get_sensors_list)(struct sensors_module_t* module,
809 struct sensor_t const** list);
810};
811
812struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800813
814 /* Name of this sensor.
815 * All sensors of the same "type" must have a different "name".
816 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800817 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800818
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800819 /* vendor of the hardware part */
820 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800821
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800822 /* version of the hardware part + driver. The value of this field
823 * must increase when the driver is updated in a way that changes the
824 * output of this sensor. This is important for fused sensors when the
825 * fusion algorithm is updated.
Aravind Akella6242f322014-02-28 18:46:19 -0800826 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800827 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800828
829 /* handle that identifies this sensors. This handle is used to reference
830 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800831 */
832 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800833
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800834 /* this sensor's type. */
835 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800836
837 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800838 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800839
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800840 /* smallest difference between two values reported by this sensor */
841 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800842
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800843 /* rough estimate of this sensor's power consumption in mA */
844 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800845
Aravind Akellac841efd2014-06-03 19:21:35 -0700846 /* this value depends on the reporting mode:
Mathias Agopiana4557722012-11-28 17:21:55 -0800847 *
848 * continuous: minimum sample period allowed in microseconds
849 * on-change : 0
850 * one-shot :-1
851 * special : 0, unless otherwise noted
852 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700853 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800854
Mathias Agopian16671c52013-07-24 21:07:40 -0700855 /* number of events reserved for this sensor in the batch mode FIFO.
856 * If there is a dedicated FIFO for this sensor, then this is the
857 * size of this FIFO. If the FIFO is shared with other sensors,
858 * this is the size reserved for that sensor and it can be zero.
859 */
860 uint32_t fifoReservedEventCount;
861
862 /* maximum number of events of this sensor that could be batched.
863 * This is especially relevant when the FIFO is shared between
864 * several sensors; this value is then set to the size of that FIFO.
865 */
866 uint32_t fifoMaxEventCount;
867
Aravind Akella477fbd52014-04-07 22:46:01 +0000868 /* type of this sensor as a string. Set to corresponding
869 * SENSOR_STRING_TYPE_*.
870 * When defining an OEM specific sensor or sensor manufacturer specific
871 * sensor, use your reserve domain name as a prefix.
872 * ex: com.google.glass.onheaddetector
873 * For sensors of known type, the android framework might overwrite this
874 * string automatically.
875 */
876 const char* stringType;
877
878 /* permission required to see this sensor, register to it and receive data.
879 * Set to "" if no permission is required. Some sensor types like the
880 * heart rate monitor have a mandatory require_permission.
881 * For sensors that always require a specific permission, like the heart
882 * rate monitor, the android framework might overwrite this string
883 * automatically.
884 */
885 const char* requiredPermission;
886
Aravind Akella110d2f22014-09-04 15:36:31 -0700887 /* This value is defined only for continuous mode and on-change sensors. It is the delay between
888 * two sensor events corresponding to the lowest frequency that this sensor supports. When lower
889 * frequencies are requested through batch()/setDelay() the events will be generated at this
890 * frequency instead. It can be used by the framework or applications to estimate when the batch
891 * FIFO may be full.
Aravind Akellac841efd2014-06-03 19:21:35 -0700892 *
893 * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
Aravind Akella110d2f22014-09-04 15:36:31 -0700894 * continuous, on-change: maximum sampling period allowed in microseconds.
895 * one-shot, special : 0
Aravind Akellac841efd2014-06-03 19:21:35 -0700896 * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit
897 * on 64 bit architectures only for binary compatibility reasons.
Aravind Akella6242f322014-02-28 18:46:19 -0800898 * Availability: SENSORS_DEVICE_API_VERSION_1_3
899 */
900 #ifdef __LP64__
901 int64_t maxDelay;
902 #else
903 int32_t maxDelay;
904 #endif
905
Aravind Akellac841efd2014-06-03 19:21:35 -0700906 /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.
907 * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.
908 * Availability: SENSORS_DEVICE_API_VERSION_1_3
909 */
Aravind Akella6242f322014-02-28 18:46:19 -0800910 #ifdef __LP64__
911 uint64_t flags;
912 #else
913 uint32_t flags;
914 #endif
915
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800916 /* reserved fields, must be zero */
Aravind Akella6242f322014-02-28 18:46:19 -0800917 void* reserved[2];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800918};
919
920
Mathias Agopiana4557722012-11-28 17:21:55 -0800921/*
922 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
923 * and is present for backward binary and source compatibility.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800924 * See the Sensors HAL interface section for complete descriptions of the
925 * following functions:
926 * http://source.android.com/devices/sensors/index.html#hal
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800927 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700928struct sensors_poll_device_t {
929 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700930 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700931 int sensor_handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700932 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700933 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700934 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700935 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700936};
937
Mathias Agopiana4557722012-11-28 17:21:55 -0800938/*
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700939 * struct sensors_poll_device_1 is used in HAL versions >= SENSORS_DEVICE_API_VERSION_1_0
Mathias Agopiana4557722012-11-28 17:21:55 -0800940 */
941typedef struct sensors_poll_device_1 {
942 union {
943 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
944 * and can be down-cast to it
945 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800946 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -0800947
948 struct {
949 struct hw_device_t common;
950
Clay Murphy8db1fb42013-12-19 09:58:28 -0800951 /* Activate/de-activate one sensor. Return 0 on success, negative
Mathias Agopiana4557722012-11-28 17:21:55 -0800952 *
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700953 * sensor_handle is the handle of the sensor to change.
Mathias Agopiana4557722012-11-28 17:21:55 -0800954 * enabled set to 1 to enable, or 0 to disable the sensor.
955 *
Clay Murphy8db1fb42013-12-19 09:58:28 -0800956 * Return 0 on success, negative errno code otherwise.
Mathias Agopiana4557722012-11-28 17:21:55 -0800957 */
958 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700959 int sensor_handle, int enabled);
Mathias Agopiana4557722012-11-28 17:21:55 -0800960
961 /**
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700962 * Set the events's period in nanoseconds for a given sensor.
963 * If sampling_period_ns > max_delay it will be truncated to
964 * max_delay and if sampling_period_ns < min_delay it will be
965 * replaced by min_delay.
Mathias Agopiana4557722012-11-28 17:21:55 -0800966 */
967 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700968 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -0800969
970 /**
971 * Returns an array of sensor data.
Mathias Agopiana4557722012-11-28 17:21:55 -0800972 */
973 int (*poll)(struct sensors_poll_device_t *dev,
974 sensors_event_t* data, int count);
975 };
976 };
977
Mathias Agopiana4557722012-11-28 17:21:55 -0800978
979 /*
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700980 * Sets a sensor’s parameters, including sampling frequency and maximum
981 * report latency. This function can be called while the sensor is
982 * activated, in which case it must not cause any sensor measurements to
983 * be lost: transitioning from one sampling rate to the other cannot cause
984 * lost events, nor can transitioning from a high maximum report latency to
985 * a low maximum report latency.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800986 * See the Batching sensor results page for details:
987 * http://source.android.com/devices/sensors/batching.html
Mathias Agopiana4557722012-11-28 17:21:55 -0800988 */
989 int (*batch)(struct sensors_poll_device_1* dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700990 int sensor_handle, int flags, int64_t sampling_period_ns,
991 int64_t max_report_latency_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -0800992
Mathias Agopian16671c52013-07-24 21:07:40 -0700993 /*
994 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
995 * to the end of the "batch mode" FIFO for the specified sensor and flushes
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700996 * the FIFO.
997 * If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero),
Aravind Akellac841efd2014-06-03 19:21:35 -0700998 * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700999 * event stream. This applies to all sensors other than one-shot sensors.
1000 * If the sensor is a one-shot sensor, flush must return -EINVAL and not generate
1001 * any flush complete metadata.
Aravind Akellaa7f2cda2014-08-21 16:31:14 -07001002 * If the sensor is not active at the time flush() is called, flush() should return
1003 * -EINVAL.
Mathias Agopian16671c52013-07-24 21:07:40 -07001004 */
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001005 int (*flush)(struct sensors_poll_device_1* dev, int sensor_handle);
Mathias Agopian16671c52013-07-24 21:07:40 -07001006
Mathias Agopiana4557722012-11-28 17:21:55 -08001007 void (*reserved_procs[8])(void);
1008
1009} sensors_poll_device_1_t;
1010
1011
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001012/** convenience API for opening and closing a device */
1013
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001014static inline int sensors_open(const struct hw_module_t* module,
1015 struct sensors_poll_device_t** device) {
1016 return module->methods->open(module,
1017 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1018}
1019
1020static inline int sensors_close(struct sensors_poll_device_t* device) {
1021 return device->common.close(&device->common);
1022}
1023
Mathias Agopiana4557722012-11-28 17:21:55 -08001024static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001025 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001026 return module->methods->open(module,
1027 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1028}
1029
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001030static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001031 return device->common.close(&device->common);
1032}
1033
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001034__END_DECLS
1035
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001036#endif // ANDROID_SENSORS_INTERFACE_H