blob: 14b8aa5bc0a7c70d53c2b8f6753fce7527f5b9d7 [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
Peng Xud1562992016-03-29 18:14:05 -0700119#define SENSOR_FLAG_MASK(nbit, shift) (((1<<(nbit))-1)<<(shift))
120#define SENSOR_FLAG_MASK_1(shift) SENSOR_FLAG_MASK(1, shift)
121
122/*
123 * Mask and shift for reporting mode sensor flags defined above.
124 */
125#define REPORTING_MODE_SHIFT (1)
126#define REPORTING_MODE_NBIT (3)
127#define REPORTING_MODE_MASK SENSOR_FLAG_MASK(REPORTING_MODE_NBIT, REPORTING_MODE_SHIFT)
128 // 0xE
129
130/*
131 * Mask and shift for data_injection mode sensor flags defined above.
132 */
133#define DATA_INJECTION_SHIFT (4)
134#define DATA_INJECTION_MASK SENSOR_FLAG_MASK_1(DATA_INJECTION_SHIFT) //0x10
135
136/*
137 * Mask and shift for dynamic sensor flag.
138 */
139#define DYNAMIC_SENSOR_SHIFT (5)
140#define DYNAMIC_SENSOR_MASK SENSOR_FLAG_MASK_1(DYNAMIC_SENSOR_SHIFT) //0x20
141
142/*
143 * Mask and shift for sensor additional information support.
144 */
145#define ADDITIONAL_INFO_SHIFT (6)
146#define ADDITIONAL_INFO_MASK SENSOR_FLAG_MASK_1(ADDITIONAL_INFO_SHIFT) //0x40
147
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700148/*
Aravind Akella6242f322014-02-28 18:46:19 -0800149 * Availability: SENSORS_DEVICE_API_VERSION_1_3
150 * Sensor flags used in sensor_t.flags.
151 */
152enum {
153 /*
Aravind Akella110d2f22014-09-04 15:36:31 -0700154 * Whether this sensor wakes up the AP from suspend mode when data is available. Whenever
155 * sensor events are delivered from a wake_up sensor, the driver needs to hold a wake_lock till
156 * the events are read by the SensorService i.e till sensors_poll_device_t.poll() is called the
157 * next time. Once poll is called again it means events have been read by the SensorService, the
158 * driver can safely release the wake_lock. SensorService will continue to hold a wake_lock till
159 * the app actually reads the events.
Aravind Akella6242f322014-02-28 18:46:19 -0800160 */
Aravind Akellac841efd2014-06-03 19:21:35 -0700161 SENSOR_FLAG_WAKE_UP = 1U << 0,
162 /*
163 * Reporting modes for various sensors. Each sensor will have exactly one of these modes set.
164 * The least significant 2nd, 3rd and 4th bits are used to represent four possible reporting
165 * modes.
166 */
167 SENSOR_FLAG_CONTINUOUS_MODE = 0, // 0000
168 SENSOR_FLAG_ON_CHANGE_MODE = 0x2, // 0010
169 SENSOR_FLAG_ONE_SHOT_MODE = 0x4, // 0100
Aravind Akellac7f54132015-06-22 18:26:54 -0700170 SENSOR_FLAG_SPECIAL_REPORTING_MODE = 0x6, // 0110
171
172 /*
173 * Set this flag if the sensor supports data_injection mode and allows data to be injected
174 * from the SensorService. When in data_injection ONLY sensors with this flag set are injected
175 * sensor data and only sensors with this flag set are activated. Eg: Accelerometer and Step
176 * Counter sensors can be set with this flag and SensorService will inject accelerometer data
177 * and read the corresponding step counts.
178 */
Peng Xud1562992016-03-29 18:14:05 -0700179 SENSOR_FLAG_SUPPORTS_DATA_INJECTION = DATA_INJECTION_MASK, // 1 0000
180
181 /*
182 * Set this flag if the sensor is a dynamically connected sensor. See
183 * dynamic_sensor_meta_event_t and SENSOR_TYPE_DYNAMIC_SENSOR_META for details.
184 */
185 SENSOR_FLAG_DYNAMIC_SENSOR = DYNAMIC_SENSOR_MASK,
186
187 /*
188 * Set this flag if sensor additional information is supported. See SENSOR_TYPE_ADDITIONAL_INFO
189 * and additional_info_event_t for details.
190 */
191 SENSOR_FLAG_ADDITIONAL_INFO = ADDITIONAL_INFO_MASK
Aravind Akella6242f322014-02-28 18:46:19 -0800192};
193
Aravind Akellac7f54132015-06-22 18:26:54 -0700194
195/*
Mathias Agopiana4557722012-11-28 17:21:55 -0800196 * Sensor type
197 *
198 * Each sensor has a type which defines what this sensor measures and how
Clay Murphy8db1fb42013-12-19 09:58:28 -0800199 * measures are reported. See the Base sensors and Composite sensors lists
200 * for complete descriptions:
201 * http://source.android.com/devices/sensors/base_triggers.html
202 * http://source.android.com/devices/sensors/composite_sensors.html
Mathias Agopian1599ec62013-08-19 14:34:47 -0700203 *
204 * Device manufacturers (OEMs) can define their own sensor types, for
205 * their private use by applications or services provided by them. Such
206 * sensor types are specific to an OEM and can't be exposed in the SDK.
207 * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE.
Aravind Akella477fbd52014-04-07 22:46:01 +0000208 *
209 * All sensors defined outside of the device private range must correspond to
210 * a type defined in this file, and must satisfy the characteristics listed in
211 * the description of the sensor type.
212 *
213 * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also
214 * has a stringType.
215 * - StringType of sensors inside of the device private range MUST be prefixed
216 * by the sensor provider's or OEM reverse domain name. In particular, they
217 * cannot use the "android.sensor" prefix.
218 * - StringType of sensors outside of the device private range MUST correspond
219 * to the one defined in this file (starting with "android.sensor").
220 * For example, accelerometers must have
221 * type=SENSOR_TYPE_ACCELEROMETER and
222 * stringType=SENSOR_STRING_TYPE_ACCELEROMETER
223 *
224 * When android introduces a new sensor type that can replace an OEM-defined
225 * sensor type, the OEM must use the official sensor type and stringType on
226 * versions of the HAL that support this new official sensor type.
227 *
228 * Example (made up): Suppose Google's Glass team wants to surface a sensor
229 * detecting that Glass is on a head.
230 * - Such a sensor is not officially supported in android KitKat
231 * - Glass devices launching on KitKat can implement a sensor with
232 * type = 0x10001 and stringType = "com.google.glass.onheaddetector"
233 * - In L android release, if android decides to define
234 * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR,
235 * those types should replace the Glass-team-specific types in all future
236 * launches.
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700237 * - When launching Glass on the L release, Google should now use the official
Aravind Akella477fbd52014-04-07 22:46:01 +0000238 * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType.
239 * - This way, all applications can now use this sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800240 */
241
242/*
Mathias Agopian1599ec62013-08-19 14:34:47 -0700243 * Base for device manufacturers private sensor types.
244 * These sensor types can't be exposed in the SDK.
245 */
246#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000
247
248/*
Mathias Agopian16671c52013-07-24 21:07:40 -0700249 * SENSOR_TYPE_META_DATA
Aravind Akellac841efd2014-06-03 19:21:35 -0700250 * reporting-mode: n/a
Mathias Agopian16671c52013-07-24 21:07:40 -0700251 * wake-up sensor: n/a
252 *
253 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
254 *
255 * SENSOR_TYPE_META_DATA is a special token used to populate the
256 * sensors_meta_data_event structure. It doesn't correspond to a physical
257 * sensor. sensors_meta_data_event are special, they exist only inside
258 * the HAL and are generated spontaneously, as opposed to be related to
259 * a physical sensor.
260 *
Mathias Agopianaf32a8d2013-08-06 20:33:38 -0700261 * sensors_meta_data_event_t.version must be META_DATA_VERSION
262 * sensors_meta_data_event_t.sensor must be 0
263 * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
264 * sensors_meta_data_event_t.reserved must be 0
265 * sensors_meta_data_event_t.timestamp must be 0
Mathias Agopian16671c52013-07-24 21:07:40 -0700266 *
267 * The payload is a meta_data_event_t, where:
268 * meta_data_event_t.what can take the following values:
269 *
270 * META_DATA_FLUSH_COMPLETE
271 * This event indicates that a previous (*flush)() call has completed for the sensor
272 * handle specified in meta_data_event_t.sensor.
273 * see (*flush)() for more details
274 *
275 * All other values for meta_data_event_t.what are reserved and
276 * must not be used.
277 *
278 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000279#define SENSOR_TYPE_META_DATA (0)
Mathias Agopian16671c52013-07-24 21:07:40 -0700280
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800281/*
Aravind Akella9057e122014-07-28 18:01:37 -0700282 * Wake up sensors.
283 * Each sensor may have either or both a wake-up and a non-wake variant.
284 * When registered in batch mode, wake-up sensors will wake up the AP when
285 * their FIFOs are full or when the batch timeout expires. A separate FIFO has
286 * to be maintained for wake up sensors and non wake up sensors. The non wake-up
287 * sensors need to overwrite their FIFOs when they are full till the AP wakes up
288 * and the wake-up sensors will wake-up the AP when their FIFOs are full or when
289 * the batch timeout expires without losing events. Wake-up and non wake-up variants
290 * of each sensor can be activated at different rates independently of each other.
291 *
292 * Note: Proximity sensor and significant motion sensor which were defined in previous
293 * releases are also wake-up sensors and should be treated as such. Wake-up one-shot
294 * sensors like SIGNIFICANT_MOTION cannot be batched, hence the text about batch above
295 * doesn't apply to them. See the definitions of SENSOR_TYPE_PROXIMITY and
296 * SENSOR_TYPE_SIGNIFICANT_MOTION for more info.
297 *
298 * Set SENSOR_FLAG_WAKE_UP flag for all wake-up sensors.
299 *
300 * For example, A device can have two sensors both of SENSOR_TYPE_ACCELEROMETER and
301 * one of them can be a wake_up sensor (with SENSOR_FLAG_WAKE_UP flag set) and the other
302 * can be a regular non wake_up sensor. Both of these sensors must be activated/deactivated
303 * independently of the other.
304 */
305
306/*
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800307 * SENSOR_TYPE_ACCELEROMETER
Aravind Akellac841efd2014-06-03 19:21:35 -0700308 * reporting-mode: continuous
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800309 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800310 * All values are in SI units (m/s^2) and measure the acceleration of the
311 * device minus the force of gravity.
312 *
Aravind Akella9057e122014-07-28 18:01:37 -0700313 * Implement the non-wake-up version of this sensor and implement the wake-up
314 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800315 */
316#define SENSOR_TYPE_ACCELEROMETER (1)
Aravind Akella477fbd52014-04-07 22:46:01 +0000317#define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800318
319/*
320 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akellac841efd2014-06-03 19:21:35 -0700321 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800322 *
323 * All values are in micro-Tesla (uT) and measure the geomagnetic
324 * field in the X, Y and Z axis.
325 *
Aravind Akella9057e122014-07-28 18:01:37 -0700326 * Implement the non-wake-up version of this sensor and implement the wake-up
327 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800328 */
329#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
330#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akella477fbd52014-04-07 22:46:01 +0000331#define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800332
333/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800334 * SENSOR_TYPE_ORIENTATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700335 * reporting-mode: continuous
Clay Murphy8db1fb42013-12-19 09:58:28 -0800336 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800337 * All values are angles in degrees.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800338 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700339 * Orientation sensors return sensor events for all 3 axes at a constant
340 * rate defined by setDelay().
Aravind Akella9057e122014-07-28 18:01:37 -0700341 *
342 * Implement the non-wake-up version of this sensor and implement the wake-up
343 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800344 */
345#define SENSOR_TYPE_ORIENTATION (3)
Aravind Akella477fbd52014-04-07 22:46:01 +0000346#define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800347
348/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800349 * SENSOR_TYPE_GYROSCOPE
Aravind Akellac841efd2014-06-03 19:21:35 -0700350 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800351 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700352 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800353 * around the X, Y and Z axis.
Aravind Akella9057e122014-07-28 18:01:37 -0700354 *
355 * Implement the non-wake-up version of this sensor and implement the wake-up
356 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800357 */
358#define SENSOR_TYPE_GYROSCOPE (4)
Aravind Akella477fbd52014-04-07 22:46:01 +0000359#define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800360
361/*
362 * SENSOR_TYPE_LIGHT
Aravind Akellac841efd2014-06-03 19:21:35 -0700363 * reporting-mode: on-change
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800364 *
365 * The light sensor value is returned in SI lux units.
Aravind Akella9057e122014-07-28 18:01:37 -0700366 *
367 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800368 */
369#define SENSOR_TYPE_LIGHT (5)
Aravind Akella477fbd52014-04-07 22:46:01 +0000370#define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800371
372/*
373 * SENSOR_TYPE_PRESSURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700374 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800375 *
376 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
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_PRESSURE (6)
Aravind Akella477fbd52014-04-07 22:46:01 +0000382#define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800383
384/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
385#define SENSOR_TYPE_TEMPERATURE (7)
Aravind Akella477fbd52014-04-07 22:46:01 +0000386#define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800387
388/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800389 * SENSOR_TYPE_PROXIMITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700390 * reporting-mode: on-change
Mike Lockwooda2414312009-11-03 10:29:50 -0500391 *
Aravind Akella9057e122014-07-28 18:01:37 -0700392 * The proximity sensor which turns the screen off and back on during calls is the
393 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
394 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
395 * SENSOR_FLAG_WAKE_UP.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800396 * The value corresponds to the distance to the nearest object in centimeters.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800397 */
398#define SENSOR_TYPE_PROXIMITY (8)
Aravind Akella477fbd52014-04-07 22:46:01 +0000399#define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800400
401/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800402 * SENSOR_TYPE_GRAVITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700403 * reporting-mode: continuous
Mathias Agopian42b743c2010-11-22 15:55:32 -0800404 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800405 * A gravity output indicates the direction of and magnitude of gravity in
Clay Murphy8db1fb42013-12-19 09:58:28 -0800406 * the devices's coordinates.
Aravind Akella9057e122014-07-28 18:01:37 -0700407 *
408 * Implement the non-wake-up version of this sensor and implement the wake-up
409 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800410 */
411#define SENSOR_TYPE_GRAVITY (9)
Aravind Akella477fbd52014-04-07 22:46:01 +0000412#define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800413
414/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800415 * SENSOR_TYPE_LINEAR_ACCELERATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700416 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800417 *
418 * Indicates the linear acceleration of the device in device coordinates,
419 * not including gravity.
Aravind Akella9057e122014-07-28 18:01:37 -0700420 *
421 * Implement the non-wake-up version of this sensor and implement the wake-up
422 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800423 */
424#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
Aravind Akella477fbd52014-04-07 22:46:01 +0000425#define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800426
427
428/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800429 * SENSOR_TYPE_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700430 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800431 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700432 * The rotation vector symbolizes the orientation of the device relative to the
Clay Murphy8db1fb42013-12-19 09:58:28 -0800433 * East-North-Up coordinates frame.
Aravind Akella9057e122014-07-28 18:01:37 -0700434 *
435 * Implement the non-wake-up version of this sensor and implement the wake-up
436 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800437 */
438#define SENSOR_TYPE_ROTATION_VECTOR (11)
Aravind Akella477fbd52014-04-07 22:46:01 +0000439#define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800440
441/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800442 * SENSOR_TYPE_RELATIVE_HUMIDITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700443 * reporting-mode: on-change
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100444 *
445 * A relative humidity sensor measures relative ambient air humidity and
446 * returns a value in percent.
Aravind Akella9057e122014-07-28 18:01:37 -0700447 *
448 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800449 */
450#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
Aravind Akella477fbd52014-04-07 22:46:01 +0000451#define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800452
453/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800454 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700455 * reporting-mode: on-change
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700456 *
457 * The ambient (room) temperature in degree Celsius.
Aravind Akella9057e122014-07-28 18:01:37 -0700458 *
459 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800460 */
461#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
Aravind Akella477fbd52014-04-07 22:46:01 +0000462#define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800463
464/*
465 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700466 * reporting-mode: continuous
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700467 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800468 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
469 * reported separately instead of being included in the measurement.
Aravind Akella9057e122014-07-28 18:01:37 -0700470 *
471 * Implement the non-wake-up version of this sensor and implement the wake-up
472 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800473 */
474#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
Aravind Akella477fbd52014-04-07 22:46:01 +0000475#define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800476
477/*
478 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700479 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800480 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800481 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
Clay Murphy8db1fb42013-12-19 09:58:28 -0800482 * field.
Aravind Akella9057e122014-07-28 18:01:37 -0700483 *
484 * Implement the non-wake-up version of this sensor and implement the wake-up
485 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800486 */
487#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
Aravind Akella477fbd52014-04-07 22:46:01 +0000488#define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800489
490/*
491 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700492 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800493 *
494 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800495 * around the X, Y and Z axis.
Aravind Akella9057e122014-07-28 18:01:37 -0700496 *
497 * Implement the non-wake-up version of this sensor and implement the wake-up
498 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800499 */
500#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
Aravind Akella477fbd52014-04-07 22:46:01 +0000501#define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800502
Mathias Agopiana4557722012-11-28 17:21:55 -0800503/*
504 * SENSOR_TYPE_SIGNIFICANT_MOTION
Aravind Akellac841efd2014-06-03 19:21:35 -0700505 * reporting-mode: one-shot
Mathias Agopiana4557722012-11-28 17:21:55 -0800506 *
507 * A sensor of this type triggers an event each time significant motion
508 * is detected and automatically disables itself.
Aravind Akella9057e122014-07-28 18:01:37 -0700509 * For Significant Motion sensor to be useful, it must be defined as a
510 * wake-up sensor. (set SENSOR_FLAG_WAKE_UP). Implement the wake-up significant motion
511 * sensor. A non wake-up version is not useful.
Mathias Agopiana4557722012-11-28 17:21:55 -0800512 * The only allowed value to return is 1.0.
Mathias Agopiana4557722012-11-28 17:21:55 -0800513 */
514
515#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
Aravind Akella477fbd52014-04-07 22:46:01 +0000516#define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
Mathias Agopiana4557722012-11-28 17:21:55 -0800517
518/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800519 * SENSOR_TYPE_STEP_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700520 * reporting-mode: special
Mathias Agopiana4557722012-11-28 17:21:55 -0800521 *
522 * A sensor of this type triggers an event each time a step is taken
Clay Murphy8db1fb42013-12-19 09:58:28 -0800523 * by the user. The only allowed value to return is 1.0 and an event
524 * is generated for each step.
Aravind Akella9057e122014-07-28 18:01:37 -0700525 *
526 * Both wake-up and non wake-up versions are useful.
Mathias Agopiana4557722012-11-28 17:21:55 -0800527 */
528
Mathias Agopian2f276f52013-01-28 17:54:41 -0800529#define SENSOR_TYPE_STEP_DETECTOR (18)
Aravind Akella477fbd52014-04-07 22:46:01 +0000530#define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
Mathias Agopiana4557722012-11-28 17:21:55 -0800531
532
533/*
534 * SENSOR_TYPE_STEP_COUNTER
Aravind Akellac841efd2014-06-03 19:21:35 -0700535 * reporting-mode: on-change
Mathias Agopiana4557722012-11-28 17:21:55 -0800536 *
537 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800538 * the last reboot while activated. The value is returned as a uint64_t and is
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700539 * reset to zero only on a system / android reboot.
Aravind Akella9057e122014-07-28 18:01:37 -0700540 *
541 * Implement the non-wake-up version of this sensor and implement the wake-up
542 * version if the system possesses a wake up fifo.
Mathias Agopiana4557722012-11-28 17:21:55 -0800543 */
544
545#define SENSOR_TYPE_STEP_COUNTER (19)
Aravind Akella477fbd52014-04-07 22:46:01 +0000546#define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
Mathias Agopiana4557722012-11-28 17:21:55 -0800547
Etienne Le Grandca858142013-02-26 19:17:20 -0800548/*
549 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700550 * reporting-mode: continuous
Etienne Le Grandca858142013-02-26 19:17:20 -0800551 *
552 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
553 * of using a gyroscope.
Aravind Akella9057e122014-07-28 18:01:37 -0700554 *
555 * Implement the non-wake-up version of this sensor and implement the wake-up
556 * version if the system possesses a wake up fifo.
Etienne Le Grandca858142013-02-26 19:17:20 -0800557 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000558#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
559#define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
560
561/*
562 * SENSOR_TYPE_HEART_RATE
Aravind Akellac841efd2014-06-03 19:21:35 -0700563 * reporting-mode: on-change
Aravind Akella477fbd52014-04-07 22:46:01 +0000564 *
Etienne Le Grand7b361582014-05-16 11:08:28 -0700565 * A sensor of this type returns the current heart rate.
566 * The events contain the current heart rate in beats per minute (BPM) and the
567 * status of the sensor during the measurement. See heart_rate_event_t for more
568 * details.
569 *
570 * Because this sensor is on-change, events must be generated when and only
571 * when heart_rate.bpm or heart_rate.status have changed since the last
Vinod Krishnan74279e32014-08-28 15:25:13 -0700572 * event. In particular, upon the first activation, unless the device is known
573 * to not be on the body, the status field of the first event must be set to
574 * SENSOR_STATUS_UNRELIABLE. The event should be generated no faster than every
575 * period_ns passed to setDelay() or to batch().
Griff Hazenf0f67e62014-08-28 17:02:50 -0700576 * See the definition of the on-change reporting mode for more information.
Etienne Le Grand7b361582014-05-16 11:08:28 -0700577 *
Aravind Akella477fbd52014-04-07 22:46:01 +0000578 * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
Aravind Akella9057e122014-07-28 18:01:37 -0700579 *
580 * Both wake-up and non wake-up versions are useful.
Aravind Akella477fbd52014-04-07 22:46:01 +0000581 */
582#define SENSOR_TYPE_HEART_RATE (21)
583#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
Mathias Agopiana4557722012-11-28 17:21:55 -0800584
Aravind Akella6242f322014-02-28 18:46:19 -0800585/*
Aravind Akellaf895c682014-04-30 11:46:09 -0700586 * SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700587 * reporting-mode: special (setDelay has no impact)
Aravind Akellaf895c682014-04-30 11:46:09 -0700588 *
589 * A sensor of this type generates an event each time a tilt event is detected. A tilt event
590 * 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 -0700591 * 35 degrees since the activation or the last trigger of the sensor.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700592 * reference_estimated_gravity = average of accelerometer measurements over the first
Etienne Le Grand53017ef2014-05-28 15:42:48 -0700593 * 1 second after activation or the estimated gravity at the last
594 * trigger.
Aravind Akellaf895c682014-04-30 11:46:09 -0700595 * current_estimated_gravity = average of accelerometer measurements over the last 2 seconds.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700596 * trigger when angle (reference_estimated_gravity, current_estimated_gravity) > 35 degrees
Aravind Akellaf895c682014-04-30 11:46:09 -0700597 *
598 * Large accelerations without a change in phone orientation should not trigger a tilt event.
599 * For example, a sharp turn or strong acceleration while driving a car should not trigger a tilt
600 * event, even though the angle of the average acceleration might vary by more than 35 degrees.
601 *
602 * Typically, this sensor is implemented with the help of only an accelerometer. Other sensors can
603 * be used as well if they do not increase the power consumption significantly. This is a low power
604 * sensor that should allow the AP to go into suspend mode. Do not emulate this sensor in the HAL.
605 * Like other wake up sensors, the driver is expected to a hold a wake_lock with a timeout of 200 ms
606 * while reporting this event. The only allowed return value is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700607 *
608 * Implement only the wake-up version of this sensor.
Aravind Akellaf895c682014-04-30 11:46:09 -0700609 */
Aravind Akella9057e122014-07-28 18:01:37 -0700610#define SENSOR_TYPE_TILT_DETECTOR (22)
611#define SENSOR_STRING_TYPE_TILT_DETECTOR "android.sensor.tilt_detector"
Aravind Akellaf895c682014-04-30 11:46:09 -0700612
Etienne Le Grandba123122014-05-05 18:20:42 -0700613/*
614 * SENSOR_TYPE_WAKE_GESTURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700615 * reporting-mode: one-shot
Etienne Le Grandba123122014-05-05 18:20:42 -0700616 *
617 * A sensor enabling waking up the device based on a device specific motion.
618 *
619 * When this sensor triggers, the device behaves as if the power button was
620 * pressed, turning the screen on. This behavior (turning on the screen when
621 * this sensor triggers) might be deactivated by the user in the device
622 * settings. Changes in settings do not impact the behavior of the sensor:
623 * only whether the framework turns the screen on when it triggers.
624 *
625 * The actual gesture to be detected is not specified, and can be chosen by
626 * the manufacturer of the device.
627 * This sensor must be low power, as it is likely to be activated 24/7.
628 * The only allowed value to return is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700629 *
630 * Implement only the wake-up version of this sensor.
Etienne Le Grandba123122014-05-05 18:20:42 -0700631 */
Aravind Akella9057e122014-07-28 18:01:37 -0700632#define SENSOR_TYPE_WAKE_GESTURE (23)
Etienne Le Grandba123122014-05-05 18:20:42 -0700633#define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture"
634
Jeff Brown8df2feb2014-07-17 15:11:51 -0700635/*
636 * SENSOR_TYPE_GLANCE_GESTURE
637 * reporting-mode: one-shot
Jeff Brown8df2feb2014-07-17 15:11:51 -0700638 *
639 * A sensor enabling briefly turning the screen on to enable the user to
640 * glance content on screen based on a specific motion. The device should
641 * turn the screen off after a few moments.
642 *
643 * When this sensor triggers, the device turns the screen on momentarily
644 * to allow the user to glance notifications or other content while the
645 * device remains locked in a non-interactive state (dozing). This behavior
646 * (briefly turning on the screen when this sensor triggers) might be deactivated
647 * by the user in the device settings. Changes in settings do not impact the
648 * behavior of the sensor: only whether the framework briefly turns the screen on
649 * when it triggers.
650 *
651 * The actual gesture to be detected is not specified, and can be chosen by
652 * the manufacturer of the device.
653 * This sensor must be low power, as it is likely to be activated 24/7.
654 * The only allowed value to return is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700655 *
656 * Implement only the wake-up version of this sensor.
Jeff Brown8df2feb2014-07-17 15:11:51 -0700657 */
Aravind Akella9057e122014-07-28 18:01:37 -0700658#define SENSOR_TYPE_GLANCE_GESTURE (24)
Jeff Brown8df2feb2014-07-17 15:11:51 -0700659#define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture"
660
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800661/**
Aravind Akella952471e2014-07-17 12:40:54 -0700662 * SENSOR_TYPE_PICK_UP_GESTURE
663 * reporting-mode: one-shot
Aravind Akella952471e2014-07-17 12:40:54 -0700664 *
665 * A sensor of this type triggers when the device is picked up regardless of wherever is was
666 * before (desk, pocket, bag). The only allowed return value is 1.0.
667 * This sensor de-activates itself immediately after it triggers.
Aravind Akella9057e122014-07-28 18:01:37 -0700668 *
669 * Implement only the wake-up version of this sensor.
Aravind Akella952471e2014-07-17 12:40:54 -0700670 */
Aravind Akella9057e122014-07-28 18:01:37 -0700671#define SENSOR_TYPE_PICK_UP_GESTURE (25)
Aravind Akella952471e2014-07-17 12:40:54 -0700672#define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture"
673
Nick Vaccaroadbfbb72015-01-13 12:14:28 -0800674/*
675 * SENSOR_TYPE_WRIST_TILT_GESTURE
676 * trigger-mode: special
677 * wake-up sensor: yes
678 *
679 * A sensor of this type triggers an event each time a tilt of the wrist-worn
680 * device is detected.
681 *
682 * This sensor must be low power, as it is likely to be activated 24/7.
683 * The only allowed value to return is 1.0.
684 *
685 * Implement only the wake-up version of this sensor.
686 */
687#define SENSOR_TYPE_WRIST_TILT_GESTURE (26)
688#define SENSOR_STRING_TYPE_WRIST_TILT_GESTURE "android.sensor.wrist_tilt_gesture"
689
Trevor Bunkerf8e7ed32016-01-08 10:22:23 -0800690/*
691 * SENSOR_TYPE_DEVICE_ORIENTATION
692 * reporting-mode: on-change
693 *
694 * The current orientation of the device. The value should be reported in the
695 * first element of the 'data' member variable in sensors_event_t. The only
696 * values that can be reported are (please refer to Android Sensor Coordinate
697 * System to understand the X and Y axis direction with respect to default
698 * orientation):
699 * - 0: device is in default orientation (Y axis is vertical and points up)
700 * - 1: device is rotated 90 degrees counter-clockwise from default
701 * orientation (X axis is vertical and points up)
702 * - 2: device is rotated 180 degrees from default orientation (Y axis is
703 * vertical and points down)
704 * - 3: device is rotated 90 degrees clockwise from default orientation (X axis
705 * is vertical and points down)
706 *
707 * Moving the device to an orientation where the Z axis is vertical (either up
708 * or down) should not cause a new event to be reported.
709 *
710 * To improve the user experience of this sensor, it is recommended to implement
711 * some physical (i.e., rotation angle) and temporal (i.e., delay) hysteresis.
712 * In other words, minor or transient rotations should not cause a new event to
713 * be reported.
714 *
715 * This sensor should only be implemented with the help of an accelerometer.
716 * This is a low power sensor that should reduce the number of interrupts of the
717 * AP. Do not emulate this sensor in the HAL.
718 *
719 * Both wake-up and non wake-up versions are useful.
720 */
721#define SENSOR_TYPE_DEVICE_ORIENTATION (27)
722#define SENSOR_STRING_TYPE_DEVICE_ORIENTATION "android.sensor.device_orientation"
723
Ashutosh Joshied021ea2016-01-14 22:28:24 -0800724/*
725 * SENSOR_TYPE_POSE_6DOF
726 * trigger-mode: continuous
727 *
728 * A sensor of this type returns the pose of the device.
729 * Pose of the device is defined as the orientation of the device from a
730 * Earth Centered Earth Fixed frame and the translation from an arbitrary
731 * point at subscription.
732 *
733 * This sensor can be high power. It can use any and all of the following
734 * . Accelerometer
735 * . Gyroscope
736 * . Camera
737 * . Depth Camera
738 *
Ashutosh Joshied021ea2016-01-14 22:28:24 -0800739 */
740#define SENSOR_TYPE_POSE_6DOF (28)
741#define SENSOR_STRING_TYPE_POSE_6DOF "android.sensor.pose_6dof"
742
Ashutosh Joshicb963312016-01-25 18:48:57 -0800743/*
744 * SENSOR_TYPE_STATIONARY_DETECT
745 * trigger mode: one shot
746 *
747 * A sensor of this type returns an event if the device is still/stationary for
748 * a while. The period of time to monitor for statinarity should be greater than
749 * 5 seconds, and less than 10 seconds.
750 *
751 * Stationarity here refers to absolute stationarity. eg: device on desk.
752 *
753 * The only allowed value to return is 1.0.
754 */
755#define SENSOR_TYPE_STATIONARY_DETECT (29)
756#define SENSOR_STRING_TYPE_STATIONARY_DETECT "android.sensor.stationary_detect"
757
758/*
759 * SENSOR_TYPE_MOTION_DETECT
760 * trigger mode: one shot
761 *
762 * A sensor of this type returns an event if the device is not still for
763 * a while. The period of time to monitor for statinarity should be greater than
764 * 5 seconds, and less than 10 seconds.
765 *
766 * Motion here refers to any mechanism in which the device is causes to be
767 * moved in its inertial frame. eg: Pickin up the device and walking with it
768 * to a nearby room may trigger motion wherewas keeping the device on a table
769 * on a smooth train moving at constant velocity may not trigger motion.
770 *
771 * The only allowed value to return is 1.0.
772 */
773#define SENSOR_TYPE_MOTION_DETECT (30)
774#define SENSOR_STRING_TYPE_MOTION_DETECT "android.sensor.motion_detect"
775
776/*
777 * SENSOR_TYPE_HEART_BEAT
778 * trigger mode: continuous
779 *
780 * A sensor of this type returns an event everytime a hear beat peak is
781 * detected.
782 *
783 * Peak here ideally corresponds to the positive peak in the QRS complex of
Peng Xue641ba92016-01-20 00:27:21 -0800784 * and ECG signal.
Ashutosh Joshicb963312016-01-25 18:48:57 -0800785 *
786 * The sensor is not expected to be optimized for latency. As a guide, a
787 * latency of up to 10 seconds is acceptable. However the timestamp attached
788 * to the event should be accurate and should correspond to the time the peak
789 * occured.
790 *
791 * The sensor event contains a parameter for the confidence in the detection
792 * of the peak where 0.0 represent no information at all, and 1.0 represents
793 * certainty.
794 */
795#define SENSOR_TYPE_HEART_BEAT (31)
796#define SENSOR_STRING_TYPE_HEART_BEAT "android.sensor.heart_beat"
797
Aravind Akella952471e2014-07-17 12:40:54 -0700798/**
Peng Xue641ba92016-01-20 00:27:21 -0800799 * SENSOR_TYPE_DYNAMIC_SENSOR_META
800 * trigger-mode: special
801 *
802 * A sensor event of this type is received when a dynamic sensor is added to or removed from the
803 * system. At most one sensor of this type can be present in one sensor HAL implementation and
804 * presence of a sensor of this type in sensor HAL implementation indicates that this sensor HAL
805 * supports dynamic sensor feature. Operations, such as batch, activate and setDelay, to this
806 * special purpose sensor should be treated as no-op and return successful.
807 *
808 * A dynamic sensor connection indicates connection of a physical device or instantiation of a
809 * virtual sensor backed by algorithm; and a dynamic sensor disconnection indicates the the
810 * opposite. A sensor event of SENSOR_TYPE_DYNAMIC_SENSOR_META type should be delivered regardless
811 * of the activation status of the sensor in the event of dynamic sensor connection and
812 * disconnection. In the sensor event, besides the common data entries, "dynamic_sensor_meta", which
813 * includes fields for connection status, handle of the sensor involved, pointer to sensor_t
814 * structure and a uuid field, should be populated.
815 *
816 * At a dynamic sensor connection event, fields of sensor_t structure referenced by a pointer in
817 * dynamic_sensor_meta should be filled as if it was regular sensors. Sensor HAL is responsible for
818 * recovery of memory if the corresponding data is dynamicially allocated. However, the the pointer
819 * must be valid until the first activate call to the sensor reported in this connection event. At a
820 * dynamic sensor disconnection, the sensor_t pointer should be NULL.
821 *
822 * The sensor handle assigned to dynamic sensors should never be the same as that of any regular
823 * static sensors, and should be unique until next boot. In another word, if a handle h is used for
824 * a dynamic sensor A, that same number cannot be used for the same dynamic sensor A or another
825 * dynamic sensor B even after disconnection of A until reboot.
826 *
827 * The UUID field will be used for identifying the sensor in addition to name, vendor and version
828 * and type. For physical sensors of the same model, all sensors will have the same values in
829 * sensor_t, but the UUID should be unique and persistent for each individual unit. An all zero UUID
830 * indicates it is not possible to differentiate individual sensor unit.
831 *
832 */
833#define SENSOR_TYPE_DYNAMIC_SENSOR_META (32)
834#define SENSOR_STRING_TYPE_DYNAMIC_SENSOR_META "android.sensor.dynamic_sensor_meta"
835
836/**
Peng Xu0743a5c2016-01-21 17:30:02 -0800837 * SENSOR_TYPE_ADDITIONAL_INFO
838 * reporting-mode: N/A
839 *
840 * This sensor type is for delivering additional sensor information aside from sensor event data.
841 * Additional information may include sensor front-end group delay, internal calibration parameters,
842 * noise level metrics, device internal temperature, etc.
843 *
844 * This type will never bind to a sensor. In other words, no sensor in the sensor list should be of
845 * the type SENSOR_TYPE_ADDITIONAL_INFO. If a sensor HAL supports sensor additional information
846 * feature, it reports sensor_event_t with "sensor" field set to handle of the reporting sensor and
847 * "type" field set to SENSOR_TYPE_ADDITIONAL_INFO. Delivery of additional information events is
848 * triggered under two conditions: an enable activate() call or a flush() call to the corresponding
849 * sensor.
850 *
851 * A single additional information report consists of multiple frames. Sequences of these frames are
852 * ordered using timestamps, which means the timestamps of sequential frames have to be at least 1
853 * nanosecond apart from each other. Each frame is a sensor_event_t delivered through the HAL
854 * interface, with related data stored in the "additional_info" field, which is of type
855 * additional_info_event_t. The "type" field of additional_info_event_t denotes the nature of the
856 * payload data (see additional_info_type_t). The "serial" field is used to keep the sequence of
857 * payload data that spans multiple frames. The first frame of the entire report is always of type
858 * AINFO_BEGIN, and the last frame is always AINFO_END.
859 *
860 * All additional information frames have to be delivered after flush complete event if flush() was
861 * triggering the report.
862 */
863#define SENSOR_TYPE_ADDITIONAL_INFO (33)
864#define SENSOR_STRING_TYPE_ADDITIONAL_INFO "android.sensor.additional_info"
865
866/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800867 * Values returned by the accelerometer in various locations in the universe.
868 * all values are in SI units (m/s^2)
869 */
870#define GRAVITY_SUN (275.0f)
871#define GRAVITY_EARTH (9.80665f)
872
873/** Maximum magnetic field on Earth's surface */
874#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
875
876/** Minimum magnetic field on Earth's surface */
877#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
878
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800879/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700880 * Possible values of the status field of sensor events.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800881 */
Etienne Le Grand7b361582014-05-16 11:08:28 -0700882#define SENSOR_STATUS_NO_CONTACT -1
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800883#define SENSOR_STATUS_UNRELIABLE 0
884#define SENSOR_STATUS_ACCURACY_LOW 1
885#define SENSOR_STATUS_ACCURACY_MEDIUM 2
886#define SENSOR_STATUS_ACCURACY_HIGH 3
887
Peng Xue641ba92016-01-20 00:27:21 -0800888
889struct sensor_t;
890
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800891/**
892 * sensor event data
893 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800894typedef struct {
895 union {
896 float v[3];
897 struct {
898 float x;
899 float y;
900 float z;
901 };
902 struct {
903 float azimuth;
904 float pitch;
905 float roll;
906 };
907 };
908 int8_t status;
909 uint8_t reserved[3];
910} sensors_vec_t;
911
912/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800913 * uncalibrated gyroscope and magnetometer event data
914 */
915typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700916 union {
917 float uncalib[3];
918 struct {
919 float x_uncalib;
920 float y_uncalib;
921 float z_uncalib;
922 };
923 };
924 union {
925 float bias[3];
926 struct {
927 float x_bias;
928 float y_bias;
929 float z_bias;
930 };
931 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800932} uncalibrated_event_t;
933
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700934/**
935 * Meta data event data
936 */
Mathias Agopian16671c52013-07-24 21:07:40 -0700937typedef struct meta_data_event {
938 int32_t what;
939 int32_t sensor;
940} meta_data_event_t;
941
Etienne Le Grandca858142013-02-26 19:17:20 -0800942/**
Peng Xue641ba92016-01-20 00:27:21 -0800943 * Dynamic sensor meta event. See the description of SENSOR_TYPE_DYNAMIC_SENSOR_META type for
944 * details.
945 */
946typedef struct dynamic_sensor_meta_event {
Peng Xue20707a2016-01-27 18:26:10 -0800947 int32_t connected;
948 int32_t handle;
Peng Xue641ba92016-01-20 00:27:21 -0800949 const struct sensor_t * sensor; // should be NULL if connected == false
950 uint8_t uuid[16]; // UUID of a dynamic sensor (use platform endianess).
951} dynamic_sensor_meta_event_t;
952
953/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700954 * Heart rate event data
955 */
956typedef struct {
957 // Heart rate in beats per minute.
958 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
959 float bpm;
960 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700961 // Note that this value should only be set for sensors that explicitly define
962 // the meaning of this field. This field is not piped through the framework
963 // for other sensors.
Etienne Le Grand7b361582014-05-16 11:08:28 -0700964 int8_t status;
965} heart_rate_event_t;
966
Peng Xu0743a5c2016-01-21 17:30:02 -0800967typedef struct {
968 int32_t type; // type of payload data, see additional_info_type_t
969 int32_t serial; // sequence number of this frame for this type
970 union {
971 // for each frame, a single data type, either int32_t or float, should be used.
972 int32_t data_int32[14];
973 float data_float[14];
974 };
975} additional_info_event_t;
976
977typedef enum additional_info_type {
978 //
979 AINFO_BEGIN = 0x0, // Marks the beginning of additional information frames
980 AINFO_END = 0x1, // Marks the end of additional information frames
981 // Basic information
982 AINFO_UNTRACKED_DELAY = 0x10000, // Estimation of the delay that is not tracked by sensor
983 // timestamps. This includes delay introduced by
984 // sensor front-end filtering, data transport, etc.
985 // float[2]: delay in seconds
986 // standard deviation of estimated value
987 //
988 AINFO_INTERNAL_TEMPERATURE, // float: Celsius temperature.
989 //
990 AINFO_VEC3_CALIBRATION, // First three rows of a homogeneous matrix, which
991 // represents calibration to a three-element vector
992 // raw sensor reading.
993 // float[12]: 3x4 matrix in row major order
994 //
995 AINFO_SENSOR_PLACEMENT, // Location and orientation of sensor element in the
996 // device frame: origin is the geometric center of the
997 // mobile device screen surface; the axis definition
998 // corresponds to Android sensor definitions.
999 // float[12]: 3x4 matrix in row major order
1000 //
1001 AINFO_SAMPLING, // float[2]: raw sample period in seconds,
1002 // standard deviation of sampling period
1003
1004 // Sampling channel modeling information
1005 AINFO_CHANNEL_NOISE = 0x20000, // int32_t: noise type
1006 // float[n]: parameters
1007 //
1008 AINFO_CHANNEL_SAMPLER, // float[3]: sample period
1009 // standard deviation of sample period,
1010 // quantization unit
1011 //
1012 AINFO_CHANNEL_FILTER, // Represents a filter:
1013 // \sum_j a_j y[n-j] == \sum_i b_i x[n-i]
1014 //
1015 // int32_t[3]: number of feedforward coefficients, M,
1016 // number of feedback coefficients, N, for
1017 // FIR filter, N=1.
1018 // bit mask that represents which element to
1019 // which the filter is applied, bit 0 == 1
1020 // means this filter applies to vector
1021 // element 0.
1022 // float[M+N]: filter coefficients (b0, b1, ..., BM-1),
1023 // then (a0, a1, ..., aN-1), a0 is always 1.
1024 // Multiple frames may be needed for higher
1025 // number of taps.
1026 //
1027 AINFO_CHANNEL_LINEAR_TRANSFORM, // int32_t[2]: size in (row, column) ... 1st frame
1028 // float[n]: matrix element values in row major order.
1029 //
1030 AINFO_CHANNEL_NONLINEAR_MAP, // int32_t[2]: extrapolate method
1031 // interpolate method
1032 // float[n]: mapping key points in pairs, (in, out)...
1033 // (may be used to model saturation)
1034 //
1035 AINFO_CHANNEL_RESAMPLER, // int32_t: resample method (0-th order, 1st order...)
1036 // float[1]: resample ratio (upsampling if < 1.0;
1037 // downsampling if > 1.0).
1038 //
1039
1040 // Custom information
1041 AINFO_CUSTOM_START = 0x10000000, //
1042 // Debugging
1043 AINFO_DEBUGGING_START = 0x40000000, //
1044} additional_info_type_t;
1045
Etienne Le Grand7b361582014-05-16 11:08:28 -07001046/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001047 * Union of the various types of sensor data
1048 * that can be returned.
1049 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001050typedef struct sensors_event_t {
1051 /* must be sizeof(struct sensors_event_t) */
1052 int32_t version;
1053
1054 /* sensor identifier */
1055 int32_t sensor;
1056
1057 /* sensor type */
1058 int32_t type;
1059
1060 /* reserved */
1061 int32_t reserved0;
1062
1063 /* time is in nanosecond */
1064 int64_t timestamp;
1065
1066 union {
Mathias Agopian27e16682013-07-08 14:00:54 -07001067 union {
1068 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001069
Mathias Agopian27e16682013-07-08 14:00:54 -07001070 /* acceleration values are in meter per second per second (m/s^2) */
1071 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001072
Mathias Agopian27e16682013-07-08 14:00:54 -07001073 /* magnetic vector values are in micro-Tesla (uT) */
1074 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001075
Mathias Agopian27e16682013-07-08 14:00:54 -07001076 /* orientation values are in degrees */
1077 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001078
Mathias Agopian27e16682013-07-08 14:00:54 -07001079 /* gyroscope values are in rad/s */
1080 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -07001081
Mathias Agopian27e16682013-07-08 14:00:54 -07001082 /* temperature is in degrees centigrade (Celsius) */
1083 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001084
Mathias Agopian27e16682013-07-08 14:00:54 -07001085 /* distance in centimeters */
1086 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001087
Mathias Agopian27e16682013-07-08 14:00:54 -07001088 /* light in SI lux units */
1089 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -07001090
Mathias Agopian27e16682013-07-08 14:00:54 -07001091 /* pressure in hectopascal (hPa) */
1092 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +01001093
Mathias Agopian27e16682013-07-08 14:00:54 -07001094 /* relative humidity in percent */
1095 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -08001096
Mathias Agopian27e16682013-07-08 14:00:54 -07001097 /* uncalibrated gyroscope values are in rad/s */
1098 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -08001099
Mathias Agopian27e16682013-07-08 14:00:54 -07001100 /* uncalibrated magnetometer values are in micro-Teslas */
1101 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -07001102
Etienne Le Grand7b361582014-05-16 11:08:28 -07001103 /* heart rate data containing value in bpm and status */
1104 heart_rate_event_t heart_rate;
Aravind Akella477fbd52014-04-07 22:46:01 +00001105
Mathias Agopian16671c52013-07-24 21:07:40 -07001106 /* this is a special event. see SENSOR_TYPE_META_DATA above.
1107 * sensors_meta_data_event_t events are all reported with a type of
1108 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
1109 */
1110 meta_data_event_t meta_data;
Peng Xue641ba92016-01-20 00:27:21 -08001111
1112 /* dynamic sensor meta event. See SENSOR_TYPE_DYNAMIC_SENSOR_META type for details */
1113 dynamic_sensor_meta_event_t dynamic_sensor_meta;
Peng Xu0743a5c2016-01-21 17:30:02 -08001114
1115 /*
1116 * special additional sensor information frame, see
1117 * SENSOR_TYPE_ADDITIONAL_INFO for details.
1118 */
1119 additional_info_event_t additional_info;
Mathias Agopian27e16682013-07-08 14:00:54 -07001120 };
Etienne Le Grandca858142013-02-26 19:17:20 -08001121
Mathias Agopian27e16682013-07-08 14:00:54 -07001122 union {
1123 uint64_t data[8];
1124
1125 /* step-counter */
1126 uint64_t step_counter;
1127 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001128 };
Aravind Akella6242f322014-02-28 18:46:19 -08001129
1130 /* Reserved flags for internal use. Set to zero. */
1131 uint32_t flags;
1132
1133 uint32_t reserved1[3];
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001134} sensors_event_t;
1135
1136
Mathias Agopian16671c52013-07-24 21:07:40 -07001137/* see SENSOR_TYPE_META_DATA */
1138typedef sensors_event_t sensors_meta_data_event_t;
1139
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001140
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001141/**
1142 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
1143 * and the fields of this data structure must begin with hw_module_t
1144 * followed by module specific information.
1145 */
1146struct sensors_module_t {
1147 struct hw_module_t common;
1148
1149 /**
1150 * Enumerate all available sensors. The list is returned in "list".
1151 * @return number of sensors in the list
1152 */
1153 int (*get_sensors_list)(struct sensors_module_t* module,
1154 struct sensor_t const** list);
Ashutosh Joshi6507f502015-04-03 16:22:32 -07001155
1156 /**
1157 * Place the module in a specific mode. The following modes are defined
1158 *
Ashutosh Joshi050f2e42015-04-15 13:56:53 -07001159 * 0 - Normal operation. Default state of the module.
Peng Xu0743a5c2016-01-21 17:30:02 -08001160 * 1 - Loopback mode. Data is injected for the supported
Ashutosh Joshi050f2e42015-04-15 13:56:53 -07001161 * sensors by the sensor service in this mode.
Aravind Akellac7f54132015-06-22 18:26:54 -07001162 * @return 0 on success
Ashutosh Joshi050f2e42015-04-15 13:56:53 -07001163 * -EINVAL if requested mode is not supported
Aravind Akellac7f54132015-06-22 18:26:54 -07001164 * -EPERM if operation is not allowed
Ashutosh Joshi6507f502015-04-03 16:22:32 -07001165 */
1166 int (*set_operation_mode)(unsigned int mode);
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001167};
1168
1169struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -08001170
1171 /* Name of this sensor.
1172 * All sensors of the same "type" must have a different "name".
1173 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001174 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -08001175
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001176 /* vendor of the hardware part */
1177 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -08001178
Mathias Agopiane9eaf372011-11-07 21:32:34 -08001179 /* version of the hardware part + driver. The value of this field
1180 * must increase when the driver is updated in a way that changes the
1181 * output of this sensor. This is important for fused sensors when the
1182 * fusion algorithm is updated.
Aravind Akella6242f322014-02-28 18:46:19 -08001183 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001184 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -08001185
1186 /* handle that identifies this sensors. This handle is used to reference
1187 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001188 */
1189 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -08001190
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001191 /* this sensor's type. */
1192 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -08001193
1194 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001195 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -08001196
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001197 /* smallest difference between two values reported by this sensor */
1198 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -08001199
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001200 /* rough estimate of this sensor's power consumption in mA */
1201 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -08001202
Aravind Akellac841efd2014-06-03 19:21:35 -07001203 /* this value depends on the reporting mode:
Mathias Agopiana4557722012-11-28 17:21:55 -08001204 *
1205 * continuous: minimum sample period allowed in microseconds
1206 * on-change : 0
1207 * one-shot :-1
1208 * special : 0, unless otherwise noted
1209 */
Mathias Agopian1511e202010-07-29 15:33:22 -07001210 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -08001211
Mathias Agopian16671c52013-07-24 21:07:40 -07001212 /* number of events reserved for this sensor in the batch mode FIFO.
1213 * If there is a dedicated FIFO for this sensor, then this is the
1214 * size of this FIFO. If the FIFO is shared with other sensors,
1215 * this is the size reserved for that sensor and it can be zero.
1216 */
1217 uint32_t fifoReservedEventCount;
1218
1219 /* maximum number of events of this sensor that could be batched.
1220 * This is especially relevant when the FIFO is shared between
1221 * several sensors; this value is then set to the size of that FIFO.
1222 */
1223 uint32_t fifoMaxEventCount;
1224
Aravind Akella477fbd52014-04-07 22:46:01 +00001225 /* type of this sensor as a string. Set to corresponding
1226 * SENSOR_STRING_TYPE_*.
1227 * When defining an OEM specific sensor or sensor manufacturer specific
1228 * sensor, use your reserve domain name as a prefix.
1229 * ex: com.google.glass.onheaddetector
1230 * For sensors of known type, the android framework might overwrite this
1231 * string automatically.
1232 */
1233 const char* stringType;
1234
1235 /* permission required to see this sensor, register to it and receive data.
1236 * Set to "" if no permission is required. Some sensor types like the
1237 * heart rate monitor have a mandatory require_permission.
1238 * For sensors that always require a specific permission, like the heart
1239 * rate monitor, the android framework might overwrite this string
1240 * automatically.
1241 */
1242 const char* requiredPermission;
1243
Aravind Akella110d2f22014-09-04 15:36:31 -07001244 /* This value is defined only for continuous mode and on-change sensors. It is the delay between
1245 * two sensor events corresponding to the lowest frequency that this sensor supports. When lower
1246 * frequencies are requested through batch()/setDelay() the events will be generated at this
1247 * frequency instead. It can be used by the framework or applications to estimate when the batch
1248 * FIFO may be full.
Aravind Akellac841efd2014-06-03 19:21:35 -07001249 *
1250 * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
Aravind Akella110d2f22014-09-04 15:36:31 -07001251 * continuous, on-change: maximum sampling period allowed in microseconds.
1252 * one-shot, special : 0
Aravind Akellac841efd2014-06-03 19:21:35 -07001253 * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit
1254 * on 64 bit architectures only for binary compatibility reasons.
Aravind Akella6242f322014-02-28 18:46:19 -08001255 * Availability: SENSORS_DEVICE_API_VERSION_1_3
1256 */
1257 #ifdef __LP64__
1258 int64_t maxDelay;
1259 #else
1260 int32_t maxDelay;
1261 #endif
1262
Aravind Akellac841efd2014-06-03 19:21:35 -07001263 /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.
1264 * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.
1265 * Availability: SENSORS_DEVICE_API_VERSION_1_3
1266 */
Aravind Akella6242f322014-02-28 18:46:19 -08001267 #ifdef __LP64__
1268 uint64_t flags;
1269 #else
1270 uint32_t flags;
1271 #endif
1272
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001273 /* reserved fields, must be zero */
Aravind Akella6242f322014-02-28 18:46:19 -08001274 void* reserved[2];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001275};
1276
1277
Mathias Agopiana4557722012-11-28 17:21:55 -08001278/*
1279 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
1280 * and is present for backward binary and source compatibility.
Clay Murphy8db1fb42013-12-19 09:58:28 -08001281 * See the Sensors HAL interface section for complete descriptions of the
1282 * following functions:
1283 * http://source.android.com/devices/sensors/index.html#hal
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001284 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001285struct sensors_poll_device_t {
1286 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001287 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001288 int sensor_handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001289 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001290 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001291 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -07001292 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001293};
1294
Mathias Agopiana4557722012-11-28 17:21:55 -08001295/*
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001296 * struct sensors_poll_device_1 is used in HAL versions >= SENSORS_DEVICE_API_VERSION_1_0
Mathias Agopiana4557722012-11-28 17:21:55 -08001297 */
1298typedef struct sensors_poll_device_1 {
1299 union {
1300 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
1301 * and can be down-cast to it
1302 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001303 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -08001304
1305 struct {
1306 struct hw_device_t common;
1307
Clay Murphy8db1fb42013-12-19 09:58:28 -08001308 /* Activate/de-activate one sensor. Return 0 on success, negative
Mathias Agopiana4557722012-11-28 17:21:55 -08001309 *
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001310 * sensor_handle is the handle of the sensor to change.
Mathias Agopiana4557722012-11-28 17:21:55 -08001311 * enabled set to 1 to enable, or 0 to disable the sensor.
1312 *
Clay Murphy8db1fb42013-12-19 09:58:28 -08001313 * Return 0 on success, negative errno code otherwise.
Mathias Agopiana4557722012-11-28 17:21:55 -08001314 */
1315 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001316 int sensor_handle, int enabled);
Mathias Agopiana4557722012-11-28 17:21:55 -08001317
1318 /**
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001319 * Set the events's period in nanoseconds for a given sensor.
1320 * If sampling_period_ns > max_delay it will be truncated to
1321 * max_delay and if sampling_period_ns < min_delay it will be
1322 * replaced by min_delay.
Mathias Agopiana4557722012-11-28 17:21:55 -08001323 */
1324 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001325 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -08001326
1327 /**
1328 * Returns an array of sensor data.
Mathias Agopiana4557722012-11-28 17:21:55 -08001329 */
1330 int (*poll)(struct sensors_poll_device_t *dev,
1331 sensors_event_t* data, int count);
1332 };
1333 };
1334
Mathias Agopiana4557722012-11-28 17:21:55 -08001335
1336 /*
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001337 * Sets a sensor’s parameters, including sampling frequency and maximum
1338 * report latency. This function can be called while the sensor is
1339 * activated, in which case it must not cause any sensor measurements to
1340 * be lost: transitioning from one sampling rate to the other cannot cause
1341 * lost events, nor can transitioning from a high maximum report latency to
1342 * a low maximum report latency.
Clay Murphy8db1fb42013-12-19 09:58:28 -08001343 * See the Batching sensor results page for details:
1344 * http://source.android.com/devices/sensors/batching.html
Mathias Agopiana4557722012-11-28 17:21:55 -08001345 */
1346 int (*batch)(struct sensors_poll_device_1* dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001347 int sensor_handle, int flags, int64_t sampling_period_ns,
1348 int64_t max_report_latency_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -08001349
Mathias Agopian16671c52013-07-24 21:07:40 -07001350 /*
1351 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
1352 * to the end of the "batch mode" FIFO for the specified sensor and flushes
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001353 * the FIFO.
1354 * If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero),
Aravind Akellac841efd2014-06-03 19:21:35 -07001355 * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001356 * event stream. This applies to all sensors other than one-shot sensors.
1357 * If the sensor is a one-shot sensor, flush must return -EINVAL and not generate
1358 * any flush complete metadata.
Aravind Akellaa7f2cda2014-08-21 16:31:14 -07001359 * If the sensor is not active at the time flush() is called, flush() should return
1360 * -EINVAL.
Mathias Agopian16671c52013-07-24 21:07:40 -07001361 */
Etienne Le Grand772d85a2014-08-19 14:30:19 -07001362 int (*flush)(struct sensors_poll_device_1* dev, int sensor_handle);
Mathias Agopian16671c52013-07-24 21:07:40 -07001363
Ashutosh Joshi6507f502015-04-03 16:22:32 -07001364 /*
Ashutosh Joshi050f2e42015-04-15 13:56:53 -07001365 * Inject a single sensor sample to be to this device.
1366 * data points to the sensor event to be injected
Aravind Akellac7f54132015-06-22 18:26:54 -07001367 * @return 0 on success
1368 * -EPERM if operation is not allowed
Ashutosh Joshi050f2e42015-04-15 13:56:53 -07001369 * -EINVAL if sensor event cannot be injected
Ashutosh Joshi6507f502015-04-03 16:22:32 -07001370 */
1371 int (*inject_sensor_data)(struct sensors_poll_device_1 *dev, const sensors_event_t *data);
1372
1373 void (*reserved_procs[7])(void);
Mathias Agopiana4557722012-11-28 17:21:55 -08001374
1375} sensors_poll_device_1_t;
1376
1377
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001378/** convenience API for opening and closing a device */
1379
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001380static inline int sensors_open(const struct hw_module_t* module,
1381 struct sensors_poll_device_t** device) {
1382 return module->methods->open(module,
1383 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1384}
1385
1386static inline int sensors_close(struct sensors_poll_device_t* device) {
1387 return device->common.close(&device->common);
1388}
1389
Mathias Agopiana4557722012-11-28 17:21:55 -08001390static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001391 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001392 return module->methods->open(module,
1393 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1394}
1395
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001396static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001397 return device->common.close(&device->common);
1398}
1399
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001400__END_DECLS
1401
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001402#endif // ANDROID_SENSORS_INTERFACE_H