blob: a2d9b2e18d9ddab3bc024cc1a798b95b2dfa41ff [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
Aravind Akellac7f54132015-06-22 18:26:54 -0700111 /*
112 * Data Injection 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 */
Aravind Akellac7f54132015-06-22 18:26:54 -0700116 SENSOR_HAL_DATA_INJECTION_MODE = 0x1
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700117};
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
Aravind Akellac7f54132015-06-22 18:26:54 -0700141 SENSOR_FLAG_SPECIAL_REPORTING_MODE = 0x6, // 0110
142
143 /*
144 * Set this flag if the sensor supports data_injection mode and allows data to be injected
145 * from the SensorService. When in data_injection ONLY sensors with this flag set are injected
146 * sensor data and only sensors with this flag set are activated. Eg: Accelerometer and Step
147 * Counter sensors can be set with this flag and SensorService will inject accelerometer data
148 * and read the corresponding step counts.
149 */
Aravind Akella2d6c8d72015-09-10 15:00:51 -0700150 SENSOR_FLAG_SUPPORTS_DATA_INJECTION = 0x10 // 1 0000
Aravind Akella6242f322014-02-28 18:46:19 -0800151};
152
153/*
Aravind Akellac841efd2014-06-03 19:21:35 -0700154 * Mask and shift for reporting mode sensor flags defined above.
155 */
156#define REPORTING_MODE_MASK (0xE)
157#define REPORTING_MODE_SHIFT (1)
158
159/*
Aravind Akellac7f54132015-06-22 18:26:54 -0700160 * Mask and shift for data_injection mode sensor flags defined above.
161 */
162#define DATA_INJECTION_MASK (0x10)
163#define DATA_INJECTION_SHIFT (4)
164
165/*
Mathias Agopiana4557722012-11-28 17:21:55 -0800166 * Sensor type
167 *
168 * Each sensor has a type which defines what this sensor measures and how
Clay Murphy8db1fb42013-12-19 09:58:28 -0800169 * measures are reported. See the Base sensors and Composite sensors lists
170 * for complete descriptions:
171 * http://source.android.com/devices/sensors/base_triggers.html
172 * http://source.android.com/devices/sensors/composite_sensors.html
Mathias Agopian1599ec62013-08-19 14:34:47 -0700173 *
174 * Device manufacturers (OEMs) can define their own sensor types, for
175 * their private use by applications or services provided by them. Such
176 * sensor types are specific to an OEM and can't be exposed in the SDK.
177 * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE.
Aravind Akella477fbd52014-04-07 22:46:01 +0000178 *
179 * All sensors defined outside of the device private range must correspond to
180 * a type defined in this file, and must satisfy the characteristics listed in
181 * the description of the sensor type.
182 *
183 * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also
184 * has a stringType.
185 * - StringType of sensors inside of the device private range MUST be prefixed
186 * by the sensor provider's or OEM reverse domain name. In particular, they
187 * cannot use the "android.sensor" prefix.
188 * - StringType of sensors outside of the device private range MUST correspond
189 * to the one defined in this file (starting with "android.sensor").
190 * For example, accelerometers must have
191 * type=SENSOR_TYPE_ACCELEROMETER and
192 * stringType=SENSOR_STRING_TYPE_ACCELEROMETER
193 *
194 * When android introduces a new sensor type that can replace an OEM-defined
195 * sensor type, the OEM must use the official sensor type and stringType on
196 * versions of the HAL that support this new official sensor type.
197 *
198 * Example (made up): Suppose Google's Glass team wants to surface a sensor
199 * detecting that Glass is on a head.
200 * - Such a sensor is not officially supported in android KitKat
201 * - Glass devices launching on KitKat can implement a sensor with
202 * type = 0x10001 and stringType = "com.google.glass.onheaddetector"
203 * - In L android release, if android decides to define
204 * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR,
205 * those types should replace the Glass-team-specific types in all future
206 * launches.
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700207 * - When launching Glass on the L release, Google should now use the official
Aravind Akella477fbd52014-04-07 22:46:01 +0000208 * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType.
209 * - This way, all applications can now use this sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800210 */
211
212/*
Mathias Agopian1599ec62013-08-19 14:34:47 -0700213 * Base for device manufacturers private sensor types.
214 * These sensor types can't be exposed in the SDK.
215 */
216#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000
217
218/*
Mathias Agopian16671c52013-07-24 21:07:40 -0700219 * SENSOR_TYPE_META_DATA
Aravind Akellac841efd2014-06-03 19:21:35 -0700220 * reporting-mode: n/a
Mathias Agopian16671c52013-07-24 21:07:40 -0700221 * wake-up sensor: n/a
222 *
223 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
224 *
225 * SENSOR_TYPE_META_DATA is a special token used to populate the
226 * sensors_meta_data_event structure. It doesn't correspond to a physical
227 * sensor. sensors_meta_data_event are special, they exist only inside
228 * the HAL and are generated spontaneously, as opposed to be related to
229 * a physical sensor.
230 *
Mathias Agopianaf32a8d2013-08-06 20:33:38 -0700231 * sensors_meta_data_event_t.version must be META_DATA_VERSION
232 * sensors_meta_data_event_t.sensor must be 0
233 * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
234 * sensors_meta_data_event_t.reserved must be 0
235 * sensors_meta_data_event_t.timestamp must be 0
Mathias Agopian16671c52013-07-24 21:07:40 -0700236 *
237 * The payload is a meta_data_event_t, where:
238 * meta_data_event_t.what can take the following values:
239 *
240 * META_DATA_FLUSH_COMPLETE
241 * This event indicates that a previous (*flush)() call has completed for the sensor
242 * handle specified in meta_data_event_t.sensor.
243 * see (*flush)() for more details
244 *
245 * All other values for meta_data_event_t.what are reserved and
246 * must not be used.
247 *
248 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000249#define SENSOR_TYPE_META_DATA (0)
Mathias Agopian16671c52013-07-24 21:07:40 -0700250
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800251/*
Aravind Akella9057e122014-07-28 18:01:37 -0700252 * Wake up sensors.
253 * Each sensor may have either or both a wake-up and a non-wake variant.
254 * When registered in batch mode, wake-up sensors will wake up the AP when
255 * their FIFOs are full or when the batch timeout expires. A separate FIFO has
256 * to be maintained for wake up sensors and non wake up sensors. The non wake-up
257 * sensors need to overwrite their FIFOs when they are full till the AP wakes up
258 * and the wake-up sensors will wake-up the AP when their FIFOs are full or when
259 * the batch timeout expires without losing events. Wake-up and non wake-up variants
260 * of each sensor can be activated at different rates independently of each other.
261 *
262 * Note: Proximity sensor and significant motion sensor which were defined in previous
263 * releases are also wake-up sensors and should be treated as such. Wake-up one-shot
264 * sensors like SIGNIFICANT_MOTION cannot be batched, hence the text about batch above
265 * doesn't apply to them. See the definitions of SENSOR_TYPE_PROXIMITY and
266 * SENSOR_TYPE_SIGNIFICANT_MOTION for more info.
267 *
268 * Set SENSOR_FLAG_WAKE_UP flag for all wake-up sensors.
269 *
270 * For example, A device can have two sensors both of SENSOR_TYPE_ACCELEROMETER and
271 * one of them can be a wake_up sensor (with SENSOR_FLAG_WAKE_UP flag set) and the other
272 * can be a regular non wake_up sensor. Both of these sensors must be activated/deactivated
273 * independently of the other.
274 */
275
276/*
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800277 * SENSOR_TYPE_ACCELEROMETER
Aravind Akellac841efd2014-06-03 19:21:35 -0700278 * reporting-mode: continuous
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800279 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800280 * All values are in SI units (m/s^2) and measure the acceleration of the
281 * device minus the force of gravity.
282 *
Aravind Akella9057e122014-07-28 18:01:37 -0700283 * Implement the non-wake-up version of this sensor and implement the wake-up
284 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800285 */
286#define SENSOR_TYPE_ACCELEROMETER (1)
Aravind Akella477fbd52014-04-07 22:46:01 +0000287#define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800288
289/*
290 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akellac841efd2014-06-03 19:21:35 -0700291 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800292 *
293 * All values are in micro-Tesla (uT) and measure the geomagnetic
294 * field in the X, Y and Z axis.
295 *
Aravind Akella9057e122014-07-28 18:01:37 -0700296 * Implement the non-wake-up version of this sensor and implement the wake-up
297 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800298 */
299#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
300#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akella477fbd52014-04-07 22:46:01 +0000301#define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800302
303/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800304 * SENSOR_TYPE_ORIENTATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700305 * reporting-mode: continuous
Clay Murphy8db1fb42013-12-19 09:58:28 -0800306 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800307 * All values are angles in degrees.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800308 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700309 * Orientation sensors return sensor events for all 3 axes at a constant
310 * rate defined by setDelay().
Aravind Akella9057e122014-07-28 18:01:37 -0700311 *
312 * Implement the non-wake-up version of this sensor and implement the wake-up
313 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800314 */
315#define SENSOR_TYPE_ORIENTATION (3)
Aravind Akella477fbd52014-04-07 22:46:01 +0000316#define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800317
318/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800319 * SENSOR_TYPE_GYROSCOPE
Aravind Akellac841efd2014-06-03 19:21:35 -0700320 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800321 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700322 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800323 * around the X, Y and Z axis.
Aravind Akella9057e122014-07-28 18:01:37 -0700324 *
325 * Implement the non-wake-up version of this sensor and implement the wake-up
326 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800327 */
328#define SENSOR_TYPE_GYROSCOPE (4)
Aravind Akella477fbd52014-04-07 22:46:01 +0000329#define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800330
331/*
332 * SENSOR_TYPE_LIGHT
Aravind Akellac841efd2014-06-03 19:21:35 -0700333 * reporting-mode: on-change
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800334 *
335 * The light sensor value is returned in SI lux units.
Aravind Akella9057e122014-07-28 18:01:37 -0700336 *
337 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800338 */
339#define SENSOR_TYPE_LIGHT (5)
Aravind Akella477fbd52014-04-07 22:46:01 +0000340#define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800341
342/*
343 * SENSOR_TYPE_PRESSURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700344 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800345 *
346 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Aravind Akella9057e122014-07-28 18:01:37 -0700347 *
348 * Implement the non-wake-up version of this sensor and implement the wake-up
349 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800350 */
351#define SENSOR_TYPE_PRESSURE (6)
Aravind Akella477fbd52014-04-07 22:46:01 +0000352#define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800353
354/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
355#define SENSOR_TYPE_TEMPERATURE (7)
Aravind Akella477fbd52014-04-07 22:46:01 +0000356#define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800357
358/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800359 * SENSOR_TYPE_PROXIMITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700360 * reporting-mode: on-change
Mike Lockwooda2414312009-11-03 10:29:50 -0500361 *
Aravind Akella9057e122014-07-28 18:01:37 -0700362 * The proximity sensor which turns the screen off and back on during calls is the
363 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
364 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
365 * SENSOR_FLAG_WAKE_UP.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800366 * The value corresponds to the distance to the nearest object in centimeters.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800367 */
368#define SENSOR_TYPE_PROXIMITY (8)
Aravind Akella477fbd52014-04-07 22:46:01 +0000369#define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800370
371/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800372 * SENSOR_TYPE_GRAVITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700373 * reporting-mode: continuous
Mathias Agopian42b743c2010-11-22 15:55:32 -0800374 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800375 * A gravity output indicates the direction of and magnitude of gravity in
Clay Murphy8db1fb42013-12-19 09:58:28 -0800376 * the devices's coordinates.
Aravind Akella9057e122014-07-28 18:01:37 -0700377 *
378 * Implement the non-wake-up version of this sensor and implement the wake-up
379 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800380 */
381#define SENSOR_TYPE_GRAVITY (9)
Aravind Akella477fbd52014-04-07 22:46:01 +0000382#define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800383
384/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800385 * SENSOR_TYPE_LINEAR_ACCELERATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700386 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800387 *
388 * Indicates the linear acceleration of the device in device coordinates,
389 * not including gravity.
Aravind Akella9057e122014-07-28 18:01:37 -0700390 *
391 * Implement the non-wake-up version of this sensor and implement the wake-up
392 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800393 */
394#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
Aravind Akella477fbd52014-04-07 22:46:01 +0000395#define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800396
397
398/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800399 * SENSOR_TYPE_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700400 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800401 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700402 * The rotation vector symbolizes the orientation of the device relative to the
Clay Murphy8db1fb42013-12-19 09:58:28 -0800403 * East-North-Up coordinates frame.
Aravind Akella9057e122014-07-28 18:01:37 -0700404 *
405 * Implement the non-wake-up version of this sensor and implement the wake-up
406 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800407 */
408#define SENSOR_TYPE_ROTATION_VECTOR (11)
Aravind Akella477fbd52014-04-07 22:46:01 +0000409#define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800410
411/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800412 * SENSOR_TYPE_RELATIVE_HUMIDITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700413 * reporting-mode: on-change
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100414 *
415 * A relative humidity sensor measures relative ambient air humidity and
416 * returns a value in percent.
Aravind Akella9057e122014-07-28 18:01:37 -0700417 *
418 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800419 */
420#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
Aravind Akella477fbd52014-04-07 22:46:01 +0000421#define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800422
423/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800424 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700425 * reporting-mode: on-change
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700426 *
427 * The ambient (room) temperature in degree Celsius.
Aravind Akella9057e122014-07-28 18:01:37 -0700428 *
429 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800430 */
431#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
Aravind Akella477fbd52014-04-07 22:46:01 +0000432#define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800433
434/*
435 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700436 * reporting-mode: continuous
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700437 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800438 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
439 * reported separately instead of being included in the measurement.
Aravind Akella9057e122014-07-28 18:01:37 -0700440 *
441 * Implement the non-wake-up version of this sensor and implement the wake-up
442 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800443 */
444#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
Aravind Akella477fbd52014-04-07 22:46:01 +0000445#define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800446
447/*
448 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700449 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800450 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800451 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
Clay Murphy8db1fb42013-12-19 09:58:28 -0800452 * field.
Aravind Akella9057e122014-07-28 18:01:37 -0700453 *
454 * Implement the non-wake-up version of this sensor and implement the wake-up
455 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800456 */
457#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
Aravind Akella477fbd52014-04-07 22:46:01 +0000458#define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800459
460/*
461 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700462 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800463 *
464 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800465 * around the X, Y and Z axis.
Aravind Akella9057e122014-07-28 18:01:37 -0700466 *
467 * Implement the non-wake-up version of this sensor and implement the wake-up
468 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800469 */
470#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
Aravind Akella477fbd52014-04-07 22:46:01 +0000471#define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800472
Mathias Agopiana4557722012-11-28 17:21:55 -0800473/*
474 * SENSOR_TYPE_SIGNIFICANT_MOTION
Aravind Akellac841efd2014-06-03 19:21:35 -0700475 * reporting-mode: one-shot
Mathias Agopiana4557722012-11-28 17:21:55 -0800476 *
477 * A sensor of this type triggers an event each time significant motion
478 * is detected and automatically disables itself.
Aravind Akella9057e122014-07-28 18:01:37 -0700479 * For Significant Motion sensor to be useful, it must be defined as a
480 * wake-up sensor. (set SENSOR_FLAG_WAKE_UP). Implement the wake-up significant motion
481 * sensor. A non wake-up version is not useful.
Mathias Agopiana4557722012-11-28 17:21:55 -0800482 * The only allowed value to return is 1.0.
Mathias Agopiana4557722012-11-28 17:21:55 -0800483 */
484
485#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
Aravind Akella477fbd52014-04-07 22:46:01 +0000486#define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
Mathias Agopiana4557722012-11-28 17:21:55 -0800487
488/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800489 * SENSOR_TYPE_STEP_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700490 * reporting-mode: special
Mathias Agopiana4557722012-11-28 17:21:55 -0800491 *
492 * A sensor of this type triggers an event each time a step is taken
Clay Murphy8db1fb42013-12-19 09:58:28 -0800493 * by the user. The only allowed value to return is 1.0 and an event
494 * is generated for each step.
Aravind Akella9057e122014-07-28 18:01:37 -0700495 *
496 * Both wake-up and non wake-up versions are useful.
Mathias Agopiana4557722012-11-28 17:21:55 -0800497 */
498
Mathias Agopian2f276f52013-01-28 17:54:41 -0800499#define SENSOR_TYPE_STEP_DETECTOR (18)
Aravind Akella477fbd52014-04-07 22:46:01 +0000500#define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
Mathias Agopiana4557722012-11-28 17:21:55 -0800501
502
503/*
504 * SENSOR_TYPE_STEP_COUNTER
Aravind Akellac841efd2014-06-03 19:21:35 -0700505 * reporting-mode: on-change
Mathias Agopiana4557722012-11-28 17:21:55 -0800506 *
507 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800508 * the last reboot while activated. The value is returned as a uint64_t and is
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700509 * reset to zero only on a system / android reboot.
Aravind Akella9057e122014-07-28 18:01:37 -0700510 *
511 * Implement the non-wake-up version of this sensor and implement the wake-up
512 * version if the system possesses a wake up fifo.
Mathias Agopiana4557722012-11-28 17:21:55 -0800513 */
514
515#define SENSOR_TYPE_STEP_COUNTER (19)
Aravind Akella477fbd52014-04-07 22:46:01 +0000516#define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
Mathias Agopiana4557722012-11-28 17:21:55 -0800517
Etienne Le Grandca858142013-02-26 19:17:20 -0800518/*
519 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700520 * reporting-mode: continuous
Etienne Le Grandca858142013-02-26 19:17:20 -0800521 *
522 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
523 * of using a gyroscope.
Aravind Akella9057e122014-07-28 18:01:37 -0700524 *
525 * Implement the non-wake-up version of this sensor and implement the wake-up
526 * version if the system possesses a wake up fifo.
Etienne Le Grandca858142013-02-26 19:17:20 -0800527 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000528#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
529#define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
530
531/*
532 * SENSOR_TYPE_HEART_RATE
Aravind Akellac841efd2014-06-03 19:21:35 -0700533 * reporting-mode: on-change
Aravind Akella477fbd52014-04-07 22:46:01 +0000534 *
Etienne Le Grand7b361582014-05-16 11:08:28 -0700535 * A sensor of this type returns the current heart rate.
536 * The events contain the current heart rate in beats per minute (BPM) and the
537 * status of the sensor during the measurement. See heart_rate_event_t for more
538 * details.
539 *
540 * Because this sensor is on-change, events must be generated when and only
541 * when heart_rate.bpm or heart_rate.status have changed since the last
Vinod Krishnan74279e32014-08-28 15:25:13 -0700542 * event. In particular, upon the first activation, unless the device is known
543 * to not be on the body, the status field of the first event must be set to
544 * SENSOR_STATUS_UNRELIABLE. The event should be generated no faster than every
545 * period_ns passed to setDelay() or to batch().
Griff Hazenf0f67e62014-08-28 17:02:50 -0700546 * See the definition of the on-change reporting mode for more information.
Etienne Le Grand7b361582014-05-16 11:08:28 -0700547 *
Aravind Akella477fbd52014-04-07 22:46:01 +0000548 * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
Aravind Akella9057e122014-07-28 18:01:37 -0700549 *
550 * Both wake-up and non wake-up versions are useful.
Aravind Akella477fbd52014-04-07 22:46:01 +0000551 */
552#define SENSOR_TYPE_HEART_RATE (21)
553#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
Mathias Agopiana4557722012-11-28 17:21:55 -0800554
Aravind Akella6242f322014-02-28 18:46:19 -0800555/*
Aravind Akellaf895c682014-04-30 11:46:09 -0700556 * SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700557 * reporting-mode: special (setDelay has no impact)
Aravind Akellaf895c682014-04-30 11:46:09 -0700558 *
559 * A sensor of this type generates an event each time a tilt event is detected. A tilt event
560 * 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 -0700561 * 35 degrees since the activation or the last trigger of the sensor.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700562 * reference_estimated_gravity = average of accelerometer measurements over the first
Etienne Le Grand53017ef2014-05-28 15:42:48 -0700563 * 1 second after activation or the estimated gravity at the last
564 * trigger.
Aravind Akellaf895c682014-04-30 11:46:09 -0700565 * current_estimated_gravity = average of accelerometer measurements over the last 2 seconds.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700566 * trigger when angle (reference_estimated_gravity, current_estimated_gravity) > 35 degrees
Aravind Akellaf895c682014-04-30 11:46:09 -0700567 *
568 * Large accelerations without a change in phone orientation should not trigger a tilt event.
569 * For example, a sharp turn or strong acceleration while driving a car should not trigger a tilt
570 * event, even though the angle of the average acceleration might vary by more than 35 degrees.
571 *
572 * Typically, this sensor is implemented with the help of only an accelerometer. Other sensors can
573 * be used as well if they do not increase the power consumption significantly. This is a low power
574 * sensor that should allow the AP to go into suspend mode. Do not emulate this sensor in the HAL.
575 * Like other wake up sensors, the driver is expected to a hold a wake_lock with a timeout of 200 ms
576 * while reporting this event. The only allowed return value is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700577 *
578 * Implement only the wake-up version of this sensor.
Aravind Akellaf895c682014-04-30 11:46:09 -0700579 */
Aravind Akella9057e122014-07-28 18:01:37 -0700580#define SENSOR_TYPE_TILT_DETECTOR (22)
581#define SENSOR_STRING_TYPE_TILT_DETECTOR "android.sensor.tilt_detector"
Aravind Akellaf895c682014-04-30 11:46:09 -0700582
Etienne Le Grandba123122014-05-05 18:20:42 -0700583/*
584 * SENSOR_TYPE_WAKE_GESTURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700585 * reporting-mode: one-shot
Etienne Le Grandba123122014-05-05 18:20:42 -0700586 *
587 * A sensor enabling waking up the device based on a device specific motion.
588 *
589 * When this sensor triggers, the device behaves as if the power button was
590 * pressed, turning the screen on. This behavior (turning on the screen when
591 * this sensor triggers) might be deactivated by the user in the device
592 * settings. Changes in settings do not impact the behavior of the sensor:
593 * only whether the framework turns the screen on when it triggers.
594 *
595 * The actual gesture to be detected is not specified, and can be chosen by
596 * the manufacturer of the device.
597 * This sensor must be low power, as it is likely to be activated 24/7.
598 * The only allowed value to return is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700599 *
600 * Implement only the wake-up version of this sensor.
Etienne Le Grandba123122014-05-05 18:20:42 -0700601 */
Aravind Akella9057e122014-07-28 18:01:37 -0700602#define SENSOR_TYPE_WAKE_GESTURE (23)
Etienne Le Grandba123122014-05-05 18:20:42 -0700603#define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture"
604
Jeff Brown8df2feb2014-07-17 15:11:51 -0700605/*
606 * SENSOR_TYPE_GLANCE_GESTURE
607 * reporting-mode: one-shot
Jeff Brown8df2feb2014-07-17 15:11:51 -0700608 *
609 * A sensor enabling briefly turning the screen on to enable the user to
610 * glance content on screen based on a specific motion. The device should
611 * turn the screen off after a few moments.
612 *
613 * When this sensor triggers, the device turns the screen on momentarily
614 * to allow the user to glance notifications or other content while the
615 * device remains locked in a non-interactive state (dozing). This behavior
616 * (briefly turning on the screen when this sensor triggers) might be deactivated
617 * by the user in the device settings. Changes in settings do not impact the
618 * behavior of the sensor: only whether the framework briefly turns the screen on
619 * when it triggers.
620 *
621 * The actual gesture to be detected is not specified, and can be chosen by
622 * the manufacturer of the device.
623 * This sensor must be low power, as it is likely to be activated 24/7.
624 * The only allowed value to return is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700625 *
626 * Implement only the wake-up version of this sensor.
Jeff Brown8df2feb2014-07-17 15:11:51 -0700627 */
Aravind Akella9057e122014-07-28 18:01:37 -0700628#define SENSOR_TYPE_GLANCE_GESTURE (24)
Jeff Brown8df2feb2014-07-17 15:11:51 -0700629#define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture"
630
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800631/**
Aravind Akella952471e2014-07-17 12:40:54 -0700632 * SENSOR_TYPE_PICK_UP_GESTURE
633 * reporting-mode: one-shot
Aravind Akella952471e2014-07-17 12:40:54 -0700634 *
635 * A sensor of this type triggers when the device is picked up regardless of wherever is was
636 * before (desk, pocket, bag). The only allowed return value is 1.0.
637 * This sensor de-activates itself immediately after it triggers.
Aravind Akella9057e122014-07-28 18:01:37 -0700638 *
639 * Implement only the wake-up version of this sensor.
Aravind Akella952471e2014-07-17 12:40:54 -0700640 */
Aravind Akella9057e122014-07-28 18:01:37 -0700641#define SENSOR_TYPE_PICK_UP_GESTURE (25)
Aravind Akella952471e2014-07-17 12:40:54 -0700642#define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture"
643
Nick Vaccaroadbfbb72015-01-13 12:14:28 -0800644/*
645 * SENSOR_TYPE_WRIST_TILT_GESTURE
646 * trigger-mode: special
647 * wake-up sensor: yes
648 *
649 * A sensor of this type triggers an event each time a tilt of the wrist-worn
650 * device is detected.
651 *
652 * This sensor must be low power, as it is likely to be activated 24/7.
653 * The only allowed value to return is 1.0.
654 *
655 * Implement only the wake-up version of this sensor.
656 */
657#define SENSOR_TYPE_WRIST_TILT_GESTURE (26)
658#define SENSOR_STRING_TYPE_WRIST_TILT_GESTURE "android.sensor.wrist_tilt_gesture"
659
Trevor Bunkerf8e7ed32016-01-08 10:22:23 -0800660/*
661 * SENSOR_TYPE_DEVICE_ORIENTATION
662 * reporting-mode: on-change
663 *
664 * The current orientation of the device. The value should be reported in the
665 * first element of the 'data' member variable in sensors_event_t. The only
666 * values that can be reported are (please refer to Android Sensor Coordinate
667 * System to understand the X and Y axis direction with respect to default
668 * orientation):
669 * - 0: device is in default orientation (Y axis is vertical and points up)
670 * - 1: device is rotated 90 degrees counter-clockwise from default
671 * orientation (X axis is vertical and points up)
672 * - 2: device is rotated 180 degrees from default orientation (Y axis is
673 * vertical and points down)
674 * - 3: device is rotated 90 degrees clockwise from default orientation (X axis
675 * is vertical and points down)
676 *
677 * Moving the device to an orientation where the Z axis is vertical (either up
678 * or down) should not cause a new event to be reported.
679 *
680 * To improve the user experience of this sensor, it is recommended to implement
681 * some physical (i.e., rotation angle) and temporal (i.e., delay) hysteresis.
682 * In other words, minor or transient rotations should not cause a new event to
683 * be reported.
684 *
685 * This sensor should only be implemented with the help of an accelerometer.
686 * This is a low power sensor that should reduce the number of interrupts of the
687 * AP. Do not emulate this sensor in the HAL.
688 *
689 * Both wake-up and non wake-up versions are useful.
690 */
691#define SENSOR_TYPE_DEVICE_ORIENTATION (27)
692#define SENSOR_STRING_TYPE_DEVICE_ORIENTATION "android.sensor.device_orientation"
693
Ashutosh Joshied021ea2016-01-14 22:28:24 -0800694/*
695 * SENSOR_TYPE_POSE_6DOF
696 * trigger-mode: continuous
697 *
698 * A sensor of this type returns the pose of the device.
699 * Pose of the device is defined as the orientation of the device from a
700 * Earth Centered Earth Fixed frame and the translation from an arbitrary
701 * point at subscription.
702 *
703 * This sensor can be high power. It can use any and all of the following
704 * . Accelerometer
705 * . Gyroscope
706 * . Camera
707 * . Depth Camera
708 *
Ashutosh Joshied021ea2016-01-14 22:28:24 -0800709 */
710#define SENSOR_TYPE_POSE_6DOF (28)
711#define SENSOR_STRING_TYPE_POSE_6DOF "android.sensor.pose_6dof"
712
Ashutosh Joshicb963312016-01-25 18:48:57 -0800713/*
714 * SENSOR_TYPE_STATIONARY_DETECT
715 * trigger mode: one shot
716 *
717 * A sensor of this type returns an event if the device is still/stationary for
718 * a while. The period of time to monitor for statinarity should be greater than
719 * 5 seconds, and less than 10 seconds.
720 *
721 * Stationarity here refers to absolute stationarity. eg: device on desk.
722 *
723 * The only allowed value to return is 1.0.
724 */
725#define SENSOR_TYPE_STATIONARY_DETECT (29)
726#define SENSOR_STRING_TYPE_STATIONARY_DETECT "android.sensor.stationary_detect"
727
728/*
729 * SENSOR_TYPE_MOTION_DETECT
730 * trigger mode: one shot
731 *
732 * A sensor of this type returns an event if the device is not still for
733 * a while. The period of time to monitor for statinarity should be greater than
734 * 5 seconds, and less than 10 seconds.
735 *
736 * Motion here refers to any mechanism in which the device is causes to be
737 * moved in its inertial frame. eg: Pickin up the device and walking with it
738 * to a nearby room may trigger motion wherewas keeping the device on a table
739 * on a smooth train moving at constant velocity may not trigger motion.
740 *
741 * The only allowed value to return is 1.0.
742 */
743#define SENSOR_TYPE_MOTION_DETECT (30)
744#define SENSOR_STRING_TYPE_MOTION_DETECT "android.sensor.motion_detect"
745
746/*
747 * SENSOR_TYPE_HEART_BEAT
748 * trigger mode: continuous
749 *
750 * A sensor of this type returns an event everytime a hear beat peak is
751 * detected.
752 *
753 * Peak here ideally corresponds to the positive peak in the QRS complex of
Peng Xue641ba92016-01-20 00:27:21 -0800754 * and ECG signal.
Ashutosh Joshicb963312016-01-25 18:48:57 -0800755 *
756 * The sensor is not expected to be optimized for latency. As a guide, a
757 * latency of up to 10 seconds is acceptable. However the timestamp attached
758 * to the event should be accurate and should correspond to the time the peak
759 * occured.
760 *
761 * The sensor event contains a parameter for the confidence in the detection
762 * of the peak where 0.0 represent no information at all, and 1.0 represents
763 * certainty.
764 */
765#define SENSOR_TYPE_HEART_BEAT (31)
766#define SENSOR_STRING_TYPE_HEART_BEAT "android.sensor.heart_beat"
767
Aravind Akella952471e2014-07-17 12:40:54 -0700768/**
Peng Xue641ba92016-01-20 00:27:21 -0800769 * SENSOR_TYPE_DYNAMIC_SENSOR_META
770 * trigger-mode: special
771 *
772 * A sensor event of this type is received when a dynamic sensor is added to or removed from the
773 * system. At most one sensor of this type can be present in one sensor HAL implementation and
774 * presence of a sensor of this type in sensor HAL implementation indicates that this sensor HAL
775 * supports dynamic sensor feature. Operations, such as batch, activate and setDelay, to this
776 * special purpose sensor should be treated as no-op and return successful.
777 *
778 * A dynamic sensor connection indicates connection of a physical device or instantiation of a
779 * virtual sensor backed by algorithm; and a dynamic sensor disconnection indicates the the
780 * opposite. A sensor event of SENSOR_TYPE_DYNAMIC_SENSOR_META type should be delivered regardless
781 * of the activation status of the sensor in the event of dynamic sensor connection and
782 * disconnection. In the sensor event, besides the common data entries, "dynamic_sensor_meta", which
783 * includes fields for connection status, handle of the sensor involved, pointer to sensor_t
784 * structure and a uuid field, should be populated.
785 *
786 * At a dynamic sensor connection event, fields of sensor_t structure referenced by a pointer in
787 * dynamic_sensor_meta should be filled as if it was regular sensors. Sensor HAL is responsible for
788 * recovery of memory if the corresponding data is dynamicially allocated. However, the the pointer
789 * must be valid until the first activate call to the sensor reported in this connection event. At a
790 * dynamic sensor disconnection, the sensor_t pointer should be NULL.
791 *
792 * The sensor handle assigned to dynamic sensors should never be the same as that of any regular
793 * static sensors, and should be unique until next boot. In another word, if a handle h is used for
794 * a dynamic sensor A, that same number cannot be used for the same dynamic sensor A or another
795 * dynamic sensor B even after disconnection of A until reboot.
796 *
797 * The UUID field will be used for identifying the sensor in addition to name, vendor and version
798 * and type. For physical sensors of the same model, all sensors will have the same values in
799 * sensor_t, but the UUID should be unique and persistent for each individual unit. An all zero UUID
800 * indicates it is not possible to differentiate individual sensor unit.
801 *
802 */
803#define SENSOR_TYPE_DYNAMIC_SENSOR_META (32)
804#define SENSOR_STRING_TYPE_DYNAMIC_SENSOR_META "android.sensor.dynamic_sensor_meta"
805
806/**
Peng Xu0743a5c2016-01-21 17:30:02 -0800807 * SENSOR_TYPE_ADDITIONAL_INFO
808 * reporting-mode: N/A
809 *
810 * This sensor type is for delivering additional sensor information aside from sensor event data.
811 * Additional information may include sensor front-end group delay, internal calibration parameters,
812 * noise level metrics, device internal temperature, etc.
813 *
814 * This type will never bind to a sensor. In other words, no sensor in the sensor list should be of
815 * the type SENSOR_TYPE_ADDITIONAL_INFO. If a sensor HAL supports sensor additional information
816 * feature, it reports sensor_event_t with "sensor" field set to handle of the reporting sensor and
817 * "type" field set to SENSOR_TYPE_ADDITIONAL_INFO. Delivery of additional information events is
818 * triggered under two conditions: an enable activate() call or a flush() call to the corresponding
819 * sensor.
820 *
821 * A single additional information report consists of multiple frames. Sequences of these frames are
822 * ordered using timestamps, which means the timestamps of sequential frames have to be at least 1
823 * nanosecond apart from each other. Each frame is a sensor_event_t delivered through the HAL
824 * interface, with related data stored in the "additional_info" field, which is of type
825 * additional_info_event_t. The "type" field of additional_info_event_t denotes the nature of the
826 * payload data (see additional_info_type_t). The "serial" field is used to keep the sequence of
827 * payload data that spans multiple frames. The first frame of the entire report is always of type
828 * AINFO_BEGIN, and the last frame is always AINFO_END.
829 *
830 * All additional information frames have to be delivered after flush complete event if flush() was
831 * triggering the report.
832 */
833#define SENSOR_TYPE_ADDITIONAL_INFO (33)
834#define SENSOR_STRING_TYPE_ADDITIONAL_INFO "android.sensor.additional_info"
835
836/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800837 * Values returned by the accelerometer in various locations in the universe.
838 * all values are in SI units (m/s^2)
839 */
840#define GRAVITY_SUN (275.0f)
841#define GRAVITY_EARTH (9.80665f)
842
843/** Maximum magnetic field on Earth's surface */
844#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
845
846/** Minimum magnetic field on Earth's surface */
847#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
848
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800849/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700850 * Possible values of the status field of sensor events.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800851 */
Etienne Le Grand7b361582014-05-16 11:08:28 -0700852#define SENSOR_STATUS_NO_CONTACT -1
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800853#define SENSOR_STATUS_UNRELIABLE 0
854#define SENSOR_STATUS_ACCURACY_LOW 1
855#define SENSOR_STATUS_ACCURACY_MEDIUM 2
856#define SENSOR_STATUS_ACCURACY_HIGH 3
857
Peng Xue641ba92016-01-20 00:27:21 -0800858
859struct sensor_t;
860
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800861/**
862 * sensor event data
863 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800864typedef struct {
865 union {
866 float v[3];
867 struct {
868 float x;
869 float y;
870 float z;
871 };
872 struct {
873 float azimuth;
874 float pitch;
875 float roll;
876 };
877 };
878 int8_t status;
879 uint8_t reserved[3];
880} sensors_vec_t;
881
882/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800883 * uncalibrated gyroscope and magnetometer event data
884 */
885typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700886 union {
887 float uncalib[3];
888 struct {
889 float x_uncalib;
890 float y_uncalib;
891 float z_uncalib;
892 };
893 };
894 union {
895 float bias[3];
896 struct {
897 float x_bias;
898 float y_bias;
899 float z_bias;
900 };
901 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800902} uncalibrated_event_t;
903
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700904/**
905 * Meta data event data
906 */
Mathias Agopian16671c52013-07-24 21:07:40 -0700907typedef struct meta_data_event {
908 int32_t what;
909 int32_t sensor;
910} meta_data_event_t;
911
Etienne Le Grandca858142013-02-26 19:17:20 -0800912/**
Peng Xue641ba92016-01-20 00:27:21 -0800913 * Dynamic sensor meta event. See the description of SENSOR_TYPE_DYNAMIC_SENSOR_META type for
914 * details.
915 */
916typedef struct dynamic_sensor_meta_event {
Peng Xue20707a2016-01-27 18:26:10 -0800917 int32_t connected;
918 int32_t handle;
Peng Xue641ba92016-01-20 00:27:21 -0800919 const struct sensor_t * sensor; // should be NULL if connected == false
920 uint8_t uuid[16]; // UUID of a dynamic sensor (use platform endianess).
921} dynamic_sensor_meta_event_t;
922
923/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700924 * Heart rate event data
925 */
926typedef struct {
927 // Heart rate in beats per minute.
928 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
929 float bpm;
930 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700931 // Note that this value should only be set for sensors that explicitly define
932 // the meaning of this field. This field is not piped through the framework
933 // for other sensors.
Etienne Le Grand7b361582014-05-16 11:08:28 -0700934 int8_t status;
935} heart_rate_event_t;
936
Peng Xu0743a5c2016-01-21 17:30:02 -0800937typedef struct {
938 int32_t type; // type of payload data, see additional_info_type_t
939 int32_t serial; // sequence number of this frame for this type
940 union {
941 // for each frame, a single data type, either int32_t or float, should be used.
942 int32_t data_int32[14];
943 float data_float[14];
944 };
945} additional_info_event_t;
946
947typedef enum additional_info_type {
948 //
949 AINFO_BEGIN = 0x0, // Marks the beginning of additional information frames
950 AINFO_END = 0x1, // Marks the end of additional information frames
951 // Basic information
952 AINFO_UNTRACKED_DELAY = 0x10000, // Estimation of the delay that is not tracked by sensor
953 // timestamps. This includes delay introduced by
954 // sensor front-end filtering, data transport, etc.
955 // float[2]: delay in seconds
956 // standard deviation of estimated value
957 //
958 AINFO_INTERNAL_TEMPERATURE, // float: Celsius temperature.
959 //
960 AINFO_VEC3_CALIBRATION, // First three rows of a homogeneous matrix, which
961 // represents calibration to a three-element vector
962 // raw sensor reading.
963 // float[12]: 3x4 matrix in row major order
964 //
965 AINFO_SENSOR_PLACEMENT, // Location and orientation of sensor element in the
966 // device frame: origin is the geometric center of the
967 // mobile device screen surface; the axis definition
968 // corresponds to Android sensor definitions.
969 // float[12]: 3x4 matrix in row major order
970 //
971 AINFO_SAMPLING, // float[2]: raw sample period in seconds,
972 // standard deviation of sampling period
973
974 // Sampling channel modeling information
975 AINFO_CHANNEL_NOISE = 0x20000, // int32_t: noise type
976 // float[n]: parameters
977 //
978 AINFO_CHANNEL_SAMPLER, // float[3]: sample period
979 // standard deviation of sample period,
980 // quantization unit
981 //
982 AINFO_CHANNEL_FILTER, // Represents a filter:
983 // \sum_j a_j y[n-j] == \sum_i b_i x[n-i]
984 //
985 // int32_t[3]: number of feedforward coefficients, M,
986 // number of feedback coefficients, N, for
987 // FIR filter, N=1.
988 // bit mask that represents which element to
989 // which the filter is applied, bit 0 == 1
990 // means this filter applies to vector
991 // element 0.
992 // float[M+N]: filter coefficients (b0, b1, ..., BM-1),
993 // then (a0, a1, ..., aN-1), a0 is always 1.
994 // Multiple frames may be needed for higher
995 // number of taps.
996 //
997 AINFO_CHANNEL_LINEAR_TRANSFORM, // int32_t[2]: size in (row, column) ... 1st frame
998 // float[n]: matrix element values in row major order.
999 //
1000 AINFO_CHANNEL_NONLINEAR_MAP, // int32_t[2]: extrapolate method
1001 // interpolate method
1002 // float[n]: mapping key points in pairs, (in, out)...
1003 // (may be used to model saturation)
1004 //
1005 AINFO_CHANNEL_RESAMPLER, // int32_t: resample method (0-th order, 1st order...)
1006 // float[1]: resample ratio (upsampling if < 1.0;
1007 // downsampling if > 1.0).
1008 //
1009
1010 // Custom information
1011 AINFO_CUSTOM_START = 0x10000000, //
1012 // Debugging
1013 AINFO_DEBUGGING_START = 0x40000000, //
1014} additional_info_type_t;
1015
Etienne Le Grand7b361582014-05-16 11:08:28 -07001016/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001017 * Union of the various types of sensor data
1018 * that can be returned.
1019 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001020typedef struct sensors_event_t {
1021 /* must be sizeof(struct sensors_event_t) */
1022 int32_t version;
1023
1024 /* sensor identifier */
1025 int32_t sensor;
1026
1027 /* sensor type */
1028 int32_t type;
1029
1030 /* reserved */
1031 int32_t reserved0;
1032
1033 /* time is in nanosecond */
1034 int64_t timestamp;
1035
1036 union {
Mathias Agopian27e16682013-07-08 14:00:54 -07001037 union {
1038 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001039
Mathias Agopian27e16682013-07-08 14:00:54 -07001040 /* acceleration values are in meter per second per second (m/s^2) */
1041 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001042
Mathias Agopian27e16682013-07-08 14:00:54 -07001043 /* magnetic vector values are in micro-Tesla (uT) */
1044 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001045
Mathias Agopian27e16682013-07-08 14:00:54 -07001046 /* orientation values are in degrees */
1047 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001048
Mathias Agopian27e16682013-07-08 14:00:54 -07001049 /* gyroscope values are in rad/s */
1050 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -07001051
Mathias Agopian27e16682013-07-08 14:00:54 -07001052 /* temperature is in degrees centigrade (Celsius) */
1053 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001054
Mathias Agopian27e16682013-07-08 14:00:54 -07001055 /* distance in centimeters */
1056 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001057
Mathias Agopian27e16682013-07-08 14:00:54 -07001058 /* light in SI lux units */
1059 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -07001060
Mathias Agopian27e16682013-07-08 14:00:54 -07001061 /* pressure in hectopascal (hPa) */
1062 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +01001063
Mathias Agopian27e16682013-07-08 14:00:54 -07001064 /* relative humidity in percent */
1065 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -08001066
Mathias Agopian27e16682013-07-08 14:00:54 -07001067 /* uncalibrated gyroscope values are in rad/s */
1068 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -08001069
Mathias Agopian27e16682013-07-08 14:00:54 -07001070 /* uncalibrated magnetometer values are in micro-Teslas */
1071 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -07001072
Etienne Le Grand7b361582014-05-16 11:08:28 -07001073 /* heart rate data containing value in bpm and status */
1074 heart_rate_event_t heart_rate;
Aravind Akella477fbd52014-04-07 22:46:01 +00001075
Mathias Agopian16671c52013-07-24 21:07:40 -07001076 /* this is a special event. see SENSOR_TYPE_META_DATA above.
1077 * sensors_meta_data_event_t events are all reported with a type of
1078 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
1079 */
1080 meta_data_event_t meta_data;
Peng Xue641ba92016-01-20 00:27:21 -08001081
1082 /* dynamic sensor meta event. See SENSOR_TYPE_DYNAMIC_SENSOR_META type for details */
1083 dynamic_sensor_meta_event_t dynamic_sensor_meta;
Peng Xu0743a5c2016-01-21 17:30:02 -08001084
1085 /*
1086 * special additional sensor information frame, see
1087 * SENSOR_TYPE_ADDITIONAL_INFO for details.
1088 */
1089 additional_info_event_t additional_info;
Mathias Agopian27e16682013-07-08 14:00:54 -07001090 };
Etienne Le Grandca858142013-02-26 19:17:20 -08001091
Mathias Agopian27e16682013-07-08 14:00:54 -07001092 union {
1093 uint64_t data[8];
1094
1095 /* step-counter */
1096 uint64_t step_counter;
1097 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001098 };
Aravind Akella6242f322014-02-28 18:46:19 -08001099
1100 /* Reserved flags for internal use. Set to zero. */
1101 uint32_t flags;
1102
1103 uint32_t reserved1[3];
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001104} sensors_event_t;
1105
1106
Mathias Agopian16671c52013-07-24 21:07:40 -07001107/* see SENSOR_TYPE_META_DATA */
1108typedef sensors_event_t sensors_meta_data_event_t;
1109
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001110
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001111/**
1112 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
1113 * and the fields of this data structure must begin with hw_module_t
1114 * followed by module specific information.
1115 */
1116struct sensors_module_t {
1117 struct hw_module_t common;
1118
1119 /**
1120 * Enumerate all available sensors. The list is returned in "list".
1121 * @return number of sensors in the list
1122 */
1123 int (*get_sensors_list)(struct sensors_module_t* module,
1124 struct sensor_t const** list);
Ashutosh Joshi6507f502015-04-03 16:22:32 -07001125
1126 /**
1127 * Place the module in a specific mode. The following modes are defined
1128 *
Ashutosh Joshi050f2e42015-04-15 13:56:53 -07001129 * 0 - Normal operation. Default state of the module.
Peng Xu0743a5c2016-01-21 17:30:02 -08001130 * 1 - Loopback mode. Data is injected for the supported
Ashutosh Joshi050f2e42015-04-15 13:56:53 -07001131 * sensors by the sensor service in this mode.
Aravind Akellac7f54132015-06-22 18:26:54 -07001132 * @return 0 on success
Ashutosh Joshi050f2e42015-04-15 13:56:53 -07001133 * -EINVAL if requested mode is not supported
Aravind Akellac7f54132015-06-22 18:26:54 -07001134 * -EPERM if operation is not allowed
Ashutosh Joshi6507f502015-04-03 16:22:32 -07001135 */
1136 int (*set_operation_mode)(unsigned int mode);
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001137};
1138
1139struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -08001140
1141 /* Name of this sensor.
1142 * All sensors of the same "type" must have a different "name".
1143 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001144 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -08001145
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001146 /* vendor of the hardware part */
1147 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -08001148
Mathias Agopiane9eaf372011-11-07 21:32:34 -08001149 /* version of the hardware part + driver. The value of this field
1150 * must increase when the driver is updated in a way that changes the
1151 * output of this sensor. This is important for fused sensors when the
1152 * fusion algorithm is updated.
Aravind Akella6242f322014-02-28 18:46:19 -08001153 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001154 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -08001155
1156 /* handle that identifies this sensors. This handle is used to reference
1157 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001158 */
1159 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -08001160
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001161 /* this sensor's type. */
1162 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -08001163
1164 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001165 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -08001166
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001167 /* smallest difference between two values reported by this sensor */
1168 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -08001169
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001170 /* rough estimate of this sensor's power consumption in mA */
1171 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -08001172
Aravind Akellac841efd2014-06-03 19:21:35 -07001173 /* this value depends on the reporting mode:
Mathias Agopiana4557722012-11-28 17:21:55 -08001174 *
1175 * continuous: minimum sample period allowed in microseconds
1176 * on-change : 0
1177 * one-shot :-1
1178 * special : 0, unless otherwise noted
1179 */
Mathias Agopian1511e202010-07-29 15:33:22 -07001180 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -08001181
Mathias Agopian16671c52013-07-24 21:07:40 -07001182 /* number of events reserved for this sensor in the batch mode FIFO.
1183 * If there is a dedicated FIFO for this sensor, then this is the
1184 * size of this FIFO. If the FIFO is shared with other sensors,
1185 * this is the size reserved for that sensor and it can be zero.
1186 */
1187 uint32_t fifoReservedEventCount;
1188
1189 /* maximum number of events of this sensor that could be batched.
1190 * This is especially relevant when the FIFO is shared between
1191 * several sensors; this value is then set to the size of that FIFO.
1192 */
1193 uint32_t fifoMaxEventCount;
1194
Aravind Akella477fbd52014-04-07 22:46:01 +00001195 /* type of this sensor as a string. Set to corresponding
1196 * SENSOR_STRING_TYPE_*.
1197 * When defining an OEM specific sensor or sensor manufacturer specific
1198 * sensor, use your reserve domain name as a prefix.
1199 * ex: com.google.glass.onheaddetector
1200 * For sensors of known type, the android framework might overwrite this
1201 * string automatically.
1202 */
1203 const char* stringType;
1204
1205 /* permission required to see this sensor, register to it and receive data.
1206 * Set to "" if no permission is required. Some sensor types like the
1207 * heart rate monitor have a mandatory require_permission.
1208 * For sensors that always require a specific permission, like the heart
1209 * rate monitor, the android framework might overwrite this string
1210 * automatically.
1211 */
1212 const char* requiredPermission;
1213
Aravind Akella110d2f22014-09-04 15:36:31 -07001214 /* This value is defined only for continuous mode and on-change sensors. It is the delay between
1215 * two sensor events corresponding to the lowest frequency that this sensor supports. When lower
1216 * frequencies are requested through batch()/setDelay() the events will be generated at this
1217 * frequency instead. It can be used by the framework or applications to estimate when the batch
1218 * FIFO may be full.
Aravind Akellac841efd2014-06-03 19:21:35 -07001219 *
1220 * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
Aravind Akella110d2f22014-09-04 15:36:31 -07001221 * continuous, on-change: maximum sampling period allowed in microseconds.
1222 * one-shot, special : 0
Aravind Akellac841efd2014-06-03 19:21:35 -07001223 * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit
1224 * on 64 bit architectures only for binary compatibility reasons.
Aravind Akella6242f322014-02-28 18:46:19 -08001225 * Availability: SENSORS_DEVICE_API_VERSION_1_3
1226 */
1227 #ifdef __LP64__
1228 int64_t maxDelay;
1229 #else
1230 int32_t maxDelay;
1231 #endif
1232
Aravind Akellac841efd2014-06-03 19:21:35 -07001233 /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.
1234 * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.
1235 * Availability: SENSORS_DEVICE_API_VERSION_1_3
1236 */
Aravind Akella6242f322014-02-28 18:46:19 -08001237 #ifdef __LP64__
1238 uint64_t flags;
1239 #else
1240 uint32_t flags;
1241 #endif
1242
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001243 /* reserved fields, must be zero */
Aravind Akella6242f322014-02-28 18:46:19 -08001244 void* reserved[2];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001245};
1246
1247
Mathias Agopiana4557722012-11-28 17:21:55 -08001248/*
1249 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
1250 * and is present for backward binary and source compatibility.
Clay Murphy8db1fb42013-12-19 09:58:28 -08001251 * See the Sensors HAL interface section for complete descriptions of the
1252 * following functions:
1253 * http://source.android.com/devices/sensors/index.html#hal
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001254 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001255struct sensors_poll_device_t {
1256 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001257 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001258 int sensor_handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001259 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001260 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001261 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001262 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001263};
1264
Mathias Agopiana4557722012-11-28 17:21:55 -08001265/*
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001266 * struct sensors_poll_device_1 is used in HAL versions >= SENSORS_DEVICE_API_VERSION_1_0
Mathias Agopiana4557722012-11-28 17:21:55 -08001267 */
1268typedef struct sensors_poll_device_1 {
1269 union {
1270 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
1271 * and can be down-cast to it
1272 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001273 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -08001274
1275 struct {
1276 struct hw_device_t common;
1277
Clay Murphy8db1fb42013-12-19 09:58:28 -08001278 /* Activate/de-activate one sensor. Return 0 on success, negative
Mathias Agopiana4557722012-11-28 17:21:55 -08001279 *
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001280 * sensor_handle is the handle of the sensor to change.
Mathias Agopiana4557722012-11-28 17:21:55 -08001281 * enabled set to 1 to enable, or 0 to disable the sensor.
1282 *
Clay Murphy8db1fb42013-12-19 09:58:28 -08001283 * Return 0 on success, negative errno code otherwise.
Mathias Agopiana4557722012-11-28 17:21:55 -08001284 */
1285 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001286 int sensor_handle, int enabled);
Mathias Agopiana4557722012-11-28 17:21:55 -08001287
1288 /**
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001289 * Set the events's period in nanoseconds for a given sensor.
1290 * If sampling_period_ns > max_delay it will be truncated to
1291 * max_delay and if sampling_period_ns < min_delay it will be
1292 * replaced by min_delay.
Mathias Agopiana4557722012-11-28 17:21:55 -08001293 */
1294 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001295 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -08001296
1297 /**
1298 * Returns an array of sensor data.
Mathias Agopiana4557722012-11-28 17:21:55 -08001299 */
1300 int (*poll)(struct sensors_poll_device_t *dev,
1301 sensors_event_t* data, int count);
1302 };
1303 };
1304
Mathias Agopiana4557722012-11-28 17:21:55 -08001305
1306 /*
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001307 * Sets a sensor’s parameters, including sampling frequency and maximum
1308 * report latency. This function can be called while the sensor is
1309 * activated, in which case it must not cause any sensor measurements to
1310 * be lost: transitioning from one sampling rate to the other cannot cause
1311 * lost events, nor can transitioning from a high maximum report latency to
1312 * a low maximum report latency.
Clay Murphy8db1fb42013-12-19 09:58:28 -08001313 * See the Batching sensor results page for details:
1314 * http://source.android.com/devices/sensors/batching.html
Mathias Agopiana4557722012-11-28 17:21:55 -08001315 */
1316 int (*batch)(struct sensors_poll_device_1* dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001317 int sensor_handle, int flags, int64_t sampling_period_ns,
1318 int64_t max_report_latency_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -08001319
Mathias Agopian16671c52013-07-24 21:07:40 -07001320 /*
1321 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
1322 * to the end of the "batch mode" FIFO for the specified sensor and flushes
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001323 * the FIFO.
1324 * If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero),
Aravind Akellac841efd2014-06-03 19:21:35 -07001325 * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001326 * event stream. This applies to all sensors other than one-shot sensors.
1327 * If the sensor is a one-shot sensor, flush must return -EINVAL and not generate
1328 * any flush complete metadata.
Aravind Akellaa7f2cda2014-08-21 16:31:14 -07001329 * If the sensor is not active at the time flush() is called, flush() should return
1330 * -EINVAL.
Mathias Agopian16671c52013-07-24 21:07:40 -07001331 */
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001332 int (*flush)(struct sensors_poll_device_1* dev, int sensor_handle);
Mathias Agopian16671c52013-07-24 21:07:40 -07001333
Ashutosh Joshi6507f502015-04-03 16:22:32 -07001334 /*
Ashutosh Joshi050f2e42015-04-15 13:56:53 -07001335 * Inject a single sensor sample to be to this device.
1336 * data points to the sensor event to be injected
Aravind Akellac7f54132015-06-22 18:26:54 -07001337 * @return 0 on success
1338 * -EPERM if operation is not allowed
Ashutosh Joshi050f2e42015-04-15 13:56:53 -07001339 * -EINVAL if sensor event cannot be injected
Ashutosh Joshi6507f502015-04-03 16:22:32 -07001340 */
1341 int (*inject_sensor_data)(struct sensors_poll_device_1 *dev, const sensors_event_t *data);
1342
1343 void (*reserved_procs[7])(void);
Mathias Agopiana4557722012-11-28 17:21:55 -08001344
1345} sensors_poll_device_1_t;
1346
1347
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001348/** convenience API for opening and closing a device */
1349
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001350static inline int sensors_open(const struct hw_module_t* module,
1351 struct sensors_poll_device_t** device) {
1352 return module->methods->open(module,
1353 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1354}
1355
1356static inline int sensors_close(struct sensors_poll_device_t* device) {
1357 return device->common.close(&device->common);
1358}
1359
Mathias Agopiana4557722012-11-28 17:21:55 -08001360static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001361 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001362 return module->methods->open(module,
1363 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1364}
1365
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001366static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001367 return device->common.close(&device->common);
1368}
1369
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001370__END_DECLS
1371
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001372#endif // ANDROID_SENSORS_INTERFACE_H