blob: 08a65f8b855e16058454e869adbb2bb6108684c5 [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
Andreas Huber92190172016-10-10 13:18:52 -070027#include "sensors-base.h"
28
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080029__BEGIN_DECLS
30
Mathias Agopian56f66cc2012-11-08 15:57:38 -080031/*****************************************************************************/
32
33#define SENSORS_HEADER_VERSION 1
34#define SENSORS_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
35#define SENSORS_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, SENSORS_HEADER_VERSION)
Mathias Agopiana4557722012-11-28 17:21:55 -080036#define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION)
Mathias Agopian16671c52013-07-24 21:07:40 -070037#define SENSORS_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, SENSORS_HEADER_VERSION)
Aravind Akella477fbd52014-04-07 22:46:01 +000038#define SENSORS_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION_2(1, 2, SENSORS_HEADER_VERSION)
Aravind Akella6242f322014-02-28 18:46:19 -080039#define SENSORS_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION_2(1, 3, SENSORS_HEADER_VERSION)
Ashutosh Joshi6507f502015-04-03 16:22:32 -070040#define SENSORS_DEVICE_API_VERSION_1_4 HARDWARE_DEVICE_API_VERSION_2(1, 4, SENSORS_HEADER_VERSION)
Mathias Agopian56f66cc2012-11-08 15:57:38 -080041
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080042/**
Clay Murphy8db1fb42013-12-19 09:58:28 -080043 * Please see the Sensors section of source.android.com for an
44 * introduction to and detailed descriptions of Android sensor types:
45 * http://source.android.com/devices/sensors/index.html
46 */
47
48/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080049 * The id of this module
50 */
51#define SENSORS_HARDWARE_MODULE_ID "sensors"
52
53/**
54 * Name of the sensors device to open
55 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -070056#define SENSORS_HARDWARE_POLL "poll"
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080057
58/**
59 * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
60 * A Handle identifies a given sensors. The handle is used to activate
61 * and/or deactivate sensors.
62 * In this version of the API there can only be 256 handles.
63 */
64#define SENSORS_HANDLE_BASE 0
65#define SENSORS_HANDLE_BITS 8
66#define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS)
67
68
Mathias Agopiana4557722012-11-28 17:21:55 -080069/*
Aravind Akella6242f322014-02-28 18:46:19 -080070 * **** Deprecated *****
Mathias Agopiana4557722012-11-28 17:21:55 -080071 * flags for (*batch)()
72 * Availability: SENSORS_DEVICE_API_VERSION_1_0
Aravind Akella6242f322014-02-28 18:46:19 -080073 * see (*batch)() documentation for details.
74 * Deprecated as of SENSORS_DEVICE_API_VERSION_1_3.
75 * WAKE_UP_* sensors replace WAKE_UPON_FIFO_FULL concept.
Mathias Agopiana4557722012-11-28 17:21:55 -080076 */
77enum {
78 SENSORS_BATCH_DRY_RUN = 0x00000001,
79 SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
80};
81
Mathias Agopian16671c52013-07-24 21:07:40 -070082/*
83 * what field for meta_data_event_t
84 */
85enum {
86 /* a previous flush operation has completed */
Andreas Huber92190172016-10-10 13:18:52 -070087 // META_DATA_FLUSH_COMPLETE = 1,
Mathias Agopianaf32a8d2013-08-06 20:33:38 -070088 META_DATA_VERSION /* always last, leave auto-assigned */
Mathias Agopian16671c52013-07-24 21:07:40 -070089};
90
Mathias Agopiana4557722012-11-28 17:21:55 -080091/*
Aravind Akella477fbd52014-04-07 22:46:01 +000092 * The permission to use for body sensors (like heart rate monitors).
93 * See sensor types for more details on what sensors should require this
94 * permission.
95 */
96#define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS"
97
98/*
Ashutosh Joshi6507f502015-04-03 16:22:32 -070099 * Availability: SENSORS_DEVICE_API_VERSION_1_4
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700100 * Sensor HAL modes used in set_operation_mode method
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700101 */
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700102
Peng Xud1562992016-03-29 18:14:05 -0700103#define SENSOR_FLAG_MASK(nbit, shift) (((1<<(nbit))-1)<<(shift))
104#define SENSOR_FLAG_MASK_1(shift) SENSOR_FLAG_MASK(1, shift)
105
106/*
107 * Mask and shift for reporting mode sensor flags defined above.
108 */
109#define REPORTING_MODE_SHIFT (1)
110#define REPORTING_MODE_NBIT (3)
111#define REPORTING_MODE_MASK SENSOR_FLAG_MASK(REPORTING_MODE_NBIT, REPORTING_MODE_SHIFT)
112 // 0xE
113
114/*
115 * Mask and shift for data_injection mode sensor flags defined above.
116 */
117#define DATA_INJECTION_SHIFT (4)
118#define DATA_INJECTION_MASK SENSOR_FLAG_MASK_1(DATA_INJECTION_SHIFT) //0x10
119
120/*
121 * Mask and shift for dynamic sensor flag.
122 */
123#define DYNAMIC_SENSOR_SHIFT (5)
124#define DYNAMIC_SENSOR_MASK SENSOR_FLAG_MASK_1(DYNAMIC_SENSOR_SHIFT) //0x20
125
126/*
127 * Mask and shift for sensor additional information support.
128 */
129#define ADDITIONAL_INFO_SHIFT (6)
130#define ADDITIONAL_INFO_MASK SENSOR_FLAG_MASK_1(ADDITIONAL_INFO_SHIFT) //0x40
131
Aravind Akella477fbd52014-04-07 22:46:01 +0000132#define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800133#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
Aravind Akella477fbd52014-04-07 22:46:01 +0000134#define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
Aravind Akella477fbd52014-04-07 22:46:01 +0000135#define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
Aravind Akella477fbd52014-04-07 22:46:01 +0000136#define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
Aravind Akella477fbd52014-04-07 22:46:01 +0000137#define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
Aravind Akella477fbd52014-04-07 22:46:01 +0000138#define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
Aravind Akella477fbd52014-04-07 22:46:01 +0000139#define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
Aravind Akella477fbd52014-04-07 22:46:01 +0000140#define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
Aravind Akella477fbd52014-04-07 22:46:01 +0000141#define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
Aravind Akella477fbd52014-04-07 22:46:01 +0000142#define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
Aravind Akella477fbd52014-04-07 22:46:01 +0000143#define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
Aravind Akella477fbd52014-04-07 22:46:01 +0000144#define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
Aravind Akella477fbd52014-04-07 22:46:01 +0000145#define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
Aravind Akella477fbd52014-04-07 22:46:01 +0000146#define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
Aravind Akella477fbd52014-04-07 22:46:01 +0000147#define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
Aravind Akella477fbd52014-04-07 22:46:01 +0000148#define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
Aravind Akella477fbd52014-04-07 22:46:01 +0000149#define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
Aravind Akella477fbd52014-04-07 22:46:01 +0000150#define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
Aravind Akella477fbd52014-04-07 22:46:01 +0000151#define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
Aravind Akella477fbd52014-04-07 22:46:01 +0000152#define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
Aravind Akella477fbd52014-04-07 22:46:01 +0000153#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
Aravind Akella9057e122014-07-28 18:01:37 -0700154#define SENSOR_STRING_TYPE_TILT_DETECTOR "android.sensor.tilt_detector"
Etienne Le Grandba123122014-05-05 18:20:42 -0700155#define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture"
Jeff Brown8df2feb2014-07-17 15:11:51 -0700156#define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture"
Aravind Akella952471e2014-07-17 12:40:54 -0700157#define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture"
Nick Vaccaroadbfbb72015-01-13 12:14:28 -0800158#define SENSOR_STRING_TYPE_WRIST_TILT_GESTURE "android.sensor.wrist_tilt_gesture"
Trevor Bunkerf8e7ed32016-01-08 10:22:23 -0800159#define SENSOR_STRING_TYPE_DEVICE_ORIENTATION "android.sensor.device_orientation"
Ashutosh Joshied021ea2016-01-14 22:28:24 -0800160#define SENSOR_STRING_TYPE_POSE_6DOF "android.sensor.pose_6dof"
Ashutosh Joshicb963312016-01-25 18:48:57 -0800161#define SENSOR_STRING_TYPE_STATIONARY_DETECT "android.sensor.stationary_detect"
Ashutosh Joshicb963312016-01-25 18:48:57 -0800162#define SENSOR_STRING_TYPE_MOTION_DETECT "android.sensor.motion_detect"
Ashutosh Joshicb963312016-01-25 18:48:57 -0800163#define SENSOR_STRING_TYPE_HEART_BEAT "android.sensor.heart_beat"
Peng Xue641ba92016-01-20 00:27:21 -0800164#define SENSOR_STRING_TYPE_DYNAMIC_SENSOR_META "android.sensor.dynamic_sensor_meta"
Peng Xu0743a5c2016-01-21 17:30:02 -0800165#define SENSOR_STRING_TYPE_ADDITIONAL_INFO "android.sensor.additional_info"
Nick Vaccarocfd950b2016-11-04 13:36:12 -0700166#define SENSOR_STRING_TYPE_LOW_LATENCY_OFFBODY_DETECT "android.sensor.low_latency_offbody"
Peng Xu0743a5c2016-01-21 17:30:02 -0800167
168/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800169 * Values returned by the accelerometer in various locations in the universe.
170 * all values are in SI units (m/s^2)
171 */
172#define GRAVITY_SUN (275.0f)
173#define GRAVITY_EARTH (9.80665f)
174
175/** Maximum magnetic field on Earth's surface */
176#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
177
178/** Minimum magnetic field on Earth's surface */
179#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
180
Peng Xue641ba92016-01-20 00:27:21 -0800181struct sensor_t;
182
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800183/**
184 * sensor event data
185 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800186typedef struct {
187 union {
188 float v[3];
189 struct {
190 float x;
191 float y;
192 float z;
193 };
194 struct {
195 float azimuth;
196 float pitch;
197 float roll;
198 };
199 };
200 int8_t status;
201 uint8_t reserved[3];
202} sensors_vec_t;
203
204/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800205 * uncalibrated gyroscope and magnetometer event data
206 */
207typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700208 union {
209 float uncalib[3];
210 struct {
211 float x_uncalib;
212 float y_uncalib;
213 float z_uncalib;
214 };
215 };
216 union {
217 float bias[3];
218 struct {
219 float x_bias;
220 float y_bias;
221 float z_bias;
222 };
223 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800224} uncalibrated_event_t;
225
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700226/**
227 * Meta data event data
228 */
Mathias Agopian16671c52013-07-24 21:07:40 -0700229typedef struct meta_data_event {
230 int32_t what;
231 int32_t sensor;
232} meta_data_event_t;
233
Etienne Le Grandca858142013-02-26 19:17:20 -0800234/**
Peng Xue641ba92016-01-20 00:27:21 -0800235 * Dynamic sensor meta event. See the description of SENSOR_TYPE_DYNAMIC_SENSOR_META type for
236 * details.
237 */
238typedef struct dynamic_sensor_meta_event {
Peng Xue20707a2016-01-27 18:26:10 -0800239 int32_t connected;
240 int32_t handle;
Peng Xue641ba92016-01-20 00:27:21 -0800241 const struct sensor_t * sensor; // should be NULL if connected == false
Peng Xu69b5dba2016-04-22 22:34:51 -0700242 uint8_t uuid[16]; // UUID of a dynamic sensor (using RFC 4122 byte order)
243 // For UUID 12345678-90AB-CDEF-1122-334455667788 the uuid field
244 // should be initialized as:
245 // {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x11, ...}
Peng Xue641ba92016-01-20 00:27:21 -0800246} dynamic_sensor_meta_event_t;
247
248/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700249 * Heart rate event data
250 */
251typedef struct {
252 // Heart rate in beats per minute.
253 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
254 float bpm;
255 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700256 // Note that this value should only be set for sensors that explicitly define
257 // the meaning of this field. This field is not piped through the framework
258 // for other sensors.
Etienne Le Grand7b361582014-05-16 11:08:28 -0700259 int8_t status;
260} heart_rate_event_t;
261
Peng Xu0743a5c2016-01-21 17:30:02 -0800262typedef struct {
263 int32_t type; // type of payload data, see additional_info_type_t
264 int32_t serial; // sequence number of this frame for this type
265 union {
266 // for each frame, a single data type, either int32_t or float, should be used.
267 int32_t data_int32[14];
268 float data_float[14];
269 };
270} additional_info_event_t;
271
Etienne Le Grand7b361582014-05-16 11:08:28 -0700272/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800273 * Union of the various types of sensor data
274 * that can be returned.
275 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700276typedef struct sensors_event_t {
277 /* must be sizeof(struct sensors_event_t) */
278 int32_t version;
279
280 /* sensor identifier */
281 int32_t sensor;
282
283 /* sensor type */
284 int32_t type;
285
286 /* reserved */
287 int32_t reserved0;
288
289 /* time is in nanosecond */
290 int64_t timestamp;
291
292 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700293 union {
294 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700295
Mathias Agopian27e16682013-07-08 14:00:54 -0700296 /* acceleration values are in meter per second per second (m/s^2) */
297 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700298
Mathias Agopian27e16682013-07-08 14:00:54 -0700299 /* magnetic vector values are in micro-Tesla (uT) */
300 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700301
Mathias Agopian27e16682013-07-08 14:00:54 -0700302 /* orientation values are in degrees */
303 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700304
Mathias Agopian27e16682013-07-08 14:00:54 -0700305 /* gyroscope values are in rad/s */
306 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700307
Mathias Agopian27e16682013-07-08 14:00:54 -0700308 /* temperature is in degrees centigrade (Celsius) */
309 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700310
Mathias Agopian27e16682013-07-08 14:00:54 -0700311 /* distance in centimeters */
312 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700313
Mathias Agopian27e16682013-07-08 14:00:54 -0700314 /* light in SI lux units */
315 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700316
Mathias Agopian27e16682013-07-08 14:00:54 -0700317 /* pressure in hectopascal (hPa) */
318 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100319
Mathias Agopian27e16682013-07-08 14:00:54 -0700320 /* relative humidity in percent */
321 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800322
Mathias Agopian27e16682013-07-08 14:00:54 -0700323 /* uncalibrated gyroscope values are in rad/s */
324 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800325
Mathias Agopian27e16682013-07-08 14:00:54 -0700326 /* uncalibrated magnetometer values are in micro-Teslas */
327 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700328
Etienne Le Grand7b361582014-05-16 11:08:28 -0700329 /* heart rate data containing value in bpm and status */
330 heart_rate_event_t heart_rate;
Aravind Akella477fbd52014-04-07 22:46:01 +0000331
Mathias Agopian16671c52013-07-24 21:07:40 -0700332 /* this is a special event. see SENSOR_TYPE_META_DATA above.
333 * sensors_meta_data_event_t events are all reported with a type of
334 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
335 */
336 meta_data_event_t meta_data;
Peng Xue641ba92016-01-20 00:27:21 -0800337
338 /* dynamic sensor meta event. See SENSOR_TYPE_DYNAMIC_SENSOR_META type for details */
339 dynamic_sensor_meta_event_t dynamic_sensor_meta;
Peng Xu0743a5c2016-01-21 17:30:02 -0800340
341 /*
342 * special additional sensor information frame, see
343 * SENSOR_TYPE_ADDITIONAL_INFO for details.
344 */
345 additional_info_event_t additional_info;
Mathias Agopian27e16682013-07-08 14:00:54 -0700346 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800347
Mathias Agopian27e16682013-07-08 14:00:54 -0700348 union {
349 uint64_t data[8];
350
351 /* step-counter */
352 uint64_t step_counter;
353 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700354 };
Aravind Akella6242f322014-02-28 18:46:19 -0800355
356 /* Reserved flags for internal use. Set to zero. */
357 uint32_t flags;
358
359 uint32_t reserved1[3];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700360} sensors_event_t;
361
362
Mathias Agopian16671c52013-07-24 21:07:40 -0700363/* see SENSOR_TYPE_META_DATA */
364typedef sensors_event_t sensors_meta_data_event_t;
365
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700366
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800367/**
368 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
369 * and the fields of this data structure must begin with hw_module_t
370 * followed by module specific information.
371 */
372struct sensors_module_t {
373 struct hw_module_t common;
374
375 /**
376 * Enumerate all available sensors. The list is returned in "list".
Colin Cross867e1e32016-10-06 16:44:46 -0700377 * return number of sensors in the list
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800378 */
379 int (*get_sensors_list)(struct sensors_module_t* module,
380 struct sensor_t const** list);
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700381
382 /**
383 * Place the module in a specific mode. The following modes are defined
384 *
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700385 * 0 - Normal operation. Default state of the module.
Peng Xu0743a5c2016-01-21 17:30:02 -0800386 * 1 - Loopback mode. Data is injected for the supported
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700387 * sensors by the sensor service in this mode.
Colin Cross867e1e32016-10-06 16:44:46 -0700388 * return 0 on success
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700389 * -EINVAL if requested mode is not supported
Aravind Akellac7f54132015-06-22 18:26:54 -0700390 * -EPERM if operation is not allowed
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700391 */
392 int (*set_operation_mode)(unsigned int mode);
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800393};
394
395struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800396
397 /* Name of this sensor.
398 * All sensors of the same "type" must have a different "name".
399 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800400 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800401
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800402 /* vendor of the hardware part */
403 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800404
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800405 /* version of the hardware part + driver. The value of this field
406 * must increase when the driver is updated in a way that changes the
407 * output of this sensor. This is important for fused sensors when the
408 * fusion algorithm is updated.
Aravind Akella6242f322014-02-28 18:46:19 -0800409 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800410 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800411
412 /* handle that identifies this sensors. This handle is used to reference
413 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800414 */
415 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800416
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800417 /* this sensor's type. */
418 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800419
420 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800421 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800422
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800423 /* smallest difference between two values reported by this sensor */
424 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800425
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800426 /* rough estimate of this sensor's power consumption in mA */
427 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800428
Aravind Akellac841efd2014-06-03 19:21:35 -0700429 /* this value depends on the reporting mode:
Mathias Agopiana4557722012-11-28 17:21:55 -0800430 *
431 * continuous: minimum sample period allowed in microseconds
432 * on-change : 0
433 * one-shot :-1
434 * special : 0, unless otherwise noted
435 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700436 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800437
Mathias Agopian16671c52013-07-24 21:07:40 -0700438 /* number of events reserved for this sensor in the batch mode FIFO.
439 * If there is a dedicated FIFO for this sensor, then this is the
440 * size of this FIFO. If the FIFO is shared with other sensors,
441 * this is the size reserved for that sensor and it can be zero.
442 */
443 uint32_t fifoReservedEventCount;
444
445 /* maximum number of events of this sensor that could be batched.
446 * This is especially relevant when the FIFO is shared between
447 * several sensors; this value is then set to the size of that FIFO.
448 */
449 uint32_t fifoMaxEventCount;
450
Aravind Akella477fbd52014-04-07 22:46:01 +0000451 /* type of this sensor as a string. Set to corresponding
452 * SENSOR_STRING_TYPE_*.
453 * When defining an OEM specific sensor or sensor manufacturer specific
454 * sensor, use your reserve domain name as a prefix.
455 * ex: com.google.glass.onheaddetector
456 * For sensors of known type, the android framework might overwrite this
457 * string automatically.
458 */
459 const char* stringType;
460
461 /* permission required to see this sensor, register to it and receive data.
462 * Set to "" if no permission is required. Some sensor types like the
463 * heart rate monitor have a mandatory require_permission.
464 * For sensors that always require a specific permission, like the heart
465 * rate monitor, the android framework might overwrite this string
466 * automatically.
467 */
468 const char* requiredPermission;
469
Aravind Akella110d2f22014-09-04 15:36:31 -0700470 /* This value is defined only for continuous mode and on-change sensors. It is the delay between
471 * two sensor events corresponding to the lowest frequency that this sensor supports. When lower
472 * frequencies are requested through batch()/setDelay() the events will be generated at this
473 * frequency instead. It can be used by the framework or applications to estimate when the batch
474 * FIFO may be full.
Aravind Akellac841efd2014-06-03 19:21:35 -0700475 *
476 * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
Aravind Akella110d2f22014-09-04 15:36:31 -0700477 * continuous, on-change: maximum sampling period allowed in microseconds.
478 * one-shot, special : 0
Aravind Akellac841efd2014-06-03 19:21:35 -0700479 * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit
480 * on 64 bit architectures only for binary compatibility reasons.
Aravind Akella6242f322014-02-28 18:46:19 -0800481 * Availability: SENSORS_DEVICE_API_VERSION_1_3
482 */
483 #ifdef __LP64__
484 int64_t maxDelay;
485 #else
486 int32_t maxDelay;
487 #endif
488
Aravind Akellac841efd2014-06-03 19:21:35 -0700489 /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.
490 * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.
491 * Availability: SENSORS_DEVICE_API_VERSION_1_3
492 */
Aravind Akella6242f322014-02-28 18:46:19 -0800493 #ifdef __LP64__
494 uint64_t flags;
495 #else
496 uint32_t flags;
497 #endif
498
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800499 /* reserved fields, must be zero */
Aravind Akella6242f322014-02-28 18:46:19 -0800500 void* reserved[2];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800501};
502
503
Mathias Agopiana4557722012-11-28 17:21:55 -0800504/*
505 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
506 * and is present for backward binary and source compatibility.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800507 * See the Sensors HAL interface section for complete descriptions of the
508 * following functions:
509 * http://source.android.com/devices/sensors/index.html#hal
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800510 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700511struct sensors_poll_device_t {
512 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700513 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700514 int sensor_handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700515 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700516 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700517 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700518 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700519};
520
Mathias Agopiana4557722012-11-28 17:21:55 -0800521/*
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700522 * struct sensors_poll_device_1 is used in HAL versions >= SENSORS_DEVICE_API_VERSION_1_0
Mathias Agopiana4557722012-11-28 17:21:55 -0800523 */
524typedef struct sensors_poll_device_1 {
525 union {
526 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
527 * and can be down-cast to it
528 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800529 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -0800530
531 struct {
532 struct hw_device_t common;
533
Peng Xuaaeeaa42016-10-05 14:56:54 -0700534 /* Activate/de-activate one sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800535 *
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700536 * sensor_handle is the handle of the sensor to change.
Mathias Agopiana4557722012-11-28 17:21:55 -0800537 * enabled set to 1 to enable, or 0 to disable the sensor.
538 *
Peng Xuaaeeaa42016-10-05 14:56:54 -0700539 * After sensor de-activation, existing sensor events that have not
540 * been picked up by poll() should be abandoned immediately so that
541 * subsequent activation will not get stale sensor events (events
542 * that is generated prior to the latter activation).
543 *
Clay Murphy8db1fb42013-12-19 09:58:28 -0800544 * Return 0 on success, negative errno code otherwise.
Mathias Agopiana4557722012-11-28 17:21:55 -0800545 */
546 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700547 int sensor_handle, int enabled);
Mathias Agopiana4557722012-11-28 17:21:55 -0800548
549 /**
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700550 * Set the events's period in nanoseconds for a given sensor.
551 * If sampling_period_ns > max_delay it will be truncated to
552 * max_delay and if sampling_period_ns < min_delay it will be
553 * replaced by min_delay.
Mathias Agopiana4557722012-11-28 17:21:55 -0800554 */
555 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700556 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -0800557
558 /**
Peng Xu355e3f62016-07-19 15:11:53 -0700559 * Write an array of sensor_event_t to data. The size of the
560 * available buffer is specified by count. Returns number of
561 * valid sensor_event_t.
562 *
563 * This function should block if there is no sensor event
564 * available when being called. Thus, return value should always be
565 * positive.
Mathias Agopiana4557722012-11-28 17:21:55 -0800566 */
567 int (*poll)(struct sensors_poll_device_t *dev,
568 sensors_event_t* data, int count);
569 };
570 };
571
Mathias Agopiana4557722012-11-28 17:21:55 -0800572
573 /*
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700574 * Sets a sensor’s parameters, including sampling frequency and maximum
575 * report latency. This function can be called while the sensor is
576 * activated, in which case it must not cause any sensor measurements to
577 * be lost: transitioning from one sampling rate to the other cannot cause
578 * lost events, nor can transitioning from a high maximum report latency to
579 * a low maximum report latency.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800580 * See the Batching sensor results page for details:
581 * http://source.android.com/devices/sensors/batching.html
Mathias Agopiana4557722012-11-28 17:21:55 -0800582 */
583 int (*batch)(struct sensors_poll_device_1* dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700584 int sensor_handle, int flags, int64_t sampling_period_ns,
585 int64_t max_report_latency_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -0800586
Mathias Agopian16671c52013-07-24 21:07:40 -0700587 /*
588 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
589 * to the end of the "batch mode" FIFO for the specified sensor and flushes
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700590 * the FIFO.
591 * If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero),
Aravind Akellac841efd2014-06-03 19:21:35 -0700592 * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700593 * event stream. This applies to all sensors other than one-shot sensors.
594 * If the sensor is a one-shot sensor, flush must return -EINVAL and not generate
595 * any flush complete metadata.
Aravind Akellaa7f2cda2014-08-21 16:31:14 -0700596 * If the sensor is not active at the time flush() is called, flush() should return
597 * -EINVAL.
Mathias Agopian16671c52013-07-24 21:07:40 -0700598 */
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700599 int (*flush)(struct sensors_poll_device_1* dev, int sensor_handle);
Mathias Agopian16671c52013-07-24 21:07:40 -0700600
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700601 /*
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700602 * Inject a single sensor sample to be to this device.
603 * data points to the sensor event to be injected
Colin Cross867e1e32016-10-06 16:44:46 -0700604 * return 0 on success
Aravind Akellac7f54132015-06-22 18:26:54 -0700605 * -EPERM if operation is not allowed
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700606 * -EINVAL if sensor event cannot be injected
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700607 */
608 int (*inject_sensor_data)(struct sensors_poll_device_1 *dev, const sensors_event_t *data);
609
610 void (*reserved_procs[7])(void);
Mathias Agopiana4557722012-11-28 17:21:55 -0800611
612} sensors_poll_device_1_t;
613
614
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800615/** convenience API for opening and closing a device */
616
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700617static inline int sensors_open(const struct hw_module_t* module,
618 struct sensors_poll_device_t** device) {
619 return module->methods->open(module,
Colin Crosscc8d9f92016-10-06 16:44:23 -0700620 SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device));
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700621}
622
623static inline int sensors_close(struct sensors_poll_device_t* device) {
624 return device->common.close(&device->common);
625}
626
Mathias Agopiana4557722012-11-28 17:21:55 -0800627static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800628 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -0800629 return module->methods->open(module,
Colin Crosscc8d9f92016-10-06 16:44:23 -0700630 SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device));
Mathias Agopiana4557722012-11-28 17:21:55 -0800631}
632
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800633static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -0800634 return device->common.close(&device->common);
635}
636
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800637__END_DECLS
638
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800639#endif // ANDROID_SENSORS_INTERFACE_H