blob: caf0ea0342d75e3affc6d43171cfb6aea44942cb [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 */
103 SENSOR_FLAG_WAKE_UP = 1U << 0
104};
105
106/*
Mathias Agopiana4557722012-11-28 17:21:55 -0800107 * Sensor type
108 *
109 * Each sensor has a type which defines what this sensor measures and how
Clay Murphy8db1fb42013-12-19 09:58:28 -0800110 * measures are reported. See the Base sensors and Composite sensors lists
111 * for complete descriptions:
112 * http://source.android.com/devices/sensors/base_triggers.html
113 * http://source.android.com/devices/sensors/composite_sensors.html
Mathias Agopian1599ec62013-08-19 14:34:47 -0700114 *
115 * Device manufacturers (OEMs) can define their own sensor types, for
116 * their private use by applications or services provided by them. Such
117 * sensor types are specific to an OEM and can't be exposed in the SDK.
118 * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE.
Aravind Akella477fbd52014-04-07 22:46:01 +0000119 *
120 * All sensors defined outside of the device private range must correspond to
121 * a type defined in this file, and must satisfy the characteristics listed in
122 * the description of the sensor type.
123 *
124 * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also
125 * has a stringType.
126 * - StringType of sensors inside of the device private range MUST be prefixed
127 * by the sensor provider's or OEM reverse domain name. In particular, they
128 * cannot use the "android.sensor" prefix.
129 * - StringType of sensors outside of the device private range MUST correspond
130 * to the one defined in this file (starting with "android.sensor").
131 * For example, accelerometers must have
132 * type=SENSOR_TYPE_ACCELEROMETER and
133 * stringType=SENSOR_STRING_TYPE_ACCELEROMETER
134 *
135 * When android introduces a new sensor type that can replace an OEM-defined
136 * sensor type, the OEM must use the official sensor type and stringType on
137 * versions of the HAL that support this new official sensor type.
138 *
139 * Example (made up): Suppose Google's Glass team wants to surface a sensor
140 * detecting that Glass is on a head.
141 * - Such a sensor is not officially supported in android KitKat
142 * - Glass devices launching on KitKat can implement a sensor with
143 * type = 0x10001 and stringType = "com.google.glass.onheaddetector"
144 * - In L android release, if android decides to define
145 * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR,
146 * those types should replace the Glass-team-specific types in all future
147 * launches.
148 * - When launching glass on the L release, Google should now use the official
149 * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType.
150 * - This way, all applications can now use this sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800151 */
152
153/*
Mathias Agopian1599ec62013-08-19 14:34:47 -0700154 * Base for device manufacturers private sensor types.
155 * These sensor types can't be exposed in the SDK.
156 */
157#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000
158
159/*
Mathias Agopian16671c52013-07-24 21:07:40 -0700160 * SENSOR_TYPE_META_DATA
161 * trigger-mode: n/a
162 * wake-up sensor: n/a
163 *
164 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
165 *
166 * SENSOR_TYPE_META_DATA is a special token used to populate the
167 * sensors_meta_data_event structure. It doesn't correspond to a physical
168 * sensor. sensors_meta_data_event are special, they exist only inside
169 * the HAL and are generated spontaneously, as opposed to be related to
170 * a physical sensor.
171 *
Mathias Agopianaf32a8d2013-08-06 20:33:38 -0700172 * sensors_meta_data_event_t.version must be META_DATA_VERSION
173 * sensors_meta_data_event_t.sensor must be 0
174 * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
175 * sensors_meta_data_event_t.reserved must be 0
176 * sensors_meta_data_event_t.timestamp must be 0
Mathias Agopian16671c52013-07-24 21:07:40 -0700177 *
178 * The payload is a meta_data_event_t, where:
179 * meta_data_event_t.what can take the following values:
180 *
181 * META_DATA_FLUSH_COMPLETE
182 * This event indicates that a previous (*flush)() call has completed for the sensor
183 * handle specified in meta_data_event_t.sensor.
184 * see (*flush)() for more details
185 *
186 * All other values for meta_data_event_t.what are reserved and
187 * must not be used.
188 *
189 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000190#define SENSOR_TYPE_META_DATA (0)
Mathias Agopian16671c52013-07-24 21:07:40 -0700191
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800192/*
193 * SENSOR_TYPE_ACCELEROMETER
Mathias Agopiana4557722012-11-28 17:21:55 -0800194 * trigger-mode: continuous
195 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800196 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800197 * All values are in SI units (m/s^2) and measure the acceleration of the
198 * device minus the force of gravity.
199 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800200 */
201#define SENSOR_TYPE_ACCELEROMETER (1)
Aravind Akella477fbd52014-04-07 22:46:01 +0000202#define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800203
204/*
205 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Mathias Agopiana4557722012-11-28 17:21:55 -0800206 * trigger-mode: continuous
207 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800208 *
209 * All values are in micro-Tesla (uT) and measure the geomagnetic
210 * field in the X, Y and Z axis.
211 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800212 */
213#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
214#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akella477fbd52014-04-07 22:46:01 +0000215#define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800216
217/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800218 * SENSOR_TYPE_ORIENTATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800219 * trigger-mode: continuous
220 * wake-up sensor: no
Clay Murphy8db1fb42013-12-19 09:58:28 -0800221 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800222 * All values are angles in degrees.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800223 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700224 * Orientation sensors return sensor events for all 3 axes at a constant
225 * rate defined by setDelay().
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800226 */
227#define SENSOR_TYPE_ORIENTATION (3)
Aravind Akella477fbd52014-04-07 22:46:01 +0000228#define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800229
230/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800231 * SENSOR_TYPE_GYROSCOPE
Mathias Agopiana4557722012-11-28 17:21:55 -0800232 * trigger-mode: continuous
233 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800234 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700235 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800236 * around the X, Y and Z axis.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800237 */
238#define SENSOR_TYPE_GYROSCOPE (4)
Aravind Akella477fbd52014-04-07 22:46:01 +0000239#define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800240
241/*
242 * SENSOR_TYPE_LIGHT
Mathias Agopiana4557722012-11-28 17:21:55 -0800243 * trigger-mode: on-change
244 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800245 *
246 * The light sensor value is returned in SI lux units.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800247 */
248#define SENSOR_TYPE_LIGHT (5)
Aravind Akella477fbd52014-04-07 22:46:01 +0000249#define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800250
251/*
252 * SENSOR_TYPE_PRESSURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800253 * trigger-mode: continuous
254 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800255 *
256 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800257 */
258#define SENSOR_TYPE_PRESSURE (6)
Aravind Akella477fbd52014-04-07 22:46:01 +0000259#define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800260
261/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
262#define SENSOR_TYPE_TEMPERATURE (7)
Aravind Akella477fbd52014-04-07 22:46:01 +0000263#define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800264
265/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800266 * SENSOR_TYPE_PROXIMITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800267 * trigger-mode: on-change
Aravind Akella6242f322014-02-28 18:46:19 -0800268 * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
Mike Lockwooda2414312009-11-03 10:29:50 -0500269 *
Clay Murphy8db1fb42013-12-19 09:58:28 -0800270 * The value corresponds to the distance to the nearest object in centimeters.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800271 */
272#define SENSOR_TYPE_PROXIMITY (8)
Aravind Akella477fbd52014-04-07 22:46:01 +0000273#define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800274
275/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800276 * SENSOR_TYPE_GRAVITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800277 * trigger-mode: continuous
278 * wake-up sensor: no
Mathias Agopian42b743c2010-11-22 15:55:32 -0800279 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800280 * A gravity output indicates the direction of and magnitude of gravity in
Clay Murphy8db1fb42013-12-19 09:58:28 -0800281 * the devices's coordinates.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800282 */
283#define SENSOR_TYPE_GRAVITY (9)
Aravind Akella477fbd52014-04-07 22:46:01 +0000284#define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800285
286/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800287 * SENSOR_TYPE_LINEAR_ACCELERATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800288 * trigger-mode: continuous
289 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800290 *
291 * Indicates the linear acceleration of the device in device coordinates,
292 * not including gravity.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800293 */
294#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
Aravind Akella477fbd52014-04-07 22:46:01 +0000295#define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800296
297
298/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800299 * SENSOR_TYPE_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800300 * trigger-mode: continuous
301 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800302 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700303 * The rotation vector symbolizes the orientation of the device relative to the
Clay Murphy8db1fb42013-12-19 09:58:28 -0800304 * East-North-Up coordinates frame.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800305 */
306#define SENSOR_TYPE_ROTATION_VECTOR (11)
Aravind Akella477fbd52014-04-07 22:46:01 +0000307#define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800308
309/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800310 * SENSOR_TYPE_RELATIVE_HUMIDITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800311 * trigger-mode: on-change
312 * wake-up sensor: no
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100313 *
314 * A relative humidity sensor measures relative ambient air humidity and
315 * returns a value in percent.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800316 */
317#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
Aravind Akella477fbd52014-04-07 22:46:01 +0000318#define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800319
320/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800321 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800322 * trigger-mode: on-change
323 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700324 *
325 * The ambient (room) temperature in degree Celsius.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800326 */
327#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
Aravind Akella477fbd52014-04-07 22:46:01 +0000328#define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800329
330/*
331 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800332 * trigger-mode: continuous
333 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700334 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800335 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
336 * reported separately instead of being included in the measurement.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800337 */
338#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
Aravind Akella477fbd52014-04-07 22:46:01 +0000339#define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800340
341/*
342 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800343 * trigger-mode: continuous
344 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800345 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800346 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
Clay Murphy8db1fb42013-12-19 09:58:28 -0800347 * field.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800348 */
349#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
Aravind Akella477fbd52014-04-07 22:46:01 +0000350#define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800351
352/*
353 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800354 * trigger-mode: continuous
355 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800356 *
357 * All values are in radians/second and measure the rate of rotation
Clay Murphy8db1fb42013-12-19 09:58:28 -0800358 * around the X, Y and Z axis.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800359 */
360#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
Aravind Akella477fbd52014-04-07 22:46:01 +0000361#define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800362
Mathias Agopiana4557722012-11-28 17:21:55 -0800363/*
364 * SENSOR_TYPE_SIGNIFICANT_MOTION
365 * trigger-mode: one-shot
Aravind Akella6242f322014-02-28 18:46:19 -0800366 * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
Mathias Agopiana4557722012-11-28 17:21:55 -0800367 *
368 * A sensor of this type triggers an event each time significant motion
369 * is detected and automatically disables itself.
370 * The only allowed value to return is 1.0.
Mathias Agopiana4557722012-11-28 17:21:55 -0800371 */
372
373#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
Aravind Akella477fbd52014-04-07 22:46:01 +0000374#define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
Mathias Agopiana4557722012-11-28 17:21:55 -0800375
376/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800377 * SENSOR_TYPE_STEP_DETECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800378 * trigger-mode: special
379 * wake-up sensor: no
380 *
381 * A sensor of this type triggers an event each time a step is taken
Clay Murphy8db1fb42013-12-19 09:58:28 -0800382 * by the user. The only allowed value to return is 1.0 and an event
383 * is generated for each step.
Mathias Agopiana4557722012-11-28 17:21:55 -0800384 */
385
Mathias Agopian2f276f52013-01-28 17:54:41 -0800386#define SENSOR_TYPE_STEP_DETECTOR (18)
Aravind Akella477fbd52014-04-07 22:46:01 +0000387#define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
Mathias Agopiana4557722012-11-28 17:21:55 -0800388
389
390/*
391 * SENSOR_TYPE_STEP_COUNTER
392 * trigger-mode: on-change
393 * wake-up sensor: no
394 *
395 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800396 * the last reboot while activated. The value is returned as a uint64_t and is
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700397 * reset to zero only on a system / android reboot.
Mathias Agopiana4557722012-11-28 17:21:55 -0800398 */
399
400#define SENSOR_TYPE_STEP_COUNTER (19)
Aravind Akella477fbd52014-04-07 22:46:01 +0000401#define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
Mathias Agopiana4557722012-11-28 17:21:55 -0800402
Etienne Le Grandca858142013-02-26 19:17:20 -0800403/*
404 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
405 * trigger-mode: continuous
406 * wake-up sensor: no
407 *
408 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
409 * of using a gyroscope.
Etienne Le Grandca858142013-02-26 19:17:20 -0800410 */
Aravind Akella477fbd52014-04-07 22:46:01 +0000411#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
412#define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
413
414/*
415 * SENSOR_TYPE_HEART_RATE
416 * trigger-mode: on-change
417 * wake-up sensor: no
418 *
Etienne Le Grand7b361582014-05-16 11:08:28 -0700419 * A sensor of this type returns the current heart rate.
420 * The events contain the current heart rate in beats per minute (BPM) and the
421 * status of the sensor during the measurement. See heart_rate_event_t for more
422 * details.
423 *
424 * Because this sensor is on-change, events must be generated when and only
425 * when heart_rate.bpm or heart_rate.status have changed since the last
426 * event. The event should be generated no faster than every period_ns passed
427 * to setDelay() or to batch(). See the definition of the on-change trigger
428 * mode for more information.
429 *
Aravind Akella477fbd52014-04-07 22:46:01 +0000430 * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
431 */
432#define SENSOR_TYPE_HEART_RATE (21)
433#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
Mathias Agopiana4557722012-11-28 17:21:55 -0800434
Aravind Akella6242f322014-02-28 18:46:19 -0800435/*
436 * SENSOR_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR
437 * Same as proximity_sensor but does not wake up the AP from suspend mode.
438 * wake-up sensor: no
439 */
440#define SENSOR_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR (22)
441#define SENSOR_STRING_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR "android.sensor.non_wake_up_proximity_sensor"
442
443/*
444 * The sensors below are wake_up variants of the base sensor types defined
445 * above. When registered in batch mode, these sensors will wake up the AP when
Aravind Akellaf895c682014-04-30 11:46:09 -0700446 * their FIFOs are full or when the batch timeout expires. A separate FIFO has
447 * to be maintained for wake up sensors and non wake up sensors. The non wake-up
448 * sensors need to overwrite their FIFOs when they are full till the AP wakes up
449 * and the wake-up sensors will wake-up the AP when their FIFOs are full or when
450 * the batch timeout expires without losing events.
451 * Note: Sensors of type SENSOR_TYPE_PROXIMITY are also wake up sensors and
452 * should be treated as such. Wake-up one-shot sensors like SIGNIFICANT_MOTION
453 * cannot be batched, hence the text about batch above doesn't apply to them.
Aravind Akella6242f322014-02-28 18:46:19 -0800454 *
455 * Define these sensors only if:
456 * 1) batching is supported.
457 * 2) wake-up and non wake-up variants of each sensor can be activated at
458 * different rates.
459 *
460 * wake-up sensor: yes
461 * Set SENSOR_FLAG_WAKE_UP flag for all these sensors.
462 */
463#define SENSOR_TYPE_WAKE_UP_ACCELEROMETER (23)
464#define SENSOR_STRING_TYPE_WAKE_UP_ACCELEROMETER "android.sensor.wake_up_accelerometer"
465
466#define SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD (24)
467#define SENSOR_STRING_TYPE_WAKE_UP_MAGNETIC_FIELD "android.sensor.wake_up_magnetic_field"
468
469#define SENSOR_TYPE_WAKE_UP_ORIENTATION (25)
470#define SENSOR_STRING_TYPE_WAKE_UP_ORIENTATION "android.sensor.wake_up_orientation"
471
472#define SENSOR_TYPE_WAKE_UP_GYROSCOPE (26)
473#define SENSOR_STRING_TYPE_WAKE_UP_GYROSCOPE "android.sensor.wake_up_gyroscope"
474
475#define SENSOR_TYPE_WAKE_UP_LIGHT (27)
476#define SENSOR_STRING_TYPE_WAKE_UP_LIGHT "android.sensor.wake_up_light"
477
478#define SENSOR_TYPE_WAKE_UP_PRESSURE (28)
479#define SENSOR_STRING_TYPE_WAKE_UP_PRESSURE "android.sensor.wake_up_pressure"
480
481#define SENSOR_TYPE_WAKE_UP_GRAVITY (29)
482#define SENSOR_STRING_TYPE_WAKE_UP_GRAVITY "android.sensor.wake_up_gravity"
483
484#define SENSOR_TYPE_WAKE_UP_LINEAR_ACCELERATION (30)
485#define SENSOR_STRING_TYPE_WAKE_UP_LINEAR_ACCELERATION "android.sensor.wake_up_linear_acceleration"
486
487#define SENSOR_TYPE_WAKE_UP_ROTATION_VECTOR (31)
488#define SENSOR_STRING_TYPE_WAKE_UP_ROTATION_VECTOR "android.sensor.wake_up_rotation_vector"
489
490#define SENSOR_TYPE_WAKE_UP_RELATIVE_HUMIDITY (32)
491#define SENSOR_STRING_TYPE_WAKE_UP_RELATIVE_HUMIDITY "android.sensor.wake_up_relative_humidity"
492
493#define SENSOR_TYPE_WAKE_UP_AMBIENT_TEMPERATURE (33)
494#define SENSOR_STRING_TYPE_WAKE_UP_AMBIENT_TEMPERATURE "android.sensor.wake_up_ambient_temperature"
495
496#define SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED (34)
497#define SENSOR_STRING_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.wake_up_magnetic_field_uncalibrated"
498
499#define SENSOR_TYPE_WAKE_UP_GAME_ROTATION_VECTOR (35)
500#define SENSOR_STRING_TYPE_WAKE_UP_GAME_ROTATION_VECTOR "android.sensor.wake_up_game_rotation_vector"
501
502#define SENSOR_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED (36)
503#define SENSOR_STRING_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED "android.sensor.wake_up_gyroscope_uncalibrated"
504
505#define SENSOR_TYPE_WAKE_UP_STEP_DETECTOR (37)
506#define SENSOR_STRING_TYPE_WAKE_UP_STEP_DETECTOR "android.sensor.wake_up_step_detector"
507
508#define SENSOR_TYPE_WAKE_UP_STEP_COUNTER (38)
509#define SENSOR_STRING_TYPE_WAKE_UP_STEP_COUNTER "android.sensor.wake_up_step_counter"
510
511#define SENSOR_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR (39)
512#define SENSOR_STRING_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.wake_up_geomagnetic_rotation_vector"
513
514#define SENSOR_TYPE_WAKE_UP_HEART_RATE (40)
515#define SENSOR_STRING_TYPE_WAKE_UP_HEART_RATE "android.sensor.wake_up_heart_rate"
516
Aravind Akellaf895c682014-04-30 11:46:09 -0700517/*
518 * SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
519 * trigger-mode: special (setDelay has no impact)
520 * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
521 *
522 * A sensor of this type generates an event each time a tilt event is detected. A tilt event
523 * 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 -0700524 * 35 degrees since the activation or the last trigger of the sensor.
Aravind Akellaf895c682014-04-30 11:46:09 -0700525 * initial_estimated_gravity = average of accelerometer measurements over the first
Etienne Le Grand53017ef2014-05-28 15:42:48 -0700526 * 1 second after activation or the estimated gravity at the last
527 * trigger.
Aravind Akellaf895c682014-04-30 11:46:09 -0700528 * current_estimated_gravity = average of accelerometer measurements over the last 2 seconds.
529 * trigger when angle (initial_estimated_gravity, current_estimated_gravity) > 35 degrees
530 *
531 * Large accelerations without a change in phone orientation should not trigger a tilt event.
532 * For example, a sharp turn or strong acceleration while driving a car should not trigger a tilt
533 * event, even though the angle of the average acceleration might vary by more than 35 degrees.
534 *
535 * Typically, this sensor is implemented with the help of only an accelerometer. Other sensors can
536 * be used as well if they do not increase the power consumption significantly. This is a low power
537 * sensor that should allow the AP to go into suspend mode. Do not emulate this sensor in the HAL.
538 * Like other wake up sensors, the driver is expected to a hold a wake_lock with a timeout of 200 ms
539 * while reporting this event. The only allowed return value is 1.0.
540 */
541#define SENSOR_TYPE_WAKE_UP_TILT_DETECTOR (41)
542#define SENSOR_STRING_TYPE_WAKE_UP_TILT_DETECTOR "android.sensor.wake_up_tilt_detector"
543
Etienne Le Grandba123122014-05-05 18:20:42 -0700544/*
545 * SENSOR_TYPE_WAKE_GESTURE
546 * trigger-mode: one-shot
547 * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
548 *
549 * A sensor enabling waking up the device based on a device specific motion.
550 *
551 * When this sensor triggers, the device behaves as if the power button was
552 * pressed, turning the screen on. This behavior (turning on the screen when
553 * this sensor triggers) might be deactivated by the user in the device
554 * settings. Changes in settings do not impact the behavior of the sensor:
555 * only whether the framework turns the screen on when it triggers.
556 *
557 * The actual gesture to be detected is not specified, and can be chosen by
558 * the manufacturer of the device.
559 * This sensor must be low power, as it is likely to be activated 24/7.
560 * The only allowed value to return is 1.0.
561 */
562#define SENSOR_TYPE_WAKE_GESTURE (42)
563#define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture"
564
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800565/**
566 * Values returned by the accelerometer in various locations in the universe.
567 * all values are in SI units (m/s^2)
568 */
569#define GRAVITY_SUN (275.0f)
570#define GRAVITY_EARTH (9.80665f)
571
572/** Maximum magnetic field on Earth's surface */
573#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
574
575/** Minimum magnetic field on Earth's surface */
576#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
577
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800578/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700579 * Possible values of the status field of sensor events.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800580 */
Etienne Le Grand7b361582014-05-16 11:08:28 -0700581#define SENSOR_STATUS_NO_CONTACT -1
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800582#define SENSOR_STATUS_UNRELIABLE 0
583#define SENSOR_STATUS_ACCURACY_LOW 1
584#define SENSOR_STATUS_ACCURACY_MEDIUM 2
585#define SENSOR_STATUS_ACCURACY_HIGH 3
586
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800587/**
588 * sensor event data
589 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800590typedef struct {
591 union {
592 float v[3];
593 struct {
594 float x;
595 float y;
596 float z;
597 };
598 struct {
599 float azimuth;
600 float pitch;
601 float roll;
602 };
603 };
604 int8_t status;
605 uint8_t reserved[3];
606} sensors_vec_t;
607
608/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800609 * uncalibrated gyroscope and magnetometer event data
610 */
611typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700612 union {
613 float uncalib[3];
614 struct {
615 float x_uncalib;
616 float y_uncalib;
617 float z_uncalib;
618 };
619 };
620 union {
621 float bias[3];
622 struct {
623 float x_bias;
624 float y_bias;
625 float z_bias;
626 };
627 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800628} uncalibrated_event_t;
629
Mathias Agopian16671c52013-07-24 21:07:40 -0700630typedef struct meta_data_event {
631 int32_t what;
632 int32_t sensor;
633} meta_data_event_t;
634
Etienne Le Grandca858142013-02-26 19:17:20 -0800635/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700636 * Heart rate event data
637 */
638typedef struct {
639 // Heart rate in beats per minute.
640 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
641 float bpm;
642 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
643 int8_t status;
644} heart_rate_event_t;
645
646/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800647 * Union of the various types of sensor data
648 * that can be returned.
649 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700650typedef struct sensors_event_t {
651 /* must be sizeof(struct sensors_event_t) */
652 int32_t version;
653
654 /* sensor identifier */
655 int32_t sensor;
656
657 /* sensor type */
658 int32_t type;
659
660 /* reserved */
661 int32_t reserved0;
662
663 /* time is in nanosecond */
664 int64_t timestamp;
665
666 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700667 union {
668 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700669
Mathias Agopian27e16682013-07-08 14:00:54 -0700670 /* acceleration values are in meter per second per second (m/s^2) */
671 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700672
Mathias Agopian27e16682013-07-08 14:00:54 -0700673 /* magnetic vector values are in micro-Tesla (uT) */
674 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700675
Mathias Agopian27e16682013-07-08 14:00:54 -0700676 /* orientation values are in degrees */
677 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700678
Mathias Agopian27e16682013-07-08 14:00:54 -0700679 /* gyroscope values are in rad/s */
680 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700681
Mathias Agopian27e16682013-07-08 14:00:54 -0700682 /* temperature is in degrees centigrade (Celsius) */
683 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700684
Mathias Agopian27e16682013-07-08 14:00:54 -0700685 /* distance in centimeters */
686 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700687
Mathias Agopian27e16682013-07-08 14:00:54 -0700688 /* light in SI lux units */
689 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700690
Mathias Agopian27e16682013-07-08 14:00:54 -0700691 /* pressure in hectopascal (hPa) */
692 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100693
Mathias Agopian27e16682013-07-08 14:00:54 -0700694 /* relative humidity in percent */
695 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800696
Mathias Agopian27e16682013-07-08 14:00:54 -0700697 /* uncalibrated gyroscope values are in rad/s */
698 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800699
Mathias Agopian27e16682013-07-08 14:00:54 -0700700 /* uncalibrated magnetometer values are in micro-Teslas */
701 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700702
Etienne Le Grand7b361582014-05-16 11:08:28 -0700703 /* heart rate data containing value in bpm and status */
704 heart_rate_event_t heart_rate;
Aravind Akella477fbd52014-04-07 22:46:01 +0000705
Mathias Agopian16671c52013-07-24 21:07:40 -0700706 /* this is a special event. see SENSOR_TYPE_META_DATA above.
707 * sensors_meta_data_event_t events are all reported with a type of
708 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
709 */
710 meta_data_event_t meta_data;
Mathias Agopian27e16682013-07-08 14:00:54 -0700711 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800712
Mathias Agopian27e16682013-07-08 14:00:54 -0700713 union {
714 uint64_t data[8];
715
716 /* step-counter */
717 uint64_t step_counter;
718 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700719 };
Aravind Akella6242f322014-02-28 18:46:19 -0800720
721 /* Reserved flags for internal use. Set to zero. */
722 uint32_t flags;
723
724 uint32_t reserved1[3];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700725} sensors_event_t;
726
727
Mathias Agopian16671c52013-07-24 21:07:40 -0700728/* see SENSOR_TYPE_META_DATA */
729typedef sensors_event_t sensors_meta_data_event_t;
730
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700731
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800732struct sensor_t;
733
734/**
735 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
736 * and the fields of this data structure must begin with hw_module_t
737 * followed by module specific information.
738 */
739struct sensors_module_t {
740 struct hw_module_t common;
741
742 /**
743 * Enumerate all available sensors. The list is returned in "list".
744 * @return number of sensors in the list
745 */
746 int (*get_sensors_list)(struct sensors_module_t* module,
747 struct sensor_t const** list);
748};
749
750struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800751
752 /* Name of this sensor.
753 * All sensors of the same "type" must have a different "name".
754 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800755 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800756
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800757 /* vendor of the hardware part */
758 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800759
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800760 /* version of the hardware part + driver. The value of this field
761 * must increase when the driver is updated in a way that changes the
762 * output of this sensor. This is important for fused sensors when the
763 * fusion algorithm is updated.
Aravind Akella6242f322014-02-28 18:46:19 -0800764 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800765 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800766
767 /* handle that identifies this sensors. This handle is used to reference
768 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800769 */
770 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800771
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800772 /* this sensor's type. */
773 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800774
775 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800776 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800777
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800778 /* smallest difference between two values reported by this sensor */
779 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800780
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800781 /* rough estimate of this sensor's power consumption in mA */
782 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800783
784 /* this value depends on the trigger mode:
785 *
786 * continuous: minimum sample period allowed in microseconds
787 * on-change : 0
788 * one-shot :-1
789 * special : 0, unless otherwise noted
790 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700791 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800792
Mathias Agopian16671c52013-07-24 21:07:40 -0700793 /* number of events reserved for this sensor in the batch mode FIFO.
794 * If there is a dedicated FIFO for this sensor, then this is the
795 * size of this FIFO. If the FIFO is shared with other sensors,
796 * this is the size reserved for that sensor and it can be zero.
797 */
798 uint32_t fifoReservedEventCount;
799
800 /* maximum number of events of this sensor that could be batched.
801 * This is especially relevant when the FIFO is shared between
802 * several sensors; this value is then set to the size of that FIFO.
803 */
804 uint32_t fifoMaxEventCount;
805
Aravind Akella477fbd52014-04-07 22:46:01 +0000806 /* type of this sensor as a string. Set to corresponding
807 * SENSOR_STRING_TYPE_*.
808 * When defining an OEM specific sensor or sensor manufacturer specific
809 * sensor, use your reserve domain name as a prefix.
810 * ex: com.google.glass.onheaddetector
811 * For sensors of known type, the android framework might overwrite this
812 * string automatically.
813 */
814 const char* stringType;
815
816 /* permission required to see this sensor, register to it and receive data.
817 * Set to "" if no permission is required. Some sensor types like the
818 * heart rate monitor have a mandatory require_permission.
819 * For sensors that always require a specific permission, like the heart
820 * rate monitor, the android framework might overwrite this string
821 * automatically.
822 */
823 const char* requiredPermission;
824
Aravind Akella6242f322014-02-28 18:46:19 -0800825 /* This value is defined only for continuous mode sensors. It is the delay between two
826 * sensor events corresponding to the lowest frequency that this sensor supports. When
827 * lower frequencies are requested through batch()/setDelay() the events will be generated
828 * at this frequency instead. It can be used by the framework or applications to estimate
829 * when the batch FIFO may be full.
830 * NOTE: period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
831 * continuous: maximum sampling period allowed in microseconds.
832 * on-change, one-shot, special : -1
833 * Availability: SENSORS_DEVICE_API_VERSION_1_3
834 */
835 #ifdef __LP64__
836 int64_t maxDelay;
837 #else
838 int32_t maxDelay;
839 #endif
840
841 /* Flags for sensor. See SENSOR_FLAG_* above. */
842 #ifdef __LP64__
843 uint64_t flags;
844 #else
845 uint32_t flags;
846 #endif
847
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800848 /* reserved fields, must be zero */
Aravind Akella6242f322014-02-28 18:46:19 -0800849 void* reserved[2];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800850};
851
852
Mathias Agopiana4557722012-11-28 17:21:55 -0800853/*
854 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
855 * and is present for backward binary and source compatibility.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800856 * See the Sensors HAL interface section for complete descriptions of the
857 * following functions:
858 * http://source.android.com/devices/sensors/index.html#hal
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800859 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700860struct sensors_poll_device_t {
861 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700862 int (*activate)(struct sensors_poll_device_t *dev,
863 int handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700864 int (*setDelay)(struct sensors_poll_device_t *dev,
865 int handle, int64_t ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700866 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700867 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700868};
869
Mathias Agopiana4557722012-11-28 17:21:55 -0800870/*
871 * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
872 */
873typedef struct sensors_poll_device_1 {
874 union {
875 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
876 * and can be down-cast to it
877 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800878 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -0800879
880 struct {
881 struct hw_device_t common;
882
Clay Murphy8db1fb42013-12-19 09:58:28 -0800883 /* Activate/de-activate one sensor. Return 0 on success, negative
Mathias Agopiana4557722012-11-28 17:21:55 -0800884 *
885 * handle is the handle of the sensor to change.
886 * enabled set to 1 to enable, or 0 to disable the sensor.
887 *
Clay Murphy8db1fb42013-12-19 09:58:28 -0800888 * Return 0 on success, negative errno code otherwise.
Mathias Agopiana4557722012-11-28 17:21:55 -0800889 */
890 int (*activate)(struct sensors_poll_device_t *dev,
891 int handle, int enabled);
892
893 /**
Aravind Akella6242f322014-02-28 18:46:19 -0800894 * Set the events's period in nanoseconds for a given sensor. If
895 * period_ns > max_delay it will be truncated to max_delay and if
896 * period_ns < min_delay it will be replaced by min_delay.
Mathias Agopiana4557722012-11-28 17:21:55 -0800897 */
898 int (*setDelay)(struct sensors_poll_device_t *dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -0800899 int handle, int64_t period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -0800900
901 /**
902 * Returns an array of sensor data.
Mathias Agopiana4557722012-11-28 17:21:55 -0800903 */
904 int (*poll)(struct sensors_poll_device_t *dev,
905 sensors_event_t* data, int count);
906 };
907 };
908
Mathias Agopiana4557722012-11-28 17:21:55 -0800909
910 /*
Clay Murphy8db1fb42013-12-19 09:58:28 -0800911 * Enables batch mode for the given sensor and sets the delay between events.
912 * See the Batching sensor results page for details:
913 * http://source.android.com/devices/sensors/batching.html
Mathias Agopiana4557722012-11-28 17:21:55 -0800914 */
915 int (*batch)(struct sensors_poll_device_1* dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -0800916 int handle, int flags, int64_t period_ns, int64_t timeout);
Mathias Agopiana4557722012-11-28 17:21:55 -0800917
Mathias Agopian16671c52013-07-24 21:07:40 -0700918 /*
919 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
920 * to the end of the "batch mode" FIFO for the specified sensor and flushes
Clay Murphy8db1fb42013-12-19 09:58:28 -0800921 * the FIFO.
Mathias Agopian16671c52013-07-24 21:07:40 -0700922 */
923 int (*flush)(struct sensors_poll_device_1* dev, int handle);
924
Mathias Agopiana4557722012-11-28 17:21:55 -0800925 void (*reserved_procs[8])(void);
926
927} sensors_poll_device_1_t;
928
929
930
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800931/** convenience API for opening and closing a device */
932
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700933static inline int sensors_open(const struct hw_module_t* module,
934 struct sensors_poll_device_t** device) {
935 return module->methods->open(module,
936 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
937}
938
939static inline int sensors_close(struct sensors_poll_device_t* device) {
940 return device->common.close(&device->common);
941}
942
Mathias Agopiana4557722012-11-28 17:21:55 -0800943static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800944 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -0800945 return module->methods->open(module,
946 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
947}
948
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800949static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -0800950 return device->common.close(&device->common);
951}
952
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800953__END_DECLS
954
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800955#endif // ANDROID_SENSORS_INTERFACE_H