blob: a618393e66c1b7ffc14908931fbefc3a48a1c556 [file] [log] [blame]
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
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
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070017/**
Leon Scroggins III4883c522020-01-30 15:10:11 -050018 * Structures and functions to receive and process sensor events in
19 * native code.
20 *
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070021 * @addtogroup Sensor
22 * @{
23 */
24
25/**
26 * @file sensor.h
27 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070028
29#ifndef ANDROID_SENSOR_H
30#define ANDROID_SENSOR_H
31
Prashanth Swaminathan8b75d502023-07-11 10:48:18 -070032#include <sys/cdefs.h>
33
Mathias Agopiane1c61d32012-03-23 14:19:36 -070034/******************************************************************
35 *
36 * IMPORTANT NOTICE:
37 *
38 * This file is part of Android's set of stable system headers
39 * exposed by the Android NDK (Native Development Kit).
40 *
41 * Third-party source AND binary code relies on the definitions
42 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
43 *
44 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
45 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
46 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
47 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
48 */
49
Mathias Agopiane1c61d32012-03-23 14:19:36 -070050#include <android/looper.h>
51
Dan Albert8f860fd2017-04-25 12:24:28 -070052#include <stdbool.h>
Peng Xuda8385c2017-02-28 20:19:47 -080053#include <sys/types.h>
54#include <math.h>
55#include <stdint.h>
56
Prashanth Swaminathan8b75d502023-07-11 10:48:18 -070057// This file may also be built on glibc or on Windows/MacOS libc's, so no-op
58// and deprecated definitions are provided.
Elliott Hughes23e82b42021-01-26 14:55:48 -080059#if !defined(__INTRODUCED_IN)
60#define __INTRODUCED_IN(__api_level) /* nothing */
61#endif
62#if !defined(__DEPRECATED_IN)
63#define __DEPRECATED_IN(__api_level) __attribute__((__deprecated__))
64#endif
65
Mathias Agopiane1c61d32012-03-23 14:19:36 -070066#ifdef __cplusplus
67extern "C" {
68#endif
69
Peng Xu47cddca2017-02-15 23:31:22 -080070typedef struct AHardwareBuffer AHardwareBuffer;
Mathias Agopiane1c61d32012-03-23 14:19:36 -070071
Peng Xuda8385c2017-02-28 20:19:47 -080072#define ASENSOR_RESOLUTION_INVALID (nanf(""))
73#define ASENSOR_FIFO_COUNT_INVALID (-1)
74#define ASENSOR_DELAY_INVALID INT32_MIN
Brian Stack8228fa72019-01-04 14:15:13 -080075#define ASENSOR_INVALID (-1)
Peng Xuda8385c2017-02-28 20:19:47 -080076
Elliott Hughesf78be362018-01-23 15:33:56 -080077/* (Keep in sync with hardware/sensors-base.h and Sensor.java.) */
78
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070079/**
80 * Sensor types.
Elliott Hughesf78be362018-01-23 15:33:56 -080081 *
82 * See
83 * [android.hardware.SensorEvent#values](https://developer.android.com/reference/android/hardware/SensorEvent.html#values)
84 * for detailed explanations of the data returned for each of these types.
Mathias Agopiane1c61d32012-03-23 14:19:36 -070085 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070086enum {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070087 /**
Peng Xu37317b62017-03-07 17:49:31 -080088 * Invalid sensor type. Returned by {@link ASensor_getType} as error value.
89 */
90 ASENSOR_TYPE_INVALID = -1,
91 /**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070092 * {@link ASENSOR_TYPE_ACCELEROMETER}
93 * reporting-mode: continuous
94 *
95 * All values are in SI units (m/s^2) and measure the acceleration of the
96 * device minus the force of gravity.
97 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -070098 ASENSOR_TYPE_ACCELEROMETER = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070099 /**
100 * {@link ASENSOR_TYPE_MAGNETIC_FIELD}
101 * reporting-mode: continuous
102 *
103 * All values are in micro-Tesla (uT) and measure the geomagnetic
104 * field in the X, Y and Z axis.
105 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700106 ASENSOR_TYPE_MAGNETIC_FIELD = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700107 /**
108 * {@link ASENSOR_TYPE_GYROSCOPE}
109 * reporting-mode: continuous
110 *
111 * All values are in radians/second and measure the rate of rotation
112 * around the X, Y and Z axis.
113 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700114 ASENSOR_TYPE_GYROSCOPE = 4,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700115 /**
116 * {@link ASENSOR_TYPE_LIGHT}
117 * reporting-mode: on-change
118 *
119 * The light sensor value is returned in SI lux units.
120 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700121 ASENSOR_TYPE_LIGHT = 5,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700122 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800123 * {@link ASENSOR_TYPE_PRESSURE}
124 *
125 * The pressure sensor value is returned in hPa (millibar).
126 */
127 ASENSOR_TYPE_PRESSURE = 6,
128 /**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700129 * {@link ASENSOR_TYPE_PROXIMITY}
130 * reporting-mode: on-change
131 *
132 * The proximity sensor which turns the screen off and back on during calls is the
133 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
134 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
135 * SENSOR_FLAG_WAKE_UP.
136 * The value corresponds to the distance to the nearest object in centimeters.
137 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700138 ASENSOR_TYPE_PROXIMITY = 8,
139 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800140 * {@link ASENSOR_TYPE_GRAVITY}
141 *
142 * All values are in SI units (m/s^2) and measure the direction and
143 * magnitude of gravity. When the device is at rest, the output of
144 * the gravity sensor should be identical to that of the accelerometer.
145 */
146 ASENSOR_TYPE_GRAVITY = 9,
147 /**
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700148 * {@link ASENSOR_TYPE_LINEAR_ACCELERATION}
149 * reporting-mode: continuous
150 *
151 * All values are in SI units (m/s^2) and measure the acceleration of the
152 * device not including the force of gravity.
153 */
Elliott Hughesf78be362018-01-23 15:33:56 -0800154 ASENSOR_TYPE_LINEAR_ACCELERATION = 10,
155 /**
156 * {@link ASENSOR_TYPE_ROTATION_VECTOR}
157 */
158 ASENSOR_TYPE_ROTATION_VECTOR = 11,
159 /**
160 * {@link ASENSOR_TYPE_RELATIVE_HUMIDITY}
161 *
162 * The relative humidity sensor value is returned in percent.
163 */
164 ASENSOR_TYPE_RELATIVE_HUMIDITY = 12,
165 /**
166 * {@link ASENSOR_TYPE_AMBIENT_TEMPERATURE}
167 *
168 * The ambient temperature sensor value is returned in Celcius.
169 */
170 ASENSOR_TYPE_AMBIENT_TEMPERATURE = 13,
171 /**
172 * {@link ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED}
173 */
174 ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14,
175 /**
176 * {@link ASENSOR_TYPE_GAME_ROTATION_VECTOR}
177 */
178 ASENSOR_TYPE_GAME_ROTATION_VECTOR = 15,
179 /**
180 * {@link ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED}
181 */
182 ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 16,
183 /**
184 * {@link ASENSOR_TYPE_SIGNIFICANT_MOTION}
185 */
186 ASENSOR_TYPE_SIGNIFICANT_MOTION = 17,
187 /**
188 * {@link ASENSOR_TYPE_STEP_DETECTOR}
189 */
190 ASENSOR_TYPE_STEP_DETECTOR = 18,
191 /**
192 * {@link ASENSOR_TYPE_STEP_COUNTER}
193 */
194 ASENSOR_TYPE_STEP_COUNTER = 19,
195 /**
196 * {@link ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR}
197 */
198 ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20,
199 /**
200 * {@link ASENSOR_TYPE_HEART_RATE}
201 */
202 ASENSOR_TYPE_HEART_RATE = 21,
203 /**
204 * {@link ASENSOR_TYPE_POSE_6DOF}
205 */
206 ASENSOR_TYPE_POSE_6DOF = 28,
207 /**
208 * {@link ASENSOR_TYPE_STATIONARY_DETECT}
209 */
210 ASENSOR_TYPE_STATIONARY_DETECT = 29,
211 /**
212 * {@link ASENSOR_TYPE_MOTION_DETECT}
213 */
214 ASENSOR_TYPE_MOTION_DETECT = 30,
215 /**
216 * {@link ASENSOR_TYPE_HEART_BEAT}
217 */
218 ASENSOR_TYPE_HEART_BEAT = 31,
219 /**
Erik Staatsb1f77952022-03-25 11:49:58 -0700220 * A constant describing a dynamic sensor meta event sensor.
221 *
222 * A sensor event of this type is received when a dynamic sensor is added to or removed from
223 * the system. This sensor type should always use special trigger report mode.
224 */
225 ASENSOR_TYPE_DYNAMIC_SENSOR_META = 32,
226 /**
Brian Stackccd88432019-01-08 17:04:18 -0800227 * This sensor type is for delivering additional sensor information aside
228 * from sensor event data.
229 *
230 * Additional information may include:
231 * - {@link ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE}
232 * - {@link ASENSOR_ADDITIONAL_INFO_SAMPLING}
233 * - {@link ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT}
234 * - {@link ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY}
235 * - {@link ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION}
236 *
237 * This type will never bind to a sensor. In other words, no sensor in the
238 * sensor list can have the type {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
239 *
240 * If a device supports the sensor additional information feature, it will
241 * report additional information events via {@link ASensorEvent} and will
gfanc150ea12021-04-14 09:27:55 -0700242 * have the type of {@link ASensorEvent} set to
243 * {@link ASENSOR_TYPE_ADDITIONAL_INFO} and the sensor of {@link ASensorEvent} set
Brian Stackccd88432019-01-08 17:04:18 -0800244 * to the handle of the reporting sensor.
245 *
246 * Additional information reports consist of multiple frames ordered by
247 * {@link ASensorEvent#timestamp}. The first frame in the report will have
248 * a {@link AAdditionalInfoEvent#type} of
249 * {@link ASENSOR_ADDITIONAL_INFO_BEGIN}, and the last frame in the report
250 * will have a {@link AAdditionalInfoEvent#type} of
251 * {@link ASENSOR_ADDITIONAL_INFO_END}.
252 *
253 */
254 ASENSOR_TYPE_ADDITIONAL_INFO = 33,
255 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800256 * {@link ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT}
257 */
258 ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT = 34,
259 /**
260 * {@link ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED}
261 */
262 ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35,
Anthony Stangefdb1fc82020-01-16 15:02:48 -0500263 /**
264 * {@link ASENSOR_TYPE_HINGE_ANGLE}
Anthony Stanged7a703c2020-02-18 12:02:22 -0500265 * reporting-mode: on-change
266 *
267 * The hinge angle sensor value is returned in degrees.
Anthony Stangefdb1fc82020-01-16 15:02:48 -0500268 */
269 ASENSOR_TYPE_HINGE_ANGLE = 36,
Brian Duddie573da3b2021-12-10 14:34:07 -0800270 /**
271 * {@link ASENSOR_TYPE_HEAD_TRACKER}
272 * reporting-mode: continuous
273 *
Brian Duddie4a4d0462022-05-09 16:49:49 -0700274 * Measures the orientation and rotational velocity of a user's head. Only for internal use
275 * within the Android system.
Brian Duddie573da3b2021-12-10 14:34:07 -0800276 */
277 ASENSOR_TYPE_HEAD_TRACKER = 37,
Eva Chenc0420b72021-04-09 15:44:12 -0700278 /**
279 * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES}
280 * reporting-mode: continuous
281 *
282 * The first three values are in SI units (m/s^2) and measure the acceleration of the device
283 * minus the force of gravity. The last three values indicate which acceleration axes are
284 * supported. A value of 1.0 means supported and a value of 0 means not supported.
285 */
286 ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES = 38,
287 /**
288 * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES}
289 * reporting-mode: continuous
290 *
291 * The first three values are in radians/second and measure the rate of rotation around the X,
292 * Y and Z axis. The last three values indicate which rotation axes are supported. A value of
293 * 1.0 means supported and a value of 0 means not supported.
294 */
295 ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES = 39,
296 /**
297 * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED}
298 * reporting-mode: continuous
299 *
300 * The first three values are in SI units (m/s^2) and measure the acceleration of the device
301 * minus the force of gravity. The middle three values represent the estimated bias for each
302 * axis. The last three values indicate which acceleration axes are supported. A value of 1.0
303 * means supported and a value of 0 means not supported.
304 */
305 ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED = 40,
306 /**
307 * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED}
308 * reporting-mode: continuous
309 *
310 * The first three values are in radians/second and measure the rate of rotation around the X,
311 * Y and Z axis. The middle three values represent the estimated drift around each axis in
312 * rad/s. The last three values indicate which rotation axes are supported. A value of 1.0 means
313 * supported and a value of 0 means not supported.
314 */
315 ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED = 41,
Eva Chen72c71042022-01-10 21:07:51 -0800316 /**
317 * {@link ASENSOR_TYPE_HEADING}
318 * reporting-mode: continuous
319 *
320 * A heading sensor measures the direction in which the device is pointing
321 * relative to true north in degrees.
322 */
323 ASENSOR_TYPE_HEADING = 42,
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700324};
325
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700326/**
327 * Sensor accuracy measure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700328 */
329enum {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700330 /** no contact */
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700331 ASENSOR_STATUS_NO_CONTACT = -1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700332 /** unreliable */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700333 ASENSOR_STATUS_UNRELIABLE = 0,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700334 /** low accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700335 ASENSOR_STATUS_ACCURACY_LOW = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700336 /** medium accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700337 ASENSOR_STATUS_ACCURACY_MEDIUM = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700338 /** high accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700339 ASENSOR_STATUS_ACCURACY_HIGH = 3
340};
341
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700342/**
Aravind Akella0e025c52014-06-03 19:19:57 -0700343 * Sensor Reporting Modes.
344 */
345enum {
Peng Xu37317b62017-03-07 17:49:31 -0800346 /** invalid reporting mode */
347 AREPORTING_MODE_INVALID = -1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700348 /** continuous reporting */
Aravind Akella0e025c52014-06-03 19:19:57 -0700349 AREPORTING_MODE_CONTINUOUS = 0,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700350 /** reporting on change */
Aravind Akella0e025c52014-06-03 19:19:57 -0700351 AREPORTING_MODE_ON_CHANGE = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700352 /** on shot reporting */
Aravind Akella0e025c52014-06-03 19:19:57 -0700353 AREPORTING_MODE_ONE_SHOT = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700354 /** special trigger reporting */
Peng Xu37317b62017-03-07 17:49:31 -0800355 AREPORTING_MODE_SPECIAL_TRIGGER = 3
Aravind Akella0e025c52014-06-03 19:19:57 -0700356};
357
Peng Xu47cddca2017-02-15 23:31:22 -0800358/**
359 * Sensor Direct Report Rates.
360 */
361enum {
362 /** stopped */
363 ASENSOR_DIRECT_RATE_STOP = 0,
364 /** nominal 50Hz */
365 ASENSOR_DIRECT_RATE_NORMAL = 1,
366 /** nominal 200Hz */
367 ASENSOR_DIRECT_RATE_FAST = 2,
368 /** nominal 800Hz */
369 ASENSOR_DIRECT_RATE_VERY_FAST = 3
370};
371
372/**
373 * Sensor Direct Channel Type.
374 */
375enum {
376 /** shared memory created by ASharedMemory_create */
377 ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1,
378 /** AHardwareBuffer */
379 ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2
380};
381
Brian Stackccd88432019-01-08 17:04:18 -0800382/**
383 * Sensor Additional Info Types.
384 *
385 * Used to populate {@link AAdditionalInfoEvent#type}.
386 */
387enum {
388 /** Marks the beginning of additional information frames */
389 ASENSOR_ADDITIONAL_INFO_BEGIN = 0,
390
391 /** Marks the end of additional information frames */
392 ASENSOR_ADDITIONAL_INFO_END = 1,
393
394 /**
395 * Estimation of the delay that is not tracked by sensor timestamps. This
396 * includes delay introduced by sensor front-end filtering, data transport,
397 * etc.
398 * float[2]: delay in seconds, standard deviation of estimated value
399 */
400 ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY = 0x10000,
401
402 /** float: Celsius temperature */
403 ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE,
404
405 /**
406 * First three rows of a homogeneous matrix, which represents calibration to
407 * a three-element vector raw sensor reading.
408 * float[12]: 3x4 matrix in row major order
409 */
410 ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION,
411
412 /**
413 * Location and orientation of sensor element in the device frame: origin is
414 * the geometric center of the mobile device screen surface; the axis
415 * definition corresponds to Android sensor definitions.
416 * float[12]: 3x4 matrix in row major order
417 */
418 ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT,
419
420 /**
421 * float[2]: raw sample period in seconds,
422 * standard deviation of sampling period
423 */
424 ASENSOR_ADDITIONAL_INFO_SAMPLING,
425};
426
Aravind Akella0e025c52014-06-03 19:19:57 -0700427/*
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700428 * A few useful constants
429 */
430
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700431/** Earth's gravity in m/s^2 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700432#define ASENSOR_STANDARD_GRAVITY (9.80665f)
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700433/** Maximum magnetic field on Earth's surface in uT */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700434#define ASENSOR_MAGNETIC_FIELD_EARTH_MAX (60.0f)
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700435/** Minimum magnetic field on Earth's surface in uT*/
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700436#define ASENSOR_MAGNETIC_FIELD_EARTH_MIN (30.0f)
437
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700438/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700439 * A sensor event.
440 */
441
Peng Xu70b98382017-08-07 14:09:11 -0700442/* NOTE: changes to these structs have to be backward compatible */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700443typedef struct ASensorVector {
444 union {
445 float v[3];
446 struct {
447 float x;
448 float y;
449 float z;
450 };
451 struct {
452 float azimuth;
453 float pitch;
454 float roll;
455 };
456 };
457 int8_t status;
458 uint8_t reserved[3];
459} ASensorVector;
460
Aravind Akella724d91d2013-06-27 12:04:23 -0700461typedef struct AMetaDataEvent {
462 int32_t what;
463 int32_t sensor;
464} AMetaDataEvent;
465
466typedef struct AUncalibratedEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800467 union {
468 float uncalib[3];
469 struct {
470 float x_uncalib;
471 float y_uncalib;
472 float z_uncalib;
473 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700474 };
Peng Xu9e720462016-01-26 18:48:54 -0800475 union {
476 float bias[3];
477 struct {
478 float x_bias;
479 float y_bias;
480 float z_bias;
481 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700482 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700483} AUncalibratedEvent;
484
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700485typedef struct AHeartRateEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800486 float bpm;
487 int8_t status;
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700488} AHeartRateEvent;
489
Peng Xu2576cb62016-01-20 00:22:09 -0800490typedef struct ADynamicSensorEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800491 int32_t connected;
492 int32_t handle;
Peng Xu2576cb62016-01-20 00:22:09 -0800493} ADynamicSensorEvent;
494
Brian Stackccd88432019-01-08 17:04:18 -0800495typedef struct AAdditionalInfoEvent {
gfan5d5faa42021-04-12 15:14:29 -0700496 /**
497 * Event type, such as ASENSOR_ADDITIONAL_INFO_BEGIN, ASENSOR_ADDITIONAL_INFO_END and others.
498 * Refer to {@link ASENSOR_TYPE_ADDITIONAL_INFO} for the expected reporting behavior.
499 */
Peng Xu9e720462016-01-26 18:48:54 -0800500 int32_t type;
501 int32_t serial;
502 union {
503 int32_t data_int32[14];
504 float data_float[14];
505 };
506} AAdditionalInfoEvent;
507
Brian Duddie573da3b2021-12-10 14:34:07 -0800508typedef struct AHeadTrackerEvent {
509 /**
510 * The fields rx, ry, rz are an Euler vector (rotation vector, i.e. a vector
511 * whose direction indicates the axis of rotation and magnitude indicates
512 * the angle to rotate around that axis) representing the transform from
513 * the (arbitrary, possibly slowly drifting) reference frame to the
514 * head frame. Expressed in radians. Magnitude of the vector must be
515 * in the range [0, pi], while the value of individual axes are
516 * in the range [-pi, pi].
517 */
518 float rx;
519 float ry;
520 float rz;
521
522 /**
523 * The fields vx, vy, vz are an Euler vector (rotation vector) representing
524 * the angular velocity of the head (relative to itself), in radians per
525 * second. The direction of this vector indicates the axis of rotation, and
526 * the magnitude indicates the rate of rotation.
527 */
528 float vx;
529 float vy;
530 float vz;
531
532 /**
533 * This value changes each time the reference frame is suddenly and
534 * significantly changed, for example if an orientation filter algorithm
535 * used for determining the orientation has had its state reset.
536 */
537 int32_t discontinuity_count;
538} AHeadTrackerEvent;
539
Eva Chenc0420b72021-04-09 15:44:12 -0700540typedef struct ALimitedAxesImuEvent {
541 union {
542 float calib[3];
543 struct {
544 float x;
545 float y;
546 float z;
547 };
548 };
549 union {
550 float supported[3];
551 struct {
552 float x_supported;
553 float y_supported;
554 float z_supported;
555 };
556 };
557} ALimitedAxesImuEvent;
558
559typedef struct ALimitedAxesImuUncalibratedEvent {
560 union {
561 float uncalib[3];
562 struct {
563 float x_uncalib;
564 float y_uncalib;
565 float z_uncalib;
566 };
567 };
568 union {
569 float bias[3];
570 struct {
571 float x_bias;
572 float y_bias;
573 float z_bias;
574 };
575 };
576 union {
577 float supported[3];
578 struct {
579 float x_supported;
580 float y_supported;
581 float z_supported;
582 };
583 };
584} ALimitedAxesImuUncalibratedEvent;
585
Eva Chen72c71042022-01-10 21:07:51 -0800586typedef struct AHeadingEvent {
587 /**
588 * The direction in which the device is pointing relative to true north in
589 * degrees. The value must be between 0.0 (inclusive) and 360.0 (exclusive),
590 * with 0 indicating north, 90 east, 180 south, and 270 west.
591 */
592 float heading;
593 /**
594 * Accuracy is defined at 68% confidence. In the case where the underlying
595 * distribution is assumed Gaussian normal, this would be considered one
596 * standard deviation. For example, if the heading returns 60 degrees, and
597 * accuracy returns 10 degrees, then there is a 68 percent probability of
598 * the true heading being between 50 degrees and 70 degrees.
599 */
600 float accuracy;
601} AHeadingEvent;
602
Devin Moored0470682022-11-29 19:12:55 +0000603// LINT.IfChange
gfan5d5faa42021-04-12 15:14:29 -0700604/**
605 * Information that describes a sensor event, refer to
606 * <a href="/reference/android/hardware/SensorEvent">SensorEvent</a> for additional
607 * documentation.
Devin Moored0470682022-11-29 19:12:55 +0000608 *
609 * NOTE: changes to this struct has to be backward compatible and reflected in
610 * sensors_event_t
gfan5d5faa42021-04-12 15:14:29 -0700611 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700612typedef struct ASensorEvent {
Brian Duddie2c5692b2023-05-18 15:04:32 -0700613 /* sizeof(struct ASensorEvent) */
614 int32_t version;
615 /** The sensor that generates this event */
616 int32_t sensor;
617 /** Sensor type for the event, such as {@link ASENSOR_TYPE_ACCELEROMETER} */
618 int32_t type;
619 /** do not use */
620 int32_t reserved0;
gfan5d5faa42021-04-12 15:14:29 -0700621 /**
622 * The time in nanoseconds at which the event happened, and its behavior
623 * is identical to <a href="/reference/android/hardware/SensorEvent#timestamp">
624 * SensorEvent::timestamp</a> in Java API.
625 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700626 int64_t timestamp;
627 union {
Mathias Agopianba02cd22013-07-03 16:20:57 -0700628 union {
629 float data[16];
630 ASensorVector vector;
631 ASensorVector acceleration;
Brian Duddiee02c0662021-03-16 09:53:20 -0700632 ASensorVector gyro;
Mathias Agopianba02cd22013-07-03 16:20:57 -0700633 ASensorVector magnetic;
634 float temperature;
635 float distance;
636 float light;
637 float pressure;
Aravind Akella724d91d2013-06-27 12:04:23 -0700638 float relative_humidity;
Brian Duddiee02c0662021-03-16 09:53:20 -0700639 AUncalibratedEvent uncalibrated_acceleration;
Aravind Akella724d91d2013-06-27 12:04:23 -0700640 AUncalibratedEvent uncalibrated_gyro;
641 AUncalibratedEvent uncalibrated_magnetic;
642 AMetaDataEvent meta_data;
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700643 AHeartRateEvent heart_rate;
Peng Xu2576cb62016-01-20 00:22:09 -0800644 ADynamicSensorEvent dynamic_sensor_meta;
Peng Xu9e720462016-01-26 18:48:54 -0800645 AAdditionalInfoEvent additional_info;
Brian Duddie573da3b2021-12-10 14:34:07 -0800646 AHeadTrackerEvent head_tracker;
Eva Chenc0420b72021-04-09 15:44:12 -0700647 ALimitedAxesImuEvent limited_axes_imu;
648 ALimitedAxesImuUncalibratedEvent limited_axes_imu_uncalibrated;
Eva Chen72c71042022-01-10 21:07:51 -0800649 AHeadingEvent heading;
Mathias Agopianba02cd22013-07-03 16:20:57 -0700650 };
651 union {
652 uint64_t data[8];
653 uint64_t step_counter;
654 } u64;
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700655 };
Aravind Akella9a844cf2014-02-11 18:58:52 -0800656
657 uint32_t flags;
658 int32_t reserved1[3];
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700659} ASensorEvent;
Prashanth Swaminathan0fa7cbb2023-07-11 10:53:21 -0700660// LINT.ThenChange(hardware/libhardware/include/hardware/sensors.h)
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700661
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700662struct ASensorManager;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700663/**
664 * {@link ASensorManager} is an opaque type to manage sensors and
665 * events queues.
666 *
667 * {@link ASensorManager} is a singleton that can be obtained using
668 * ASensorManager_getInstance().
669 *
670 * This file provides a set of functions that uses {@link
671 * ASensorManager} to access and list hardware sensors, and
672 * create and destroy event queues:
673 * - ASensorManager_getSensorList()
674 * - ASensorManager_getDefaultSensor()
675 * - ASensorManager_getDefaultSensorEx()
676 * - ASensorManager_createEventQueue()
677 * - ASensorManager_destroyEventQueue()
678 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700679typedef struct ASensorManager ASensorManager;
680
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700681
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700682struct ASensorEventQueue;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700683/**
684 * {@link ASensorEventQueue} is an opaque type that provides access to
685 * {@link ASensorEvent} from hardware sensors.
686 *
687 * A new {@link ASensorEventQueue} can be obtained using ASensorManager_createEventQueue().
688 *
689 * This file provides a set of functions to enable and disable
690 * sensors, check and get events, and set event rates on a {@link
691 * ASensorEventQueue}.
692 * - ASensorEventQueue_enableSensor()
693 * - ASensorEventQueue_disableSensor()
694 * - ASensorEventQueue_hasEvents()
695 * - ASensorEventQueue_getEvents()
696 * - ASensorEventQueue_setEventRate()
Brian Stack65089d52019-01-11 10:52:07 -0800697 * - ASensorEventQueue_requestAdditionalInfoEvents()
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700698 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700699typedef struct ASensorEventQueue ASensorEventQueue;
700
701struct ASensor;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700702/**
703 * {@link ASensor} is an opaque type that provides information about
704 * an hardware sensors.
705 *
706 * A {@link ASensor} pointer can be obtained using
707 * ASensorManager_getDefaultSensor(),
708 * ASensorManager_getDefaultSensorEx() or from a {@link ASensorList}.
709 *
710 * This file provides a set of functions to access properties of a
711 * {@link ASensor}:
712 * - ASensor_getName()
713 * - ASensor_getVendor()
714 * - ASensor_getType()
715 * - ASensor_getResolution()
716 * - ASensor_getMinDelay()
717 * - ASensor_getFifoMaxEventCount()
718 * - ASensor_getFifoReservedEventCount()
719 * - ASensor_getStringType()
720 * - ASensor_getReportingMode()
721 * - ASensor_isWakeUpSensor()
Brian Stack8228fa72019-01-04 14:15:13 -0800722 * - ASensor_getHandle()
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700723 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700724typedef struct ASensor ASensor;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700725/**
726 * {@link ASensorRef} is a type for constant pointers to {@link ASensor}.
727 *
728 * This is used to define entry in {@link ASensorList} arrays.
729 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700730typedef ASensor const* ASensorRef;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700731/**
732 * {@link ASensorList} is an array of reference to {@link ASensor}.
733 *
734 * A {@link ASensorList} can be initialized using ASensorManager_getSensorList().
735 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700736typedef ASensorRef const* ASensorList;
737
738/*****************************************************************************/
739
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700740/**
Svet Ganov5fa32d42015-05-07 10:50:59 -0700741 * Get a reference to the sensor manager. ASensorManager is a singleton
742 * per package as different packages may have access to different sensors.
743 *
744 * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead.
745 *
746 * Example:
747 *
748 * ASensorManager* sensorManager = ASensorManager_getInstance();
749 *
750 */
Elliott Hughes23e82b42021-01-26 14:55:48 -0800751ASensorManager* ASensorManager_getInstance() __DEPRECATED_IN(26);
Svet Ganov5fa32d42015-05-07 10:50:59 -0700752
Peng Xu80df0162017-08-05 19:00:23 -0700753/**
Svet Ganov5fa32d42015-05-07 10:50:59 -0700754 * Get a reference to the sensor manager. ASensorManager is a singleton
755 * per package as different packages may have access to different sensors.
756 *
757 * Example:
758 *
Peng Xu80df0162017-08-05 19:00:23 -0700759 * ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz");
Svet Ganov5fa32d42015-05-07 10:50:59 -0700760 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700761 * Available since API level 26.
Svet Ganov5fa32d42015-05-07 10:50:59 -0700762 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700763ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26);
Svet Ganov5fa32d42015-05-07 10:50:59 -0700764
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700765/**
Erik Staatsd35a5742022-02-04 06:37:58 -0800766 * Returns the list of available sensors. The returned list is owned by the
767 * sensor manager and will not change between calls to this function.
768 *
769 * \param manager the {@link ASensorManager} instance obtained from
770 * {@link ASensorManager_getInstanceForPackage}.
771 * \param list the returned list of sensors.
772 * \return positive number of returned sensors or negative error code.
773 * BAD_VALUE: manager is NULL.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700774 */
775int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list);
776
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700777/**
Erik Staatsd35a5742022-02-04 06:37:58 -0800778 * Returns the list of available dynamic sensors. If there are no dynamic
779 * sensors available, returns nullptr in list.
780 *
781 * Each time this is called, the previously returned list is deallocated and
782 * must no longer be used.
783 *
Erik Staatsb1f77952022-03-25 11:49:58 -0700784 * Clients should call this if they receive a sensor update from
785 * {@link ASENSOR_TYPE_DYNAMIC_SENSOR_META} indicating the sensors have changed.
786 * If this happens, previously received lists from this method will be stale.
787 *
Erik Staatsd35a5742022-02-04 06:37:58 -0800788 * Available since API level 33.
789 *
790 * \param manager the {@link ASensorManager} instance obtained from
791 * {@link ASensorManager_getInstanceForPackage}.
792 * \param list the returned list of dynamic sensors.
793 * \return positive number of returned sensors or negative error code.
794 * BAD_VALUE: manager is NULL.
795 */
796ssize_t ASensorManager_getDynamicSensorList(
797 ASensorManager* manager, ASensorList* list) __INTRODUCED_IN(33);
798
799/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700800 * Returns the default sensor for the given type, or NULL if no sensor
Aravind Akellab37ba392014-08-05 14:53:07 -0700801 * of that type exists.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700802 */
803ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type);
804
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700805/**
Aravind Akellab37ba392014-08-05 14:53:07 -0700806 * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor
807 * of this type and wakeUp properties exists.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700808 *
809 * Available since API level 21.
Aravind Akellab37ba392014-08-05 14:53:07 -0700810 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700811ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp) __INTRODUCED_IN(21);
Aravind Akellab37ba392014-08-05 14:53:07 -0700812
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700813/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700814 * Creates a new sensor event queue and associate it with a looper.
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700815 *
816 * "ident" is a identifier for the events that will be returned when
817 * calling ALooper_pollOnce(). The identifier must be >= 0, or
818 * ALOOPER_POLL_CALLBACK if providing a non-NULL callback.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700819 */
820ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
821 ALooper* looper, int ident, ALooper_callbackFunc callback, void* data);
822
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700823/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700824 * Destroys the event queue and free all resources associated to it.
825 */
826int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue);
827
Peng Xu47cddca2017-02-15 23:31:22 -0800828/**
829 * Create direct channel based on shared memory
830 *
831 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} to be used
832 * for configuring sensor direct report.
833 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700834 * Available since API level 26.
835 *
Peng Xu47cddca2017-02-15 23:31:22 -0800836 * \param manager the {@link ASensorManager} instance obtained from
837 * {@link ASensorManager_getInstanceForPackage}.
838 * \param fd file descriptor representing a shared memory created by
839 * {@link ASharedMemory_create}
840 * \param size size to be used, must be less or equal to size of shared memory.
841 *
842 * \return a positive integer as a channel id to be used in
843 * {@link ASensorManager_destroyDirectChannel} and
844 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
845 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700846int ASensorManager_createSharedMemoryDirectChannel(ASensorManager* manager, int fd, size_t size) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800847
848/**
849 * Create direct channel based on AHardwareBuffer
850 *
851 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER} type to be used
852 * for configuring sensor direct report.
853 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700854 * Available since API level 26.
855 *
Peng Xu47cddca2017-02-15 23:31:22 -0800856 * \param manager the {@link ASensorManager} instance obtained from
857 * {@link ASensorManager_getInstanceForPackage}.
858 * \param buffer {@link AHardwareBuffer} instance created by {@link AHardwareBuffer_allocate}.
859 * \param size the intended size to be used, must be less or equal to size of buffer.
860 *
861 * \return a positive integer as a channel id to be used in
862 * {@link ASensorManager_destroyDirectChannel} and
863 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
864 */
865int ASensorManager_createHardwareBufferDirectChannel(
Elliott Hughes9db409b2018-06-18 12:28:46 -0700866 ASensorManager* manager, AHardwareBuffer const * buffer, size_t size) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800867
868/**
869 * Destroy a direct channel
870 *
gfan5d5faa42021-04-12 15:14:29 -0700871 * Destroy a direct channel previously created by using one of
872 * ASensorManager_create*DirectChannel() derivative functions.
873 * Note that the buffer used for creating the direct channel does not get destroyed with
874 * ASensorManager_destroyDirectChannel and has to be closed or released separately.
Peng Xu47cddca2017-02-15 23:31:22 -0800875 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700876 * Available since API level 26.
877 *
Peng Xu47cddca2017-02-15 23:31:22 -0800878 * \param manager the {@link ASensorManager} instance obtained from
879 * {@link ASensorManager_getInstanceForPackage}.
880 * \param channelId channel id (a positive integer) returned from
881 * {@link ASensorManager_createSharedMemoryDirectChannel} or
882 * {@link ASensorManager_createHardwareBufferDirectChannel}.
883 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700884void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800885
886/**
887 * Configure direct report on channel
888 *
889 * Configure sensor direct report on a direct channel: set rate to value other than
890 * {@link ASENSOR_DIRECT_RATE_STOP} so that sensor event can be directly
Peng Xuec53d022017-04-06 18:02:29 -0700891 * written into the shared memory region used for creating the buffer. It returns a positive token
892 * which can be used for identify sensor events from different sensors on success. Calling with rate
893 * {@link ASENSOR_DIRECT_RATE_STOP} will stop direct report of the sensor specified in the channel.
Peng Xu47cddca2017-02-15 23:31:22 -0800894 *
895 * To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to
896 * {@link ASENSOR_DIRECT_RATE_STOP}.
897 *
898 * In order to successfully configure a direct report, the sensor has to support the specified rate
899 * and the channel type, which can be checked by {@link ASensor_getHighestDirectReportRateLevel} and
900 * {@link ASensor_isDirectChannelTypeSupported}, respectively.
901 *
902 * Example:
Peng Xu47cddca2017-02-15 23:31:22 -0800903 *
Peng Xu80df0162017-08-05 19:00:23 -0700904 * ASensorManager *manager = ...;
905 * ASensor *sensor = ...;
906 * int channelId = ...;
907 *
908 * ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST);
Peng Xu47cddca2017-02-15 23:31:22 -0800909 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700910 * Available since API level 26.
911 *
Peng Xu47cddca2017-02-15 23:31:22 -0800912 * \param manager the {@link ASensorManager} instance obtained from
913 * {@link ASensorManager_getInstanceForPackage}.
914 * \param sensor a {@link ASensor} to denote which sensor to be operate. It can be NULL if rate
915 * is {@link ASENSOR_DIRECT_RATE_STOP}, denoting stopping of all active sensor
916 * direct report.
917 * \param channelId channel id (a positive integer) returned from
918 * {@link ASensorManager_createSharedMemoryDirectChannel} or
919 * {@link ASensorManager_createHardwareBufferDirectChannel}.
gfan5d5faa42021-04-12 15:14:29 -0700920 * \param rate one of predefined ASENSOR_DIRECT_RATE_... that is supported by the sensor.
Peng Xuec53d022017-04-06 18:02:29 -0700921 * \return positive token for success or negative error code.
Peng Xu47cddca2017-02-15 23:31:22 -0800922 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700923int ASensorManager_configureDirectReport(ASensorManager* manager,
924 ASensor const* sensor, int channelId, int rate) __INTRODUCED_IN(26);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700925
926/*****************************************************************************/
927
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700928/**
Peng Xu80df0162017-08-05 19:00:23 -0700929 * Enable the selected sensor with sampling and report parameters
930 *
931 * Enable the selected sensor at a specified sampling period and max batch report latency.
932 * To disable sensor, use {@link ASensorEventQueue_disableSensor}.
933 *
934 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
935 * \param sensor {@link ASensor} to be enabled.
936 * \param samplingPeriodUs sampling period of sensor in microseconds.
gfan5d5faa42021-04-12 15:14:29 -0700937 * \param maxBatchReportLatencyUs maximum time interval between two batches of sensor events are
Peng Xu80df0162017-08-05 19:00:23 -0700938 * delievered in microseconds. For sensor streaming, set to 0.
939 * \return 0 on success or a negative error code on failure.
Aniroop Mathurda94fd82015-11-03 01:47:46 +0530940 */
941int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor,
Peng Xuda8385c2017-02-28 20:19:47 -0800942 int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs);
Aniroop Mathurda94fd82015-11-03 01:47:46 +0530943
944/**
Peng Xu80df0162017-08-05 19:00:23 -0700945 * Enable the selected sensor at default sampling rate.
946 *
947 * Start event reports of a sensor to specified sensor event queue at a default rate.
948 *
949 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
950 * \param sensor {@link ASensor} to be enabled.
951 *
952 * \return 0 on success or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700953 */
954int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor);
955
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700956/**
Peng Xu80df0162017-08-05 19:00:23 -0700957 * Disable the selected sensor.
958 *
959 * Stop event reports from the sensor to specified sensor event queue.
960 *
961 * \param queue {@link ASensorEventQueue} to be changed
962 * \param sensor {@link ASensor} to be disabled
963 * \return 0 on success or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700964 */
965int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor);
966
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700967/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700968 * Sets the delivery rate of events in microseconds for the given sensor.
Peng Xu80df0162017-08-05 19:00:23 -0700969 *
970 * This function has to be called after {@link ASensorEventQueue_enableSensor}.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700971 * Note that this is a hint only, generally event will arrive at a higher
972 * rate. It is an error to set a rate inferior to the value returned by
973 * ASensor_getMinDelay().
Peng Xu80df0162017-08-05 19:00:23 -0700974 *
975 * \param queue {@link ASensorEventQueue} to which sensor event is delivered.
976 * \param sensor {@link ASensor} of which sampling rate to be updated.
977 * \param usec sensor sampling period (1/sampling rate) in microseconds
978 * \return 0 on sucess or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700979 */
980int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec);
981
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700982/**
Peng Xu80df0162017-08-05 19:00:23 -0700983 * Determine if a sensor event queue has pending event to be processed.
984 *
985 * \param queue {@link ASensorEventQueue} to be queried
986 * \return 1 if the queue has events; 0 if it does not have events;
987 * or a negative value if there is an error.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700988 */
989int ASensorEventQueue_hasEvents(ASensorEventQueue* queue);
990
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700991/**
Peng Xu80df0162017-08-05 19:00:23 -0700992 * Retrieve pending events in sensor event queue
993 *
994 * Retrieve next available events from the queue to a specified event array.
995 *
996 * \param queue {@link ASensorEventQueue} to get events from
gfan5d5faa42021-04-12 15:14:29 -0700997 * \param events pointer to an array of {@link ASensorEvent}.
Peng Xu80df0162017-08-05 19:00:23 -0700998 * \param count max number of event that can be filled into array event.
999 * \return number of events returned on success; negative error code when
1000 * no events are pending or an error has occurred.
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001001 *
1002 * Examples:
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001003 *
Peng Xu80df0162017-08-05 19:00:23 -07001004 * ASensorEvent event;
1005 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1);
1006 *
1007 * ASensorEvent eventBuffer[8];
1008 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8);
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001009 *
1010 */
Peng Xuda8385c2017-02-28 20:19:47 -08001011ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count);
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001012
Brian Stack65089d52019-01-11 10:52:07 -08001013/**
1014 * Request that {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to be delivered on
1015 * the given {@link ASensorEventQueue}.
1016 *
gfan5d5faa42021-04-12 15:14:29 -07001017 * Sensor data events are always delivered to the {@link ASensorEventQueue}.
Brian Stack65089d52019-01-11 10:52:07 -08001018 *
1019 * The {@link ASENSOR_TYPE_ADDITIONAL_INFO} events will be returned through
1020 * {@link ASensorEventQueue_getEvents}. The client is responsible for checking
1021 * {@link ASensorEvent#type} to determine the event type prior to handling of
1022 * the event.
1023 *
1024 * The client must be tolerant of any value for
1025 * {@link AAdditionalInfoEvent#type}, as new values may be defined in the future
1026 * and may delivered to the client.
1027 *
Elliott Hughes3d70e532019-10-29 08:59:39 -07001028 * Available since API level 29.
1029 *
Brian Stack65089d52019-01-11 10:52:07 -08001030 * \param queue {@link ASensorEventQueue} to configure
1031 * \param enable true to request {@link ASENSOR_TYPE_ADDITIONAL_INFO} events,
1032 * false to stop receiving events
1033 * \return 0 on success or a negative error code on failure
1034 */
Elliott Hughes3d70e532019-10-29 08:59:39 -07001035int ASensorEventQueue_requestAdditionalInfoEvents(ASensorEventQueue* queue, bool enable) __INTRODUCED_IN(29);
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001036
1037/*****************************************************************************/
1038
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001039/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001040 * Returns this sensor's name (non localized)
1041 */
1042const char* ASensor_getName(ASensor const* sensor);
1043
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001044/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001045 * Returns this sensor's vendor's name (non localized)
1046 */
1047const char* ASensor_getVendor(ASensor const* sensor);
1048
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001049/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001050 * Return this sensor's type
1051 */
1052int ASensor_getType(ASensor const* sensor);
1053
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001054/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001055 * Returns this sensors's resolution
1056 */
1057float ASensor_getResolution(ASensor const* sensor);
1058
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001059/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001060 * Returns the minimum delay allowed between events in microseconds.
1061 * A value of zero means that this sensor doesn't report events at a
1062 * constant rate, but rather only when a new data is available.
1063 */
1064int ASensor_getMinDelay(ASensor const* sensor);
1065
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001066/**
Aravind Akella70018042014-04-07 22:52:37 +00001067 * Returns the maximum size of batches for this sensor. Batches will often be
1068 * smaller, as the hardware fifo might be used for other sensors.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001069 *
1070 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +00001071 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001072int ASensor_getFifoMaxEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +00001073
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001074/**
Aravind Akella70018042014-04-07 22:52:37 +00001075 * Returns the hardware batch fifo size reserved to this sensor.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001076 *
1077 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +00001078 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001079int ASensor_getFifoReservedEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +00001080
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001081/**
Aravind Akella70018042014-04-07 22:52:37 +00001082 * Returns this sensor's string type.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001083 *
1084 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +00001085 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001086const char* ASensor_getStringType(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +00001087
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001088/**
Aravind Akella0e025c52014-06-03 19:19:57 -07001089 * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001090 *
1091 * Available since API level 21.
Aravind Akella0e025c52014-06-03 19:19:57 -07001092 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001093int ASensor_getReportingMode(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella0e025c52014-06-03 19:19:57 -07001094
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001095/**
Aravind Akellab37ba392014-08-05 14:53:07 -07001096 * Returns true if this is a wake up sensor, false otherwise.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001097 *
1098 * Available since API level 21.
Aravind Akellab37ba392014-08-05 14:53:07 -07001099 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001100bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akellab37ba392014-08-05 14:53:07 -07001101
Peng Xu47cddca2017-02-15 23:31:22 -08001102/**
1103 * Test if sensor supports a certain type of direct channel.
1104 *
Elliott Hughes3d70e532019-10-29 08:59:39 -07001105 * Available since API level 26.
1106 *
Peng Xu47cddca2017-02-15 23:31:22 -08001107 * \param sensor a {@link ASensor} to denote the sensor to be checked.
1108 * \param channelType Channel type constant, either
gfan5d5faa42021-04-12 15:14:29 -07001109 * {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY}
Peng Xu47cddca2017-02-15 23:31:22 -08001110 * or {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER}.
1111 * \returns true if sensor supports the specified direct channel type.
1112 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001113bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType) __INTRODUCED_IN(26);
1114
Peng Xu47cddca2017-02-15 23:31:22 -08001115/**
Elliott Hughes3d70e532019-10-29 08:59:39 -07001116 * Get the highest direct rate level that a sensor supports.
1117 *
1118 * Available since API level 26.
Peng Xu47cddca2017-02-15 23:31:22 -08001119 *
1120 * \param sensor a {@link ASensor} to denote the sensor to be checked.
1121 *
1122 * \return a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor.
1123 * If return value is {@link ASENSOR_DIRECT_RATE_STOP}, it means the sensor
1124 * does not support direct report.
1125 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001126int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -08001127
Brian Stack8228fa72019-01-04 14:15:13 -08001128/**
1129 * Returns the sensor's handle.
1130 *
1131 * The handle identifies the sensor within the system and is included in the
gfanc150ea12021-04-14 09:27:55 -07001132 * sensor field of {@link ASensorEvent}, including those sent with type
Brian Stack8228fa72019-01-04 14:15:13 -08001133 * {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
1134 *
1135 * A sensor's handle is able to be used to map {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to the
1136 * sensor that generated the event.
1137 *
1138 * It is important to note that the value returned by {@link ASensor_getHandle} is not the same as
gfan5d5faa42021-04-12 15:14:29 -07001139 * the value returned by the Java API <a href="/reference/android/hardware/Sensor#getId()">
1140 * android.hardware.Sensor's getId()</a> and no mapping exists between the values.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001141 *
1142 * Available since API level 29.
Brian Stack8228fa72019-01-04 14:15:13 -08001143 */
Elliott Hughes3d70e532019-10-29 08:59:39 -07001144int ASensor_getHandle(ASensor const* sensor) __INTRODUCED_IN(29);
Brian Stack8228fa72019-01-04 14:15:13 -08001145
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001146#ifdef __cplusplus
1147};
1148#endif
1149
1150#endif // ANDROID_SENSOR_H
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001151
1152/** @} */