blob: 339508a7b9a11e8bcc8a40e224515c6bf193b96f [file] [log] [blame]
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001/*
Mathias Agopiana4557722012-11-28 17:21:55 -08002 * Copyright (C) 2012 The Android Open Source Project
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_SENSORS_INTERFACE_H
18#define ANDROID_SENSORS_INTERFACE_H
19
20#include <stdint.h>
21#include <sys/cdefs.h>
22#include <sys/types.h>
23
24#include <hardware/hardware.h>
Mike Lockwood21b652f2009-05-22 10:05:48 -040025#include <cutils/native_handle.h>
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080026
27__BEGIN_DECLS
28
Mathias Agopian56f66cc2012-11-08 15:57:38 -080029/*****************************************************************************/
30
31#define SENSORS_HEADER_VERSION 1
32#define SENSORS_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
33#define SENSORS_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, SENSORS_HEADER_VERSION)
Mathias Agopiana4557722012-11-28 17:21:55 -080034#define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION)
Mathias Agopian16671c52013-07-24 21:07:40 -070035#define SENSORS_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, SENSORS_HEADER_VERSION)
Aravind Akella477fbd52014-04-07 22:46:01 +000036#define SENSORS_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION_2(1, 2, SENSORS_HEADER_VERSION)
Aravind Akella6242f322014-02-28 18:46:19 -080037#define SENSORS_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION_2(1, 3, SENSORS_HEADER_VERSION)
Mathias Agopian56f66cc2012-11-08 15:57:38 -080038
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080039/**
Clay Murphy8db1fb42013-12-19 09:58:28 -080040 * Please see the Sensors section of source.android.com for an
41 * introduction to and detailed descriptions of Android sensor types:
42 * http://source.android.com/devices/sensors/index.html
43 */
44
45/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080046 * The id of this module
47 */
48#define SENSORS_HARDWARE_MODULE_ID "sensors"
49
50/**
51 * Name of the sensors device to open
52 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -070053#define SENSORS_HARDWARE_POLL "poll"
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080054
55/**
56 * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
57 * A Handle identifies a given sensors. The handle is used to activate
58 * and/or deactivate sensors.
59 * In this version of the API there can only be 256 handles.
60 */
61#define SENSORS_HANDLE_BASE 0
62#define SENSORS_HANDLE_BITS 8
63#define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS)
64
65
Mathias Agopiana4557722012-11-28 17:21:55 -080066/*
Aravind Akella6242f322014-02-28 18:46:19 -080067 * **** Deprecated *****
Mathias Agopiana4557722012-11-28 17:21:55 -080068 * flags for (*batch)()
69 * Availability: SENSORS_DEVICE_API_VERSION_1_0
Aravind Akella6242f322014-02-28 18:46:19 -080070 * see (*batch)() documentation for details.
71 * Deprecated as of SENSORS_DEVICE_API_VERSION_1_3.
72 * WAKE_UP_* sensors replace WAKE_UPON_FIFO_FULL concept.
Mathias Agopiana4557722012-11-28 17:21:55 -080073 */
74enum {
75 SENSORS_BATCH_DRY_RUN = 0x00000001,
76 SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
77};
78
Mathias Agopian16671c52013-07-24 21:07:40 -070079/*
80 * what field for meta_data_event_t
81 */
82enum {
83 /* a previous flush operation has completed */
Mathias Agopianaf32a8d2013-08-06 20:33:38 -070084 META_DATA_FLUSH_COMPLETE = 1,
85 META_DATA_VERSION /* always last, leave auto-assigned */
Mathias Agopian16671c52013-07-24 21:07:40 -070086};
87
Mathias Agopiana4557722012-11-28 17:21:55 -080088/*
Aravind Akella477fbd52014-04-07 22:46:01 +000089 * The permission to use for body sensors (like heart rate monitors).
90 * See sensor types for more details on what sensors should require this
91 * permission.
92 */
93#define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS"
94
95/*
Aravind Akella6242f322014-02-28 18:46:19 -080096 * Availability: SENSORS_DEVICE_API_VERSION_1_3
97 * Sensor flags used in sensor_t.flags.
98 */
99enum {
100 /*
101 * Whether this sensor wakes up the AP from suspend mode when data is available.
102 */
Aravind Akellac841efd2014-06-03 19:21:35 -0700103 SENSOR_FLAG_WAKE_UP = 1U << 0,
104 /*
105 * Reporting modes for various sensors. Each sensor will have exactly one of these modes set.
106 * The least significant 2nd, 3rd and 4th bits are used to represent four possible reporting
107 * modes.
108 */
109 SENSOR_FLAG_CONTINUOUS_MODE = 0, // 0000
110 SENSOR_FLAG_ON_CHANGE_MODE = 0x2, // 0010
111 SENSOR_FLAG_ONE_SHOT_MODE = 0x4, // 0100
112 SENSOR_FLAG_SPECIAL_REPORTING_MODE = 0x6 // 0110
Aravind Akella6242f322014-02-28 18:46:19 -0800113};
114
115/*
Aravind Akellac841efd2014-06-03 19:21:35 -0700116 * Mask and shift for reporting mode sensor flags defined above.
117 */
118#define REPORTING_MODE_MASK (0xE)
119#define REPORTING_MODE_SHIFT (1)
120
121/*
Mathias Agopiana4557722012-11-28 17:21:55 -0800122 * Sensor type
123 *
124 * Each sensor has a type which defines what this sensor measures and how
Clay Murphy8db1fb42013-12-19 09:58:28 -0800125 * measures are reported. See the Base sensors and Composite sensors lists
126 * for complete descriptions:
127 * http://source.android.com/devices/sensors/base_triggers.html
128 * http://source.android.com/devices/sensors/composite_sensors.html
Mathias Agopian1599ec62013-08-19 14:34:47 -0700129 *
130 * Device manufacturers (OEMs) can define their own sensor types, for
131 * their private use by applications or services provided by them. Such
132 * sensor types are specific to an OEM and can't be exposed in the SDK.
133 * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE.
Aravind Akella477fbd52014-04-07 22:46:01 +0000134 *
135 * All sensors defined outside of the device private range must correspond to
136 * a type defined in this file, and must satisfy the characteristics listed in
137 * the description of the sensor type.
138 *
139 * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also
140 * has a stringType.
141 * - StringType of sensors inside of the device private range MUST be prefixed
142 * by the sensor provider's or OEM reverse domain name. In particular, they
143 * cannot use the "android.sensor" prefix.
144 * - StringType of sensors outside of the device private range MUST correspond
145 * to the one defined in this file (starting with "android.sensor").
146 * For example, accelerometers must have
147 * type=SENSOR_TYPE_ACCELEROMETER and
148 * stringType=SENSOR_STRING_TYPE_ACCELEROMETER
149 *
150 * When android introduces a new sensor type that can replace an OEM-defined
151 * sensor type, the OEM must use the official sensor type and stringType on
152 * versions of the HAL that support this new official sensor type.
153 *
154 * Example (made up): Suppose Google's Glass team wants to surface a sensor
155 * detecting that Glass is on a head.
156 * - Such a sensor is not officially supported in android KitKat
157 * - Glass devices launching on KitKat can implement a sensor with
158 * type = 0x10001 and stringType = "com.google.glass.onheaddetector"
159 * - In L android release, if android decides to define
160 * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR,
161 * those types should replace the Glass-team-specific types in all future
162 * launches.
163 * - When launching glass on the L release, Google should now use the official
164 * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType.
165 * - This way, all applications can now use this sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800166 */
167
168/*
Mathias Agopian1599ec62013-08-19 14:34:47 -0700169 * Base for device manufacturers private sensor types.
170 * These sensor types can't be exposed in the SDK.
171 */
172#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000
173
174/*
Mathias Agopian16671c52013-07-24 21:07:40 -0700175 * SENSOR_TYPE_META_DATA
Aravind Akellac841efd2014-06-03 19:21:35 -0700176 * reporting-mode: n/a
Mathias Agopian16671c52013-07-24 21:07:40 -0700177 * wake-up sensor: n/a
178 *
179 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
180 *
181 * SENSOR_TYPE_META_DATA is a special token used to populate the
182 * sensors_meta_data_event structure. It doesn't correspond to a physical
183 * sensor. sensors_meta_data_event are special, they exist only inside
184 * the HAL and are generated spontaneously, as opposed to be related to
185 * a physical sensor.
186 *
Mathias Agopianaf32a8d2013-08-06 20:33:38 -0700187 * sensors_meta_data_event_t.version must be META_DATA_VERSION
188 * sensors_meta_data_event_t.sensor must be 0
189 * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
190 * sensors_meta_data_event_t.reserved must be 0
191 * sensors_meta_data_event_t.timestamp must be 0
Mathias Agopian16671c52013-07-24 21:07:40 -0700192 *
193 * The payload is a meta_data_event_t, where:
194 * meta_data_event_t.what can take the following values:
195 *
196 * META_DATA_FLUSH_COMPLETE
197 * This event indicates that a previous (*flush)() call has completed for the sensor
198 * handle specified in meta_data_event_t.sensor.
199 * see (*flush)() for more details
200 *
201 * All other values for meta_data_event_t.what are reserved and
202 * must not be used.
203 *
204 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000205#define SENSOR_TYPE_META_DATA (0)
Mathias Agopian16671c52013-07-24 21:07:40 -0700206
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800207/*
Aravind Akella9057e122014-07-28 18:01:37 -0700208 * Wake up sensors.
209 * Each sensor may have either or both a wake-up and a non-wake variant.
210 * When registered in batch mode, wake-up sensors will wake up the AP when
211 * their FIFOs are full or when the batch timeout expires. A separate FIFO has
212 * to be maintained for wake up sensors and non wake up sensors. The non wake-up
213 * sensors need to overwrite their FIFOs when they are full till the AP wakes up
214 * and the wake-up sensors will wake-up the AP when their FIFOs are full or when
215 * the batch timeout expires without losing events. Wake-up and non wake-up variants
216 * of each sensor can be activated at different rates independently of each other.
217 *
218 * Note: Proximity sensor and significant motion sensor which were defined in previous
219 * releases are also wake-up sensors and should be treated as such. Wake-up one-shot
220 * sensors like SIGNIFICANT_MOTION cannot be batched, hence the text about batch above
221 * doesn't apply to them. See the definitions of SENSOR_TYPE_PROXIMITY and
222 * SENSOR_TYPE_SIGNIFICANT_MOTION for more info.
223 *
224 * Set SENSOR_FLAG_WAKE_UP flag for all wake-up sensors.
225 *
226 * For example, A device can have two sensors both of SENSOR_TYPE_ACCELEROMETER and
227 * one of them can be a wake_up sensor (with SENSOR_FLAG_WAKE_UP flag set) and the other
228 * can be a regular non wake_up sensor. Both of these sensors must be activated/deactivated
229 * independently of the other.
230 */
231
232/*
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800233 * SENSOR_TYPE_ACCELEROMETER
Aravind Akellac841efd2014-06-03 19:21:35 -0700234 * reporting-mode: continuous
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800235 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800236 * All values are in SI units (m/s^2) and measure the acceleration of the
237 * device minus the force of gravity.
238 *
Aravind Akella9057e122014-07-28 18:01:37 -0700239 * Implement the non-wake-up version of this sensor and implement the wake-up
240 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800241 */
242#define SENSOR_TYPE_ACCELEROMETER (1)
Aravind Akella477fbd52014-04-07 22:46:01 +0000243#define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800244
245/*
246 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akellac841efd2014-06-03 19:21:35 -0700247 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800248 *
249 * All values are in micro-Tesla (uT) and measure the geomagnetic
250 * field in the X, Y and Z axis.
251 *
Aravind Akella9057e122014-07-28 18:01:37 -0700252 * Implement the non-wake-up version of this sensor and implement the wake-up
253 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800254 */
255#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
256#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akella477fbd52014-04-07 22:46:01 +0000257#define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800258
259/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800260 * SENSOR_TYPE_ORIENTATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700261 * reporting-mode: continuous
Clay Murphy8db1fb42013-12-19 09:58:28 -0800262 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800263 * All values are angles in degrees.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800264 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700265 * Orientation sensors return sensor events for all 3 axes at a constant
266 * rate defined by setDelay().
Aravind Akella9057e122014-07-28 18:01:37 -0700267 *
268 * Implement the non-wake-up version of this sensor and implement the wake-up
269 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800270 */
271#define SENSOR_TYPE_ORIENTATION (3)
Aravind Akella477fbd52014-04-07 22:46:01 +0000272#define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800273
274/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800275 * SENSOR_TYPE_GYROSCOPE
Aravind Akellac841efd2014-06-03 19:21:35 -0700276 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800277 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700278 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800279 * around the X, Y and Z axis.
Aravind Akella9057e122014-07-28 18:01:37 -0700280 *
281 * Implement the non-wake-up version of this sensor and implement the wake-up
282 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800283 */
284#define SENSOR_TYPE_GYROSCOPE (4)
Aravind Akella477fbd52014-04-07 22:46:01 +0000285#define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800286
287/*
288 * SENSOR_TYPE_LIGHT
Aravind Akellac841efd2014-06-03 19:21:35 -0700289 * reporting-mode: on-change
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800290 *
291 * The light sensor value is returned in SI lux units.
Aravind Akella9057e122014-07-28 18:01:37 -0700292 *
293 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800294 */
295#define SENSOR_TYPE_LIGHT (5)
Aravind Akella477fbd52014-04-07 22:46:01 +0000296#define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800297
298/*
299 * SENSOR_TYPE_PRESSURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700300 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800301 *
302 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Aravind Akella9057e122014-07-28 18:01:37 -0700303 *
304 * Implement the non-wake-up version of this sensor and implement the wake-up
305 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800306 */
307#define SENSOR_TYPE_PRESSURE (6)
Aravind Akella477fbd52014-04-07 22:46:01 +0000308#define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800309
310/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
311#define SENSOR_TYPE_TEMPERATURE (7)
Aravind Akella477fbd52014-04-07 22:46:01 +0000312#define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800313
314/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800315 * SENSOR_TYPE_PROXIMITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700316 * reporting-mode: on-change
Mike Lockwooda2414312009-11-03 10:29:50 -0500317 *
Aravind Akella9057e122014-07-28 18:01:37 -0700318 * The proximity sensor which turns the screen off and back on during calls is the
319 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
320 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
321 * SENSOR_FLAG_WAKE_UP.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800322 * The value corresponds to the distance to the nearest object in centimeters.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800323 */
324#define SENSOR_TYPE_PROXIMITY (8)
Aravind Akella477fbd52014-04-07 22:46:01 +0000325#define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800326
327/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800328 * SENSOR_TYPE_GRAVITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700329 * reporting-mode: continuous
Mathias Agopian42b743c2010-11-22 15:55:32 -0800330 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800331 * A gravity output indicates the direction of and magnitude of gravity in
Clay Murphy8db1fb42013-12-19 09:58:28 -0800332 * the devices's coordinates.
Aravind Akella9057e122014-07-28 18:01:37 -0700333 *
334 * Implement the non-wake-up version of this sensor and implement the wake-up
335 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800336 */
337#define SENSOR_TYPE_GRAVITY (9)
Aravind Akella477fbd52014-04-07 22:46:01 +0000338#define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800339
340/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800341 * SENSOR_TYPE_LINEAR_ACCELERATION
Aravind Akellac841efd2014-06-03 19:21:35 -0700342 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800343 *
344 * Indicates the linear acceleration of the device in device coordinates,
345 * not including gravity.
Aravind Akella9057e122014-07-28 18:01:37 -0700346 *
347 * Implement the non-wake-up version of this sensor and implement the wake-up
348 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800349 */
350#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
Aravind Akella477fbd52014-04-07 22:46:01 +0000351#define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800352
353
354/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800355 * SENSOR_TYPE_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700356 * reporting-mode: continuous
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800357 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700358 * The rotation vector symbolizes the orientation of the device relative to the
Clay Murphy8db1fb42013-12-19 09:58:28 -0800359 * East-North-Up coordinates frame.
Aravind Akella9057e122014-07-28 18:01:37 -0700360 *
361 * Implement the non-wake-up version of this sensor and implement the wake-up
362 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800363 */
364#define SENSOR_TYPE_ROTATION_VECTOR (11)
Aravind Akella477fbd52014-04-07 22:46:01 +0000365#define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800366
367/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800368 * SENSOR_TYPE_RELATIVE_HUMIDITY
Aravind Akellac841efd2014-06-03 19:21:35 -0700369 * reporting-mode: on-change
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100370 *
371 * A relative humidity sensor measures relative ambient air humidity and
372 * returns a value in percent.
Aravind Akella9057e122014-07-28 18:01:37 -0700373 *
374 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800375 */
376#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
Aravind Akella477fbd52014-04-07 22:46:01 +0000377#define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800378
379/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800380 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700381 * reporting-mode: on-change
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700382 *
383 * The ambient (room) temperature in degree Celsius.
Aravind Akella9057e122014-07-28 18:01:37 -0700384 *
385 * Both wake-up and non wake-up versions are useful.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800386 */
387#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
Aravind Akella477fbd52014-04-07 22:46:01 +0000388#define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800389
390/*
391 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700392 * reporting-mode: continuous
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700393 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800394 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
395 * reported separately instead of being included in the measurement.
Aravind Akella9057e122014-07-28 18:01:37 -0700396 *
397 * Implement the non-wake-up version of this sensor and implement the wake-up
398 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800399 */
400#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
Aravind Akella477fbd52014-04-07 22:46:01 +0000401#define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800402
403/*
404 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700405 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800406 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800407 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
Clay Murphy8db1fb42013-12-19 09:58:28 -0800408 * field.
Aravind Akella9057e122014-07-28 18:01:37 -0700409 *
410 * Implement the non-wake-up version of this sensor and implement the wake-up
411 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800412 */
413#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
Aravind Akella477fbd52014-04-07 22:46:01 +0000414#define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800415
416/*
417 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Aravind Akellac841efd2014-06-03 19:21:35 -0700418 * reporting-mode: continuous
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800419 *
420 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800421 * around the X, Y and Z axis.
Aravind Akella9057e122014-07-28 18:01:37 -0700422 *
423 * Implement the non-wake-up version of this sensor and implement the wake-up
424 * version if the system possesses a wake up fifo.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800425 */
426#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
Aravind Akella477fbd52014-04-07 22:46:01 +0000427#define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800428
Mathias Agopiana4557722012-11-28 17:21:55 -0800429/*
430 * SENSOR_TYPE_SIGNIFICANT_MOTION
Aravind Akellac841efd2014-06-03 19:21:35 -0700431 * reporting-mode: one-shot
Mathias Agopiana4557722012-11-28 17:21:55 -0800432 *
433 * A sensor of this type triggers an event each time significant motion
434 * is detected and automatically disables itself.
Aravind Akella9057e122014-07-28 18:01:37 -0700435 * For Significant Motion sensor to be useful, it must be defined as a
436 * wake-up sensor. (set SENSOR_FLAG_WAKE_UP). Implement the wake-up significant motion
437 * sensor. A non wake-up version is not useful.
Mathias Agopiana4557722012-11-28 17:21:55 -0800438 * The only allowed value to return is 1.0.
Mathias Agopiana4557722012-11-28 17:21:55 -0800439 */
440
441#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
Aravind Akella477fbd52014-04-07 22:46:01 +0000442#define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
Mathias Agopiana4557722012-11-28 17:21:55 -0800443
444/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800445 * SENSOR_TYPE_STEP_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700446 * reporting-mode: special
Mathias Agopiana4557722012-11-28 17:21:55 -0800447 *
448 * A sensor of this type triggers an event each time a step is taken
Clay Murphy8db1fb42013-12-19 09:58:28 -0800449 * by the user. The only allowed value to return is 1.0 and an event
450 * is generated for each step.
Aravind Akella9057e122014-07-28 18:01:37 -0700451 *
452 * Both wake-up and non wake-up versions are useful.
Mathias Agopiana4557722012-11-28 17:21:55 -0800453 */
454
Mathias Agopian2f276f52013-01-28 17:54:41 -0800455#define SENSOR_TYPE_STEP_DETECTOR (18)
Aravind Akella477fbd52014-04-07 22:46:01 +0000456#define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
Mathias Agopiana4557722012-11-28 17:21:55 -0800457
458
459/*
460 * SENSOR_TYPE_STEP_COUNTER
Aravind Akellac841efd2014-06-03 19:21:35 -0700461 * reporting-mode: on-change
Mathias Agopiana4557722012-11-28 17:21:55 -0800462 *
463 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800464 * the last reboot while activated. The value is returned as a uint64_t and is
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700465 * reset to zero only on a system / android reboot.
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 Agopiana4557722012-11-28 17:21:55 -0800469 */
470
471#define SENSOR_TYPE_STEP_COUNTER (19)
Aravind Akella477fbd52014-04-07 22:46:01 +0000472#define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
Mathias Agopiana4557722012-11-28 17:21:55 -0800473
Etienne Le Grandca858142013-02-26 19:17:20 -0800474/*
475 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700476 * reporting-mode: continuous
Etienne Le Grandca858142013-02-26 19:17:20 -0800477 *
478 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
479 * of using a gyroscope.
Aravind Akella9057e122014-07-28 18:01:37 -0700480 *
481 * Implement the non-wake-up version of this sensor and implement the wake-up
482 * version if the system possesses a wake up fifo.
Etienne Le Grandca858142013-02-26 19:17:20 -0800483 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000484#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
485#define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
486
487/*
488 * SENSOR_TYPE_HEART_RATE
Aravind Akellac841efd2014-06-03 19:21:35 -0700489 * reporting-mode: on-change
Aravind Akella477fbd52014-04-07 22:46:01 +0000490 *
Etienne Le Grand7b361582014-05-16 11:08:28 -0700491 * A sensor of this type returns the current heart rate.
492 * The events contain the current heart rate in beats per minute (BPM) and the
493 * status of the sensor during the measurement. See heart_rate_event_t for more
494 * details.
495 *
496 * Because this sensor is on-change, events must be generated when and only
497 * when heart_rate.bpm or heart_rate.status have changed since the last
498 * event. The event should be generated no faster than every period_ns passed
Aravind Akellac841efd2014-06-03 19:21:35 -0700499 * to setDelay() or to batch(). See the definition of the on-change reporting
Etienne Le Grand7b361582014-05-16 11:08:28 -0700500 * mode for more information.
501 *
Aravind Akella477fbd52014-04-07 22:46:01 +0000502 * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
Aravind Akella9057e122014-07-28 18:01:37 -0700503 *
504 * Both wake-up and non wake-up versions are useful.
Aravind Akella477fbd52014-04-07 22:46:01 +0000505 */
506#define SENSOR_TYPE_HEART_RATE (21)
507#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
Mathias Agopiana4557722012-11-28 17:21:55 -0800508
Aravind Akella6242f322014-02-28 18:46:19 -0800509/*
Aravind Akellaf895c682014-04-30 11:46:09 -0700510 * SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
Aravind Akellac841efd2014-06-03 19:21:35 -0700511 * reporting-mode: special (setDelay has no impact)
Aravind Akellaf895c682014-04-30 11:46:09 -0700512 *
513 * A sensor of this type generates an event each time a tilt event is detected. A tilt event
514 * 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 -0700515 * 35 degrees since the activation or the last trigger of the sensor.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700516 * reference_estimated_gravity = average of accelerometer measurements over the first
Etienne Le Grand53017ef2014-05-28 15:42:48 -0700517 * 1 second after activation or the estimated gravity at the last
518 * trigger.
Aravind Akellaf895c682014-04-30 11:46:09 -0700519 * current_estimated_gravity = average of accelerometer measurements over the last 2 seconds.
Etienne Le Grand426f14d2014-05-29 19:35:48 -0700520 * trigger when angle (reference_estimated_gravity, current_estimated_gravity) > 35 degrees
Aravind Akellaf895c682014-04-30 11:46:09 -0700521 *
522 * Large accelerations without a change in phone orientation should not trigger a tilt event.
523 * For example, a sharp turn or strong acceleration while driving a car should not trigger a tilt
524 * event, even though the angle of the average acceleration might vary by more than 35 degrees.
525 *
526 * Typically, this sensor is implemented with the help of only an accelerometer. Other sensors can
527 * be used as well if they do not increase the power consumption significantly. This is a low power
528 * sensor that should allow the AP to go into suspend mode. Do not emulate this sensor in the HAL.
529 * Like other wake up sensors, the driver is expected to a hold a wake_lock with a timeout of 200 ms
530 * while reporting this event. The only allowed return value is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700531 *
532 * Implement only the wake-up version of this sensor.
Aravind Akellaf895c682014-04-30 11:46:09 -0700533 */
Aravind Akella9057e122014-07-28 18:01:37 -0700534#define SENSOR_TYPE_TILT_DETECTOR (22)
535#define SENSOR_STRING_TYPE_TILT_DETECTOR "android.sensor.tilt_detector"
Aravind Akellaf895c682014-04-30 11:46:09 -0700536
Etienne Le Grandba123122014-05-05 18:20:42 -0700537/*
538 * SENSOR_TYPE_WAKE_GESTURE
Aravind Akellac841efd2014-06-03 19:21:35 -0700539 * reporting-mode: one-shot
Etienne Le Grandba123122014-05-05 18:20:42 -0700540 *
541 * A sensor enabling waking up the device based on a device specific motion.
542 *
543 * When this sensor triggers, the device behaves as if the power button was
544 * pressed, turning the screen on. This behavior (turning on the screen when
545 * this sensor triggers) might be deactivated by the user in the device
546 * settings. Changes in settings do not impact the behavior of the sensor:
547 * only whether the framework turns the screen on when it triggers.
548 *
549 * The actual gesture to be detected is not specified, and can be chosen by
550 * the manufacturer of the device.
551 * This sensor must be low power, as it is likely to be activated 24/7.
552 * The only allowed value to return is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700553 *
554 * Implement only the wake-up version of this sensor.
Etienne Le Grandba123122014-05-05 18:20:42 -0700555 */
Aravind Akella9057e122014-07-28 18:01:37 -0700556#define SENSOR_TYPE_WAKE_GESTURE (23)
Etienne Le Grandba123122014-05-05 18:20:42 -0700557#define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture"
558
Jeff Brown8df2feb2014-07-17 15:11:51 -0700559/*
560 * SENSOR_TYPE_GLANCE_GESTURE
561 * reporting-mode: one-shot
Jeff Brown8df2feb2014-07-17 15:11:51 -0700562 *
563 * A sensor enabling briefly turning the screen on to enable the user to
564 * glance content on screen based on a specific motion. The device should
565 * turn the screen off after a few moments.
566 *
567 * When this sensor triggers, the device turns the screen on momentarily
568 * to allow the user to glance notifications or other content while the
569 * device remains locked in a non-interactive state (dozing). This behavior
570 * (briefly turning on the screen when this sensor triggers) might be deactivated
571 * by the user in the device settings. Changes in settings do not impact the
572 * behavior of the sensor: only whether the framework briefly turns the screen on
573 * when it triggers.
574 *
575 * The actual gesture to be detected is not specified, and can be chosen by
576 * the manufacturer of the device.
577 * This sensor must be low power, as it is likely to be activated 24/7.
578 * The only allowed value to return is 1.0.
Aravind Akella9057e122014-07-28 18:01:37 -0700579 *
580 * Implement only the wake-up version of this sensor.
Jeff Brown8df2feb2014-07-17 15:11:51 -0700581 */
Aravind Akella9057e122014-07-28 18:01:37 -0700582#define SENSOR_TYPE_GLANCE_GESTURE (24)
Jeff Brown8df2feb2014-07-17 15:11:51 -0700583#define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture"
584
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800585/**
Aravind Akella952471e2014-07-17 12:40:54 -0700586 * SENSOR_TYPE_PICK_UP_GESTURE
587 * reporting-mode: one-shot
Aravind Akella952471e2014-07-17 12:40:54 -0700588 *
589 * A sensor of this type triggers when the device is picked up regardless of wherever is was
590 * before (desk, pocket, bag). The only allowed return value is 1.0.
591 * This sensor de-activates itself immediately after it triggers.
Aravind Akella9057e122014-07-28 18:01:37 -0700592 *
593 * Implement only the wake-up version of this sensor.
Aravind Akella952471e2014-07-17 12:40:54 -0700594 */
Aravind Akella9057e122014-07-28 18:01:37 -0700595#define SENSOR_TYPE_PICK_UP_GESTURE (25)
Aravind Akella952471e2014-07-17 12:40:54 -0700596#define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture"
597
598/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800599 * Values returned by the accelerometer in various locations in the universe.
600 * all values are in SI units (m/s^2)
601 */
602#define GRAVITY_SUN (275.0f)
603#define GRAVITY_EARTH (9.80665f)
604
605/** Maximum magnetic field on Earth's surface */
606#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
607
608/** Minimum magnetic field on Earth's surface */
609#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
610
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800611/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700612 * Possible values of the status field of sensor events.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800613 */
Etienne Le Grand7b361582014-05-16 11:08:28 -0700614#define SENSOR_STATUS_NO_CONTACT -1
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800615#define SENSOR_STATUS_UNRELIABLE 0
616#define SENSOR_STATUS_ACCURACY_LOW 1
617#define SENSOR_STATUS_ACCURACY_MEDIUM 2
618#define SENSOR_STATUS_ACCURACY_HIGH 3
619
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800620/**
621 * sensor event data
622 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800623typedef struct {
624 union {
625 float v[3];
626 struct {
627 float x;
628 float y;
629 float z;
630 };
631 struct {
632 float azimuth;
633 float pitch;
634 float roll;
635 };
636 };
637 int8_t status;
638 uint8_t reserved[3];
639} sensors_vec_t;
640
641/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800642 * uncalibrated gyroscope and magnetometer event data
643 */
644typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700645 union {
646 float uncalib[3];
647 struct {
648 float x_uncalib;
649 float y_uncalib;
650 float z_uncalib;
651 };
652 };
653 union {
654 float bias[3];
655 struct {
656 float x_bias;
657 float y_bias;
658 float z_bias;
659 };
660 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800661} uncalibrated_event_t;
662
Mathias Agopian16671c52013-07-24 21:07:40 -0700663typedef struct meta_data_event {
664 int32_t what;
665 int32_t sensor;
666} meta_data_event_t;
667
Etienne Le Grandca858142013-02-26 19:17:20 -0800668/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700669 * Heart rate event data
670 */
671typedef struct {
672 // Heart rate in beats per minute.
673 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
674 float bpm;
675 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
676 int8_t status;
677} heart_rate_event_t;
678
679/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800680 * Union of the various types of sensor data
681 * that can be returned.
682 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700683typedef struct sensors_event_t {
684 /* must be sizeof(struct sensors_event_t) */
685 int32_t version;
686
687 /* sensor identifier */
688 int32_t sensor;
689
690 /* sensor type */
691 int32_t type;
692
693 /* reserved */
694 int32_t reserved0;
695
696 /* time is in nanosecond */
697 int64_t timestamp;
698
699 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700700 union {
701 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700702
Mathias Agopian27e16682013-07-08 14:00:54 -0700703 /* acceleration values are in meter per second per second (m/s^2) */
704 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700705
Mathias Agopian27e16682013-07-08 14:00:54 -0700706 /* magnetic vector values are in micro-Tesla (uT) */
707 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700708
Mathias Agopian27e16682013-07-08 14:00:54 -0700709 /* orientation values are in degrees */
710 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700711
Mathias Agopian27e16682013-07-08 14:00:54 -0700712 /* gyroscope values are in rad/s */
713 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700714
Mathias Agopian27e16682013-07-08 14:00:54 -0700715 /* temperature is in degrees centigrade (Celsius) */
716 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700717
Mathias Agopian27e16682013-07-08 14:00:54 -0700718 /* distance in centimeters */
719 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700720
Mathias Agopian27e16682013-07-08 14:00:54 -0700721 /* light in SI lux units */
722 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700723
Mathias Agopian27e16682013-07-08 14:00:54 -0700724 /* pressure in hectopascal (hPa) */
725 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100726
Mathias Agopian27e16682013-07-08 14:00:54 -0700727 /* relative humidity in percent */
728 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800729
Mathias Agopian27e16682013-07-08 14:00:54 -0700730 /* uncalibrated gyroscope values are in rad/s */
731 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800732
Mathias Agopian27e16682013-07-08 14:00:54 -0700733 /* uncalibrated magnetometer values are in micro-Teslas */
734 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700735
Etienne Le Grand7b361582014-05-16 11:08:28 -0700736 /* heart rate data containing value in bpm and status */
737 heart_rate_event_t heart_rate;
Aravind Akella477fbd52014-04-07 22:46:01 +0000738
Mathias Agopian16671c52013-07-24 21:07:40 -0700739 /* this is a special event. see SENSOR_TYPE_META_DATA above.
740 * sensors_meta_data_event_t events are all reported with a type of
741 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
742 */
743 meta_data_event_t meta_data;
Mathias Agopian27e16682013-07-08 14:00:54 -0700744 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800745
Mathias Agopian27e16682013-07-08 14:00:54 -0700746 union {
747 uint64_t data[8];
748
749 /* step-counter */
750 uint64_t step_counter;
751 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700752 };
Aravind Akella6242f322014-02-28 18:46:19 -0800753
754 /* Reserved flags for internal use. Set to zero. */
755 uint32_t flags;
756
757 uint32_t reserved1[3];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700758} sensors_event_t;
759
760
Mathias Agopian16671c52013-07-24 21:07:40 -0700761/* see SENSOR_TYPE_META_DATA */
762typedef sensors_event_t sensors_meta_data_event_t;
763
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700764
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800765struct sensor_t;
766
767/**
768 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
769 * and the fields of this data structure must begin with hw_module_t
770 * followed by module specific information.
771 */
772struct sensors_module_t {
773 struct hw_module_t common;
774
775 /**
776 * Enumerate all available sensors. The list is returned in "list".
777 * @return number of sensors in the list
778 */
779 int (*get_sensors_list)(struct sensors_module_t* module,
780 struct sensor_t const** list);
781};
782
783struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800784
785 /* Name of this sensor.
786 * All sensors of the same "type" must have a different "name".
787 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800788 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800789
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800790 /* vendor of the hardware part */
791 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800792
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800793 /* version of the hardware part + driver. The value of this field
794 * must increase when the driver is updated in a way that changes the
795 * output of this sensor. This is important for fused sensors when the
796 * fusion algorithm is updated.
Aravind Akella6242f322014-02-28 18:46:19 -0800797 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800798 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800799
800 /* handle that identifies this sensors. This handle is used to reference
801 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800802 */
803 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800804
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800805 /* this sensor's type. */
806 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800807
808 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800809 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800810
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800811 /* smallest difference between two values reported by this sensor */
812 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800813
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800814 /* rough estimate of this sensor's power consumption in mA */
815 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800816
Aravind Akellac841efd2014-06-03 19:21:35 -0700817 /* this value depends on the reporting mode:
Mathias Agopiana4557722012-11-28 17:21:55 -0800818 *
819 * continuous: minimum sample period allowed in microseconds
820 * on-change : 0
821 * one-shot :-1
822 * special : 0, unless otherwise noted
823 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700824 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800825
Mathias Agopian16671c52013-07-24 21:07:40 -0700826 /* number of events reserved for this sensor in the batch mode FIFO.
827 * If there is a dedicated FIFO for this sensor, then this is the
828 * size of this FIFO. If the FIFO is shared with other sensors,
829 * this is the size reserved for that sensor and it can be zero.
830 */
831 uint32_t fifoReservedEventCount;
832
833 /* maximum number of events of this sensor that could be batched.
834 * This is especially relevant when the FIFO is shared between
835 * several sensors; this value is then set to the size of that FIFO.
836 */
837 uint32_t fifoMaxEventCount;
838
Aravind Akella477fbd52014-04-07 22:46:01 +0000839 /* type of this sensor as a string. Set to corresponding
840 * SENSOR_STRING_TYPE_*.
841 * When defining an OEM specific sensor or sensor manufacturer specific
842 * sensor, use your reserve domain name as a prefix.
843 * ex: com.google.glass.onheaddetector
844 * For sensors of known type, the android framework might overwrite this
845 * string automatically.
846 */
847 const char* stringType;
848
849 /* permission required to see this sensor, register to it and receive data.
850 * Set to "" if no permission is required. Some sensor types like the
851 * heart rate monitor have a mandatory require_permission.
852 * For sensors that always require a specific permission, like the heart
853 * rate monitor, the android framework might overwrite this string
854 * automatically.
855 */
856 const char* requiredPermission;
857
Aravind Akella6242f322014-02-28 18:46:19 -0800858 /* This value is defined only for continuous mode sensors. It is the delay between two
859 * sensor events corresponding to the lowest frequency that this sensor supports. When
860 * lower frequencies are requested through batch()/setDelay() the events will be generated
861 * at this frequency instead. It can be used by the framework or applications to estimate
862 * when the batch FIFO may be full.
Aravind Akellac841efd2014-06-03 19:21:35 -0700863 *
864 * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
865 * continuous: maximum sampling period allowed in microseconds.
866 * on-change, one-shot, special : 0
867 * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit
868 * on 64 bit architectures only for binary compatibility reasons.
Aravind Akella6242f322014-02-28 18:46:19 -0800869 * Availability: SENSORS_DEVICE_API_VERSION_1_3
870 */
871 #ifdef __LP64__
872 int64_t maxDelay;
873 #else
874 int32_t maxDelay;
875 #endif
876
Aravind Akellac841efd2014-06-03 19:21:35 -0700877 /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.
878 * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.
879 * Availability: SENSORS_DEVICE_API_VERSION_1_3
880 */
Aravind Akella6242f322014-02-28 18:46:19 -0800881 #ifdef __LP64__
882 uint64_t flags;
883 #else
884 uint32_t flags;
885 #endif
886
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800887 /* reserved fields, must be zero */
Aravind Akella6242f322014-02-28 18:46:19 -0800888 void* reserved[2];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800889};
890
891
Mathias Agopiana4557722012-11-28 17:21:55 -0800892/*
893 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
894 * and is present for backward binary and source compatibility.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800895 * See the Sensors HAL interface section for complete descriptions of the
896 * following functions:
897 * http://source.android.com/devices/sensors/index.html#hal
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800898 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700899struct sensors_poll_device_t {
900 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700901 int (*activate)(struct sensors_poll_device_t *dev,
902 int handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700903 int (*setDelay)(struct sensors_poll_device_t *dev,
904 int handle, int64_t ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700905 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700906 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700907};
908
Mathias Agopiana4557722012-11-28 17:21:55 -0800909/*
910 * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
911 */
912typedef struct sensors_poll_device_1 {
913 union {
914 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
915 * and can be down-cast to it
916 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800917 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -0800918
919 struct {
920 struct hw_device_t common;
921
Clay Murphy8db1fb42013-12-19 09:58:28 -0800922 /* Activate/de-activate one sensor. Return 0 on success, negative
Mathias Agopiana4557722012-11-28 17:21:55 -0800923 *
924 * handle is the handle of the sensor to change.
925 * enabled set to 1 to enable, or 0 to disable the sensor.
926 *
Clay Murphy8db1fb42013-12-19 09:58:28 -0800927 * Return 0 on success, negative errno code otherwise.
Mathias Agopiana4557722012-11-28 17:21:55 -0800928 */
929 int (*activate)(struct sensors_poll_device_t *dev,
930 int handle, int enabled);
931
932 /**
Aravind Akella6242f322014-02-28 18:46:19 -0800933 * Set the events's period in nanoseconds for a given sensor. If
934 * period_ns > max_delay it will be truncated to max_delay and if
935 * period_ns < min_delay it will be replaced by min_delay.
Mathias Agopiana4557722012-11-28 17:21:55 -0800936 */
937 int (*setDelay)(struct sensors_poll_device_t *dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -0800938 int handle, int64_t period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -0800939
940 /**
941 * Returns an array of sensor data.
Mathias Agopiana4557722012-11-28 17:21:55 -0800942 */
943 int (*poll)(struct sensors_poll_device_t *dev,
944 sensors_event_t* data, int count);
945 };
946 };
947
Mathias Agopiana4557722012-11-28 17:21:55 -0800948
949 /*
Clay Murphy8db1fb42013-12-19 09:58:28 -0800950 * Enables batch mode for the given sensor and sets the delay between events.
951 * See the Batching sensor results page for details:
952 * http://source.android.com/devices/sensors/batching.html
Mathias Agopiana4557722012-11-28 17:21:55 -0800953 */
954 int (*batch)(struct sensors_poll_device_1* dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -0800955 int handle, int flags, int64_t period_ns, int64_t timeout);
Mathias Agopiana4557722012-11-28 17:21:55 -0800956
Mathias Agopian16671c52013-07-24 21:07:40 -0700957 /*
958 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
959 * to the end of the "batch mode" FIFO for the specified sensor and flushes
Aravind Akellac841efd2014-06-03 19:21:35 -0700960 * the FIFO. If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero),
961 * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the
962 * event stream. This applies to all sensors other than ONE_SHOT sensors.
Mathias Agopian16671c52013-07-24 21:07:40 -0700963 */
964 int (*flush)(struct sensors_poll_device_1* dev, int handle);
965
Mathias Agopiana4557722012-11-28 17:21:55 -0800966 void (*reserved_procs[8])(void);
967
968} sensors_poll_device_1_t;
969
970
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800971/** convenience API for opening and closing a device */
972
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700973static inline int sensors_open(const struct hw_module_t* module,
974 struct sensors_poll_device_t** device) {
975 return module->methods->open(module,
976 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
977}
978
979static inline int sensors_close(struct sensors_poll_device_t* device) {
980 return device->common.close(&device->common);
981}
982
Mathias Agopiana4557722012-11-28 17:21:55 -0800983static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800984 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -0800985 return module->methods->open(module,
986 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
987}
988
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800989static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -0800990 return device->common.close(&device->common);
991}
992
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800993__END_DECLS
994
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800995#endif // ANDROID_SENSORS_INTERFACE_H