blob: 7e86d3fbb80d35060a4eacfaed385abc906a9551 [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
32/******************************************************************
33 *
34 * IMPORTANT NOTICE:
35 *
36 * This file is part of Android's set of stable system headers
37 * exposed by the Android NDK (Native Development Kit).
38 *
39 * Third-party source AND binary code relies on the definitions
40 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
41 *
42 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
43 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
44 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
45 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
46 */
47
Mathias Agopiane1c61d32012-03-23 14:19:36 -070048#include <android/looper.h>
49
Dan Albert8f860fd2017-04-25 12:24:28 -070050#include <stdbool.h>
Peng Xuda8385c2017-02-28 20:19:47 -080051#include <sys/types.h>
52#include <math.h>
53#include <stdint.h>
54
Elliott Hughes23e82b42021-01-26 14:55:48 -080055#if !defined(__INTRODUCED_IN)
56#define __INTRODUCED_IN(__api_level) /* nothing */
57#endif
58#if !defined(__DEPRECATED_IN)
59#define __DEPRECATED_IN(__api_level) __attribute__((__deprecated__))
60#endif
61
Mathias Agopiane1c61d32012-03-23 14:19:36 -070062#ifdef __cplusplus
63extern "C" {
64#endif
65
Peng Xu47cddca2017-02-15 23:31:22 -080066typedef struct AHardwareBuffer AHardwareBuffer;
Mathias Agopiane1c61d32012-03-23 14:19:36 -070067
Peng Xuda8385c2017-02-28 20:19:47 -080068#define ASENSOR_RESOLUTION_INVALID (nanf(""))
69#define ASENSOR_FIFO_COUNT_INVALID (-1)
70#define ASENSOR_DELAY_INVALID INT32_MIN
Brian Stack8228fa72019-01-04 14:15:13 -080071#define ASENSOR_INVALID (-1)
Peng Xuda8385c2017-02-28 20:19:47 -080072
Elliott Hughesf78be362018-01-23 15:33:56 -080073/* (Keep in sync with hardware/sensors-base.h and Sensor.java.) */
74
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070075/**
76 * Sensor types.
Elliott Hughesf78be362018-01-23 15:33:56 -080077 *
78 * See
79 * [android.hardware.SensorEvent#values](https://developer.android.com/reference/android/hardware/SensorEvent.html#values)
80 * for detailed explanations of the data returned for each of these types.
Mathias Agopiane1c61d32012-03-23 14:19:36 -070081 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070082enum {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070083 /**
Peng Xu37317b62017-03-07 17:49:31 -080084 * Invalid sensor type. Returned by {@link ASensor_getType} as error value.
85 */
86 ASENSOR_TYPE_INVALID = -1,
87 /**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070088 * {@link ASENSOR_TYPE_ACCELEROMETER}
89 * reporting-mode: continuous
90 *
91 * All values are in SI units (m/s^2) and measure the acceleration of the
92 * device minus the force of gravity.
93 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -070094 ASENSOR_TYPE_ACCELEROMETER = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070095 /**
96 * {@link ASENSOR_TYPE_MAGNETIC_FIELD}
97 * reporting-mode: continuous
98 *
99 * All values are in micro-Tesla (uT) and measure the geomagnetic
100 * field in the X, Y and Z axis.
101 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700102 ASENSOR_TYPE_MAGNETIC_FIELD = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700103 /**
104 * {@link ASENSOR_TYPE_GYROSCOPE}
105 * reporting-mode: continuous
106 *
107 * All values are in radians/second and measure the rate of rotation
108 * around the X, Y and Z axis.
109 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700110 ASENSOR_TYPE_GYROSCOPE = 4,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700111 /**
112 * {@link ASENSOR_TYPE_LIGHT}
113 * reporting-mode: on-change
114 *
115 * The light sensor value is returned in SI lux units.
116 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700117 ASENSOR_TYPE_LIGHT = 5,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700118 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800119 * {@link ASENSOR_TYPE_PRESSURE}
120 *
121 * The pressure sensor value is returned in hPa (millibar).
122 */
123 ASENSOR_TYPE_PRESSURE = 6,
124 /**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700125 * {@link ASENSOR_TYPE_PROXIMITY}
126 * reporting-mode: on-change
127 *
128 * The proximity sensor which turns the screen off and back on during calls is the
129 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
130 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
131 * SENSOR_FLAG_WAKE_UP.
132 * The value corresponds to the distance to the nearest object in centimeters.
133 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700134 ASENSOR_TYPE_PROXIMITY = 8,
135 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800136 * {@link ASENSOR_TYPE_GRAVITY}
137 *
138 * All values are in SI units (m/s^2) and measure the direction and
139 * magnitude of gravity. When the device is at rest, the output of
140 * the gravity sensor should be identical to that of the accelerometer.
141 */
142 ASENSOR_TYPE_GRAVITY = 9,
143 /**
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700144 * {@link ASENSOR_TYPE_LINEAR_ACCELERATION}
145 * reporting-mode: continuous
146 *
147 * All values are in SI units (m/s^2) and measure the acceleration of the
148 * device not including the force of gravity.
149 */
Elliott Hughesf78be362018-01-23 15:33:56 -0800150 ASENSOR_TYPE_LINEAR_ACCELERATION = 10,
151 /**
152 * {@link ASENSOR_TYPE_ROTATION_VECTOR}
153 */
154 ASENSOR_TYPE_ROTATION_VECTOR = 11,
155 /**
156 * {@link ASENSOR_TYPE_RELATIVE_HUMIDITY}
157 *
158 * The relative humidity sensor value is returned in percent.
159 */
160 ASENSOR_TYPE_RELATIVE_HUMIDITY = 12,
161 /**
162 * {@link ASENSOR_TYPE_AMBIENT_TEMPERATURE}
163 *
164 * The ambient temperature sensor value is returned in Celcius.
165 */
166 ASENSOR_TYPE_AMBIENT_TEMPERATURE = 13,
167 /**
168 * {@link ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED}
169 */
170 ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14,
171 /**
172 * {@link ASENSOR_TYPE_GAME_ROTATION_VECTOR}
173 */
174 ASENSOR_TYPE_GAME_ROTATION_VECTOR = 15,
175 /**
176 * {@link ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED}
177 */
178 ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 16,
179 /**
180 * {@link ASENSOR_TYPE_SIGNIFICANT_MOTION}
181 */
182 ASENSOR_TYPE_SIGNIFICANT_MOTION = 17,
183 /**
184 * {@link ASENSOR_TYPE_STEP_DETECTOR}
185 */
186 ASENSOR_TYPE_STEP_DETECTOR = 18,
187 /**
188 * {@link ASENSOR_TYPE_STEP_COUNTER}
189 */
190 ASENSOR_TYPE_STEP_COUNTER = 19,
191 /**
192 * {@link ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR}
193 */
194 ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20,
195 /**
196 * {@link ASENSOR_TYPE_HEART_RATE}
197 */
198 ASENSOR_TYPE_HEART_RATE = 21,
199 /**
200 * {@link ASENSOR_TYPE_POSE_6DOF}
201 */
202 ASENSOR_TYPE_POSE_6DOF = 28,
203 /**
204 * {@link ASENSOR_TYPE_STATIONARY_DETECT}
205 */
206 ASENSOR_TYPE_STATIONARY_DETECT = 29,
207 /**
208 * {@link ASENSOR_TYPE_MOTION_DETECT}
209 */
210 ASENSOR_TYPE_MOTION_DETECT = 30,
211 /**
212 * {@link ASENSOR_TYPE_HEART_BEAT}
213 */
214 ASENSOR_TYPE_HEART_BEAT = 31,
215 /**
Brian Stackccd88432019-01-08 17:04:18 -0800216 * This sensor type is for delivering additional sensor information aside
217 * from sensor event data.
218 *
219 * Additional information may include:
220 * - {@link ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE}
221 * - {@link ASENSOR_ADDITIONAL_INFO_SAMPLING}
222 * - {@link ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT}
223 * - {@link ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY}
224 * - {@link ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION}
225 *
226 * This type will never bind to a sensor. In other words, no sensor in the
227 * sensor list can have the type {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
228 *
229 * If a device supports the sensor additional information feature, it will
230 * report additional information events via {@link ASensorEvent} and will
gfanc150ea12021-04-14 09:27:55 -0700231 * have the type of {@link ASensorEvent} set to
232 * {@link ASENSOR_TYPE_ADDITIONAL_INFO} and the sensor of {@link ASensorEvent} set
Brian Stackccd88432019-01-08 17:04:18 -0800233 * to the handle of the reporting sensor.
234 *
235 * Additional information reports consist of multiple frames ordered by
236 * {@link ASensorEvent#timestamp}. The first frame in the report will have
237 * a {@link AAdditionalInfoEvent#type} of
238 * {@link ASENSOR_ADDITIONAL_INFO_BEGIN}, and the last frame in the report
239 * will have a {@link AAdditionalInfoEvent#type} of
240 * {@link ASENSOR_ADDITIONAL_INFO_END}.
241 *
242 */
243 ASENSOR_TYPE_ADDITIONAL_INFO = 33,
244 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800245 * {@link ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT}
246 */
247 ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT = 34,
248 /**
249 * {@link ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED}
250 */
251 ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35,
Anthony Stangefdb1fc82020-01-16 15:02:48 -0500252 /**
253 * {@link ASENSOR_TYPE_HINGE_ANGLE}
Anthony Stanged7a703c2020-02-18 12:02:22 -0500254 * reporting-mode: on-change
255 *
256 * The hinge angle sensor value is returned in degrees.
Anthony Stangefdb1fc82020-01-16 15:02:48 -0500257 */
258 ASENSOR_TYPE_HINGE_ANGLE = 36,
Brian Duddie573da3b2021-12-10 14:34:07 -0800259 /**
260 * {@link ASENSOR_TYPE_HEAD_TRACKER}
261 * reporting-mode: continuous
262 *
263 * Measures the orientation and rotational velocity of a user's head.
264 */
265 ASENSOR_TYPE_HEAD_TRACKER = 37,
Eva Chenc0420b72021-04-09 15:44:12 -0700266 /**
267 * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES}
268 * reporting-mode: continuous
269 *
270 * The first three values are in SI units (m/s^2) and measure the acceleration of the device
271 * minus the force of gravity. The last three values indicate which acceleration axes are
272 * supported. A value of 1.0 means supported and a value of 0 means not supported.
273 */
274 ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES = 38,
275 /**
276 * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES}
277 * reporting-mode: continuous
278 *
279 * The first three values are in radians/second and measure the rate of rotation around the X,
280 * Y and Z axis. The last three values indicate which rotation axes are supported. A value of
281 * 1.0 means supported and a value of 0 means not supported.
282 */
283 ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES = 39,
284 /**
285 * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED}
286 * reporting-mode: continuous
287 *
288 * The first three values are in SI units (m/s^2) and measure the acceleration of the device
289 * minus the force of gravity. The middle three values represent the estimated bias for each
290 * axis. The last three values indicate which acceleration axes are supported. A value of 1.0
291 * means supported and a value of 0 means not supported.
292 */
293 ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED = 40,
294 /**
295 * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED}
296 * reporting-mode: continuous
297 *
298 * The first three values are in radians/second and measure the rate of rotation around the X,
299 * Y and Z axis. The middle three values represent the estimated drift around each axis in
300 * rad/s. The last three values indicate which rotation axes are supported. A value of 1.0 means
301 * supported and a value of 0 means not supported.
302 */
303 ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED = 41,
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700304};
305
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700306/**
307 * Sensor accuracy measure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700308 */
309enum {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700310 /** no contact */
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700311 ASENSOR_STATUS_NO_CONTACT = -1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700312 /** unreliable */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700313 ASENSOR_STATUS_UNRELIABLE = 0,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700314 /** low accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700315 ASENSOR_STATUS_ACCURACY_LOW = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700316 /** medium accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700317 ASENSOR_STATUS_ACCURACY_MEDIUM = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700318 /** high accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700319 ASENSOR_STATUS_ACCURACY_HIGH = 3
320};
321
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700322/**
Aravind Akella0e025c52014-06-03 19:19:57 -0700323 * Sensor Reporting Modes.
324 */
325enum {
Peng Xu37317b62017-03-07 17:49:31 -0800326 /** invalid reporting mode */
327 AREPORTING_MODE_INVALID = -1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700328 /** continuous reporting */
Aravind Akella0e025c52014-06-03 19:19:57 -0700329 AREPORTING_MODE_CONTINUOUS = 0,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700330 /** reporting on change */
Aravind Akella0e025c52014-06-03 19:19:57 -0700331 AREPORTING_MODE_ON_CHANGE = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700332 /** on shot reporting */
Aravind Akella0e025c52014-06-03 19:19:57 -0700333 AREPORTING_MODE_ONE_SHOT = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700334 /** special trigger reporting */
Peng Xu37317b62017-03-07 17:49:31 -0800335 AREPORTING_MODE_SPECIAL_TRIGGER = 3
Aravind Akella0e025c52014-06-03 19:19:57 -0700336};
337
Peng Xu47cddca2017-02-15 23:31:22 -0800338/**
339 * Sensor Direct Report Rates.
340 */
341enum {
342 /** stopped */
343 ASENSOR_DIRECT_RATE_STOP = 0,
344 /** nominal 50Hz */
345 ASENSOR_DIRECT_RATE_NORMAL = 1,
346 /** nominal 200Hz */
347 ASENSOR_DIRECT_RATE_FAST = 2,
348 /** nominal 800Hz */
349 ASENSOR_DIRECT_RATE_VERY_FAST = 3
350};
351
352/**
353 * Sensor Direct Channel Type.
354 */
355enum {
356 /** shared memory created by ASharedMemory_create */
357 ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1,
358 /** AHardwareBuffer */
359 ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2
360};
361
Brian Stackccd88432019-01-08 17:04:18 -0800362/**
363 * Sensor Additional Info Types.
364 *
365 * Used to populate {@link AAdditionalInfoEvent#type}.
366 */
367enum {
368 /** Marks the beginning of additional information frames */
369 ASENSOR_ADDITIONAL_INFO_BEGIN = 0,
370
371 /** Marks the end of additional information frames */
372 ASENSOR_ADDITIONAL_INFO_END = 1,
373
374 /**
375 * Estimation of the delay that is not tracked by sensor timestamps. This
376 * includes delay introduced by sensor front-end filtering, data transport,
377 * etc.
378 * float[2]: delay in seconds, standard deviation of estimated value
379 */
380 ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY = 0x10000,
381
382 /** float: Celsius temperature */
383 ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE,
384
385 /**
386 * First three rows of a homogeneous matrix, which represents calibration to
387 * a three-element vector raw sensor reading.
388 * float[12]: 3x4 matrix in row major order
389 */
390 ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION,
391
392 /**
393 * Location and orientation of sensor element in the device frame: origin is
394 * the geometric center of the mobile device screen surface; the axis
395 * definition corresponds to Android sensor definitions.
396 * float[12]: 3x4 matrix in row major order
397 */
398 ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT,
399
400 /**
401 * float[2]: raw sample period in seconds,
402 * standard deviation of sampling period
403 */
404 ASENSOR_ADDITIONAL_INFO_SAMPLING,
405};
406
Aravind Akella0e025c52014-06-03 19:19:57 -0700407/*
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700408 * A few useful constants
409 */
410
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700411/** Earth's gravity in m/s^2 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700412#define ASENSOR_STANDARD_GRAVITY (9.80665f)
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700413/** Maximum magnetic field on Earth's surface in uT */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700414#define ASENSOR_MAGNETIC_FIELD_EARTH_MAX (60.0f)
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700415/** Minimum magnetic field on Earth's surface in uT*/
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700416#define ASENSOR_MAGNETIC_FIELD_EARTH_MIN (30.0f)
417
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700418/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700419 * A sensor event.
420 */
421
Peng Xu70b98382017-08-07 14:09:11 -0700422/* NOTE: changes to these structs have to be backward compatible */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700423typedef struct ASensorVector {
424 union {
425 float v[3];
426 struct {
427 float x;
428 float y;
429 float z;
430 };
431 struct {
432 float azimuth;
433 float pitch;
434 float roll;
435 };
436 };
437 int8_t status;
438 uint8_t reserved[3];
439} ASensorVector;
440
Aravind Akella724d91d2013-06-27 12:04:23 -0700441typedef struct AMetaDataEvent {
442 int32_t what;
443 int32_t sensor;
444} AMetaDataEvent;
445
446typedef struct AUncalibratedEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800447 union {
448 float uncalib[3];
449 struct {
450 float x_uncalib;
451 float y_uncalib;
452 float z_uncalib;
453 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700454 };
Peng Xu9e720462016-01-26 18:48:54 -0800455 union {
456 float bias[3];
457 struct {
458 float x_bias;
459 float y_bias;
460 float z_bias;
461 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700462 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700463} AUncalibratedEvent;
464
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700465typedef struct AHeartRateEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800466 float bpm;
467 int8_t status;
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700468} AHeartRateEvent;
469
Peng Xu2576cb62016-01-20 00:22:09 -0800470typedef struct ADynamicSensorEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800471 int32_t connected;
472 int32_t handle;
Peng Xu2576cb62016-01-20 00:22:09 -0800473} ADynamicSensorEvent;
474
Brian Stackccd88432019-01-08 17:04:18 -0800475typedef struct AAdditionalInfoEvent {
gfan5d5faa42021-04-12 15:14:29 -0700476 /**
477 * Event type, such as ASENSOR_ADDITIONAL_INFO_BEGIN, ASENSOR_ADDITIONAL_INFO_END and others.
478 * Refer to {@link ASENSOR_TYPE_ADDITIONAL_INFO} for the expected reporting behavior.
479 */
Peng Xu9e720462016-01-26 18:48:54 -0800480 int32_t type;
481 int32_t serial;
482 union {
483 int32_t data_int32[14];
484 float data_float[14];
485 };
486} AAdditionalInfoEvent;
487
Brian Duddie573da3b2021-12-10 14:34:07 -0800488typedef struct AHeadTrackerEvent {
489 /**
490 * The fields rx, ry, rz are an Euler vector (rotation vector, i.e. a vector
491 * whose direction indicates the axis of rotation and magnitude indicates
492 * the angle to rotate around that axis) representing the transform from
493 * the (arbitrary, possibly slowly drifting) reference frame to the
494 * head frame. Expressed in radians. Magnitude of the vector must be
495 * in the range [0, pi], while the value of individual axes are
496 * in the range [-pi, pi].
497 */
498 float rx;
499 float ry;
500 float rz;
501
502 /**
503 * The fields vx, vy, vz are an Euler vector (rotation vector) representing
504 * the angular velocity of the head (relative to itself), in radians per
505 * second. The direction of this vector indicates the axis of rotation, and
506 * the magnitude indicates the rate of rotation.
507 */
508 float vx;
509 float vy;
510 float vz;
511
512 /**
513 * This value changes each time the reference frame is suddenly and
514 * significantly changed, for example if an orientation filter algorithm
515 * used for determining the orientation has had its state reset.
516 */
517 int32_t discontinuity_count;
518} AHeadTrackerEvent;
519
Eva Chenc0420b72021-04-09 15:44:12 -0700520typedef struct ALimitedAxesImuEvent {
521 union {
522 float calib[3];
523 struct {
524 float x;
525 float y;
526 float z;
527 };
528 };
529 union {
530 float supported[3];
531 struct {
532 float x_supported;
533 float y_supported;
534 float z_supported;
535 };
536 };
537} ALimitedAxesImuEvent;
538
539typedef struct ALimitedAxesImuUncalibratedEvent {
540 union {
541 float uncalib[3];
542 struct {
543 float x_uncalib;
544 float y_uncalib;
545 float z_uncalib;
546 };
547 };
548 union {
549 float bias[3];
550 struct {
551 float x_bias;
552 float y_bias;
553 float z_bias;
554 };
555 };
556 union {
557 float supported[3];
558 struct {
559 float x_supported;
560 float y_supported;
561 float z_supported;
562 };
563 };
564} ALimitedAxesImuUncalibratedEvent;
565
gfan5d5faa42021-04-12 15:14:29 -0700566/**
567 * Information that describes a sensor event, refer to
568 * <a href="/reference/android/hardware/SensorEvent">SensorEvent</a> for additional
569 * documentation.
570 */
Peng Xu70b98382017-08-07 14:09:11 -0700571/* NOTE: changes to this struct has to be backward compatible */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700572typedef struct ASensorEvent {
573 int32_t version; /* sizeof(struct ASensorEvent) */
gfan5d5faa42021-04-12 15:14:29 -0700574 int32_t sensor; /** The sensor that generates this event */
gfanc150ea12021-04-14 09:27:55 -0700575 int32_t type; /** Sensor type for the event, such as {@link ASENSOR_TYPE_ACCELEROMETER} */
gfan5d5faa42021-04-12 15:14:29 -0700576 int32_t reserved0; /** do not use */
577 /**
578 * The time in nanoseconds at which the event happened, and its behavior
579 * is identical to <a href="/reference/android/hardware/SensorEvent#timestamp">
580 * SensorEvent::timestamp</a> in Java API.
581 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700582 int64_t timestamp;
583 union {
Mathias Agopianba02cd22013-07-03 16:20:57 -0700584 union {
585 float data[16];
586 ASensorVector vector;
587 ASensorVector acceleration;
Brian Duddiee02c0662021-03-16 09:53:20 -0700588 ASensorVector gyro;
Mathias Agopianba02cd22013-07-03 16:20:57 -0700589 ASensorVector magnetic;
590 float temperature;
591 float distance;
592 float light;
593 float pressure;
Aravind Akella724d91d2013-06-27 12:04:23 -0700594 float relative_humidity;
Brian Duddiee02c0662021-03-16 09:53:20 -0700595 AUncalibratedEvent uncalibrated_acceleration;
Aravind Akella724d91d2013-06-27 12:04:23 -0700596 AUncalibratedEvent uncalibrated_gyro;
597 AUncalibratedEvent uncalibrated_magnetic;
598 AMetaDataEvent meta_data;
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700599 AHeartRateEvent heart_rate;
Peng Xu2576cb62016-01-20 00:22:09 -0800600 ADynamicSensorEvent dynamic_sensor_meta;
Peng Xu9e720462016-01-26 18:48:54 -0800601 AAdditionalInfoEvent additional_info;
Brian Duddie573da3b2021-12-10 14:34:07 -0800602 AHeadTrackerEvent head_tracker;
Eva Chenc0420b72021-04-09 15:44:12 -0700603 ALimitedAxesImuEvent limited_axes_imu;
604 ALimitedAxesImuUncalibratedEvent limited_axes_imu_uncalibrated;
Mathias Agopianba02cd22013-07-03 16:20:57 -0700605 };
606 union {
607 uint64_t data[8];
608 uint64_t step_counter;
609 } u64;
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700610 };
Aravind Akella9a844cf2014-02-11 18:58:52 -0800611
612 uint32_t flags;
613 int32_t reserved1[3];
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700614} ASensorEvent;
615
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700616struct ASensorManager;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700617/**
618 * {@link ASensorManager} is an opaque type to manage sensors and
619 * events queues.
620 *
621 * {@link ASensorManager} is a singleton that can be obtained using
622 * ASensorManager_getInstance().
623 *
624 * This file provides a set of functions that uses {@link
625 * ASensorManager} to access and list hardware sensors, and
626 * create and destroy event queues:
627 * - ASensorManager_getSensorList()
628 * - ASensorManager_getDefaultSensor()
629 * - ASensorManager_getDefaultSensorEx()
630 * - ASensorManager_createEventQueue()
631 * - ASensorManager_destroyEventQueue()
632 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700633typedef struct ASensorManager ASensorManager;
634
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700635
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700636struct ASensorEventQueue;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700637/**
638 * {@link ASensorEventQueue} is an opaque type that provides access to
639 * {@link ASensorEvent} from hardware sensors.
640 *
641 * A new {@link ASensorEventQueue} can be obtained using ASensorManager_createEventQueue().
642 *
643 * This file provides a set of functions to enable and disable
644 * sensors, check and get events, and set event rates on a {@link
645 * ASensorEventQueue}.
646 * - ASensorEventQueue_enableSensor()
647 * - ASensorEventQueue_disableSensor()
648 * - ASensorEventQueue_hasEvents()
649 * - ASensorEventQueue_getEvents()
650 * - ASensorEventQueue_setEventRate()
Brian Stack65089d52019-01-11 10:52:07 -0800651 * - ASensorEventQueue_requestAdditionalInfoEvents()
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700652 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700653typedef struct ASensorEventQueue ASensorEventQueue;
654
655struct ASensor;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700656/**
657 * {@link ASensor} is an opaque type that provides information about
658 * an hardware sensors.
659 *
660 * A {@link ASensor} pointer can be obtained using
661 * ASensorManager_getDefaultSensor(),
662 * ASensorManager_getDefaultSensorEx() or from a {@link ASensorList}.
663 *
664 * This file provides a set of functions to access properties of a
665 * {@link ASensor}:
666 * - ASensor_getName()
667 * - ASensor_getVendor()
668 * - ASensor_getType()
669 * - ASensor_getResolution()
670 * - ASensor_getMinDelay()
671 * - ASensor_getFifoMaxEventCount()
672 * - ASensor_getFifoReservedEventCount()
673 * - ASensor_getStringType()
674 * - ASensor_getReportingMode()
675 * - ASensor_isWakeUpSensor()
Brian Stack8228fa72019-01-04 14:15:13 -0800676 * - ASensor_getHandle()
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700677 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700678typedef struct ASensor ASensor;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700679/**
680 * {@link ASensorRef} is a type for constant pointers to {@link ASensor}.
681 *
682 * This is used to define entry in {@link ASensorList} arrays.
683 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700684typedef ASensor const* ASensorRef;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700685/**
686 * {@link ASensorList} is an array of reference to {@link ASensor}.
687 *
688 * A {@link ASensorList} can be initialized using ASensorManager_getSensorList().
689 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700690typedef ASensorRef const* ASensorList;
691
692/*****************************************************************************/
693
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700694/**
Svet Ganov5fa32d42015-05-07 10:50:59 -0700695 * Get a reference to the sensor manager. ASensorManager is a singleton
696 * per package as different packages may have access to different sensors.
697 *
698 * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead.
699 *
700 * Example:
701 *
702 * ASensorManager* sensorManager = ASensorManager_getInstance();
703 *
704 */
Elliott Hughes23e82b42021-01-26 14:55:48 -0800705ASensorManager* ASensorManager_getInstance() __DEPRECATED_IN(26);
Svet Ganov5fa32d42015-05-07 10:50:59 -0700706
Peng Xu80df0162017-08-05 19:00:23 -0700707/**
Svet Ganov5fa32d42015-05-07 10:50:59 -0700708 * Get a reference to the sensor manager. ASensorManager is a singleton
709 * per package as different packages may have access to different sensors.
710 *
711 * Example:
712 *
Peng Xu80df0162017-08-05 19:00:23 -0700713 * ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz");
Svet Ganov5fa32d42015-05-07 10:50:59 -0700714 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700715 * Available since API level 26.
Svet Ganov5fa32d42015-05-07 10:50:59 -0700716 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700717ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26);
Svet Ganov5fa32d42015-05-07 10:50:59 -0700718
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700719/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700720 * Returns the list of available sensors.
721 */
722int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list);
723
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700724/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700725 * Returns the default sensor for the given type, or NULL if no sensor
Aravind Akellab37ba392014-08-05 14:53:07 -0700726 * of that type exists.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700727 */
728ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type);
729
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700730/**
Aravind Akellab37ba392014-08-05 14:53:07 -0700731 * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor
732 * of this type and wakeUp properties exists.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700733 *
734 * Available since API level 21.
Aravind Akellab37ba392014-08-05 14:53:07 -0700735 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700736ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp) __INTRODUCED_IN(21);
Aravind Akellab37ba392014-08-05 14:53:07 -0700737
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700738/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700739 * Creates a new sensor event queue and associate it with a looper.
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700740 *
741 * "ident" is a identifier for the events that will be returned when
742 * calling ALooper_pollOnce(). The identifier must be >= 0, or
743 * ALOOPER_POLL_CALLBACK if providing a non-NULL callback.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700744 */
745ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
746 ALooper* looper, int ident, ALooper_callbackFunc callback, void* data);
747
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700748/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700749 * Destroys the event queue and free all resources associated to it.
750 */
751int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue);
752
Peng Xu47cddca2017-02-15 23:31:22 -0800753/**
754 * Create direct channel based on shared memory
755 *
756 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} to be used
757 * for configuring sensor direct report.
758 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700759 * Available since API level 26.
760 *
Peng Xu47cddca2017-02-15 23:31:22 -0800761 * \param manager the {@link ASensorManager} instance obtained from
762 * {@link ASensorManager_getInstanceForPackage}.
763 * \param fd file descriptor representing a shared memory created by
764 * {@link ASharedMemory_create}
765 * \param size size to be used, must be less or equal to size of shared memory.
766 *
767 * \return a positive integer as a channel id to be used in
768 * {@link ASensorManager_destroyDirectChannel} and
769 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
770 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700771int ASensorManager_createSharedMemoryDirectChannel(ASensorManager* manager, int fd, size_t size) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800772
773/**
774 * Create direct channel based on AHardwareBuffer
775 *
776 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER} type to be used
777 * for configuring sensor direct report.
778 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700779 * Available since API level 26.
780 *
Peng Xu47cddca2017-02-15 23:31:22 -0800781 * \param manager the {@link ASensorManager} instance obtained from
782 * {@link ASensorManager_getInstanceForPackage}.
783 * \param buffer {@link AHardwareBuffer} instance created by {@link AHardwareBuffer_allocate}.
784 * \param size the intended size to be used, must be less or equal to size of buffer.
785 *
786 * \return a positive integer as a channel id to be used in
787 * {@link ASensorManager_destroyDirectChannel} and
788 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
789 */
790int ASensorManager_createHardwareBufferDirectChannel(
Elliott Hughes9db409b2018-06-18 12:28:46 -0700791 ASensorManager* manager, AHardwareBuffer const * buffer, size_t size) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800792
793/**
794 * Destroy a direct channel
795 *
gfan5d5faa42021-04-12 15:14:29 -0700796 * Destroy a direct channel previously created by using one of
797 * ASensorManager_create*DirectChannel() derivative functions.
798 * Note that the buffer used for creating the direct channel does not get destroyed with
799 * ASensorManager_destroyDirectChannel and has to be closed or released separately.
Peng Xu47cddca2017-02-15 23:31:22 -0800800 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700801 * Available since API level 26.
802 *
Peng Xu47cddca2017-02-15 23:31:22 -0800803 * \param manager the {@link ASensorManager} instance obtained from
804 * {@link ASensorManager_getInstanceForPackage}.
805 * \param channelId channel id (a positive integer) returned from
806 * {@link ASensorManager_createSharedMemoryDirectChannel} or
807 * {@link ASensorManager_createHardwareBufferDirectChannel}.
808 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700809void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800810
811/**
812 * Configure direct report on channel
813 *
814 * Configure sensor direct report on a direct channel: set rate to value other than
815 * {@link ASENSOR_DIRECT_RATE_STOP} so that sensor event can be directly
Peng Xuec53d022017-04-06 18:02:29 -0700816 * written into the shared memory region used for creating the buffer. It returns a positive token
817 * which can be used for identify sensor events from different sensors on success. Calling with rate
818 * {@link ASENSOR_DIRECT_RATE_STOP} will stop direct report of the sensor specified in the channel.
Peng Xu47cddca2017-02-15 23:31:22 -0800819 *
820 * To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to
821 * {@link ASENSOR_DIRECT_RATE_STOP}.
822 *
823 * In order to successfully configure a direct report, the sensor has to support the specified rate
824 * and the channel type, which can be checked by {@link ASensor_getHighestDirectReportRateLevel} and
825 * {@link ASensor_isDirectChannelTypeSupported}, respectively.
826 *
827 * Example:
Peng Xu47cddca2017-02-15 23:31:22 -0800828 *
Peng Xu80df0162017-08-05 19:00:23 -0700829 * ASensorManager *manager = ...;
830 * ASensor *sensor = ...;
831 * int channelId = ...;
832 *
833 * ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST);
Peng Xu47cddca2017-02-15 23:31:22 -0800834 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700835 * Available since API level 26.
836 *
Peng Xu47cddca2017-02-15 23:31:22 -0800837 * \param manager the {@link ASensorManager} instance obtained from
838 * {@link ASensorManager_getInstanceForPackage}.
839 * \param sensor a {@link ASensor} to denote which sensor to be operate. It can be NULL if rate
840 * is {@link ASENSOR_DIRECT_RATE_STOP}, denoting stopping of all active sensor
841 * direct report.
842 * \param channelId channel id (a positive integer) returned from
843 * {@link ASensorManager_createSharedMemoryDirectChannel} or
844 * {@link ASensorManager_createHardwareBufferDirectChannel}.
gfan5d5faa42021-04-12 15:14:29 -0700845 * \param rate one of predefined ASENSOR_DIRECT_RATE_... that is supported by the sensor.
Peng Xuec53d022017-04-06 18:02:29 -0700846 * \return positive token for success or negative error code.
Peng Xu47cddca2017-02-15 23:31:22 -0800847 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700848int ASensorManager_configureDirectReport(ASensorManager* manager,
849 ASensor const* sensor, int channelId, int rate) __INTRODUCED_IN(26);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700850
851/*****************************************************************************/
852
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700853/**
Peng Xu80df0162017-08-05 19:00:23 -0700854 * Enable the selected sensor with sampling and report parameters
855 *
856 * Enable the selected sensor at a specified sampling period and max batch report latency.
857 * To disable sensor, use {@link ASensorEventQueue_disableSensor}.
858 *
859 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
860 * \param sensor {@link ASensor} to be enabled.
861 * \param samplingPeriodUs sampling period of sensor in microseconds.
gfan5d5faa42021-04-12 15:14:29 -0700862 * \param maxBatchReportLatencyUs maximum time interval between two batches of sensor events are
Peng Xu80df0162017-08-05 19:00:23 -0700863 * delievered in microseconds. For sensor streaming, set to 0.
864 * \return 0 on success or a negative error code on failure.
Aniroop Mathurda94fd82015-11-03 01:47:46 +0530865 */
866int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor,
Peng Xuda8385c2017-02-28 20:19:47 -0800867 int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs);
Aniroop Mathurda94fd82015-11-03 01:47:46 +0530868
869/**
Peng Xu80df0162017-08-05 19:00:23 -0700870 * Enable the selected sensor at default sampling rate.
871 *
872 * Start event reports of a sensor to specified sensor event queue at a default rate.
873 *
874 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
875 * \param sensor {@link ASensor} to be enabled.
876 *
877 * \return 0 on success or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700878 */
879int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor);
880
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700881/**
Peng Xu80df0162017-08-05 19:00:23 -0700882 * Disable the selected sensor.
883 *
884 * Stop event reports from the sensor to specified sensor event queue.
885 *
886 * \param queue {@link ASensorEventQueue} to be changed
887 * \param sensor {@link ASensor} to be disabled
888 * \return 0 on success or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700889 */
890int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor);
891
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700892/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700893 * Sets the delivery rate of events in microseconds for the given sensor.
Peng Xu80df0162017-08-05 19:00:23 -0700894 *
895 * This function has to be called after {@link ASensorEventQueue_enableSensor}.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700896 * Note that this is a hint only, generally event will arrive at a higher
897 * rate. It is an error to set a rate inferior to the value returned by
898 * ASensor_getMinDelay().
Peng Xu80df0162017-08-05 19:00:23 -0700899 *
900 * \param queue {@link ASensorEventQueue} to which sensor event is delivered.
901 * \param sensor {@link ASensor} of which sampling rate to be updated.
902 * \param usec sensor sampling period (1/sampling rate) in microseconds
903 * \return 0 on sucess or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700904 */
905int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec);
906
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700907/**
Peng Xu80df0162017-08-05 19:00:23 -0700908 * Determine if a sensor event queue has pending event to be processed.
909 *
910 * \param queue {@link ASensorEventQueue} to be queried
911 * \return 1 if the queue has events; 0 if it does not have events;
912 * or a negative value if there is an error.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700913 */
914int ASensorEventQueue_hasEvents(ASensorEventQueue* queue);
915
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700916/**
Peng Xu80df0162017-08-05 19:00:23 -0700917 * Retrieve pending events in sensor event queue
918 *
919 * Retrieve next available events from the queue to a specified event array.
920 *
921 * \param queue {@link ASensorEventQueue} to get events from
gfan5d5faa42021-04-12 15:14:29 -0700922 * \param events pointer to an array of {@link ASensorEvent}.
Peng Xu80df0162017-08-05 19:00:23 -0700923 * \param count max number of event that can be filled into array event.
924 * \return number of events returned on success; negative error code when
925 * no events are pending or an error has occurred.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700926 *
927 * Examples:
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700928 *
Peng Xu80df0162017-08-05 19:00:23 -0700929 * ASensorEvent event;
930 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1);
931 *
932 * ASensorEvent eventBuffer[8];
933 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700934 *
935 */
Peng Xuda8385c2017-02-28 20:19:47 -0800936ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700937
Brian Stack65089d52019-01-11 10:52:07 -0800938/**
939 * Request that {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to be delivered on
940 * the given {@link ASensorEventQueue}.
941 *
gfan5d5faa42021-04-12 15:14:29 -0700942 * Sensor data events are always delivered to the {@link ASensorEventQueue}.
Brian Stack65089d52019-01-11 10:52:07 -0800943 *
944 * The {@link ASENSOR_TYPE_ADDITIONAL_INFO} events will be returned through
945 * {@link ASensorEventQueue_getEvents}. The client is responsible for checking
946 * {@link ASensorEvent#type} to determine the event type prior to handling of
947 * the event.
948 *
949 * The client must be tolerant of any value for
950 * {@link AAdditionalInfoEvent#type}, as new values may be defined in the future
951 * and may delivered to the client.
952 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700953 * Available since API level 29.
954 *
Brian Stack65089d52019-01-11 10:52:07 -0800955 * \param queue {@link ASensorEventQueue} to configure
956 * \param enable true to request {@link ASENSOR_TYPE_ADDITIONAL_INFO} events,
957 * false to stop receiving events
958 * \return 0 on success or a negative error code on failure
959 */
Elliott Hughes3d70e532019-10-29 08:59:39 -0700960int ASensorEventQueue_requestAdditionalInfoEvents(ASensorEventQueue* queue, bool enable) __INTRODUCED_IN(29);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700961
962/*****************************************************************************/
963
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700964/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700965 * Returns this sensor's name (non localized)
966 */
967const char* ASensor_getName(ASensor const* sensor);
968
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700969/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700970 * Returns this sensor's vendor's name (non localized)
971 */
972const char* ASensor_getVendor(ASensor const* sensor);
973
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700974/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700975 * Return this sensor's type
976 */
977int ASensor_getType(ASensor const* sensor);
978
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700979/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700980 * Returns this sensors's resolution
981 */
982float ASensor_getResolution(ASensor const* sensor);
983
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700984/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700985 * Returns the minimum delay allowed between events in microseconds.
986 * A value of zero means that this sensor doesn't report events at a
987 * constant rate, but rather only when a new data is available.
988 */
989int ASensor_getMinDelay(ASensor const* sensor);
990
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700991/**
Aravind Akella70018042014-04-07 22:52:37 +0000992 * Returns the maximum size of batches for this sensor. Batches will often be
993 * smaller, as the hardware fifo might be used for other sensors.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700994 *
995 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +0000996 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700997int ASensor_getFifoMaxEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +0000998
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700999/**
Aravind Akella70018042014-04-07 22:52:37 +00001000 * Returns the hardware batch fifo size reserved to this sensor.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001001 *
1002 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +00001003 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001004int ASensor_getFifoReservedEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +00001005
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001006/**
Aravind Akella70018042014-04-07 22:52:37 +00001007 * Returns this sensor's string type.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001008 *
1009 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +00001010 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001011const char* ASensor_getStringType(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +00001012
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001013/**
Aravind Akella0e025c52014-06-03 19:19:57 -07001014 * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001015 *
1016 * Available since API level 21.
Aravind Akella0e025c52014-06-03 19:19:57 -07001017 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001018int ASensor_getReportingMode(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella0e025c52014-06-03 19:19:57 -07001019
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001020/**
Aravind Akellab37ba392014-08-05 14:53:07 -07001021 * Returns true if this is a wake up sensor, false otherwise.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001022 *
1023 * Available since API level 21.
Aravind Akellab37ba392014-08-05 14:53:07 -07001024 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001025bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akellab37ba392014-08-05 14:53:07 -07001026
Peng Xu47cddca2017-02-15 23:31:22 -08001027/**
1028 * Test if sensor supports a certain type of direct channel.
1029 *
Elliott Hughes3d70e532019-10-29 08:59:39 -07001030 * Available since API level 26.
1031 *
Peng Xu47cddca2017-02-15 23:31:22 -08001032 * \param sensor a {@link ASensor} to denote the sensor to be checked.
1033 * \param channelType Channel type constant, either
gfan5d5faa42021-04-12 15:14:29 -07001034 * {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY}
Peng Xu47cddca2017-02-15 23:31:22 -08001035 * or {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER}.
1036 * \returns true if sensor supports the specified direct channel type.
1037 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001038bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType) __INTRODUCED_IN(26);
1039
Peng Xu47cddca2017-02-15 23:31:22 -08001040/**
Elliott Hughes3d70e532019-10-29 08:59:39 -07001041 * Get the highest direct rate level that a sensor supports.
1042 *
1043 * Available since API level 26.
Peng Xu47cddca2017-02-15 23:31:22 -08001044 *
1045 * \param sensor a {@link ASensor} to denote the sensor to be checked.
1046 *
1047 * \return a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor.
1048 * If return value is {@link ASENSOR_DIRECT_RATE_STOP}, it means the sensor
1049 * does not support direct report.
1050 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001051int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -08001052
Brian Stack8228fa72019-01-04 14:15:13 -08001053/**
1054 * Returns the sensor's handle.
1055 *
1056 * The handle identifies the sensor within the system and is included in the
gfanc150ea12021-04-14 09:27:55 -07001057 * sensor field of {@link ASensorEvent}, including those sent with type
Brian Stack8228fa72019-01-04 14:15:13 -08001058 * {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
1059 *
1060 * A sensor's handle is able to be used to map {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to the
1061 * sensor that generated the event.
1062 *
1063 * It is important to note that the value returned by {@link ASensor_getHandle} is not the same as
gfan5d5faa42021-04-12 15:14:29 -07001064 * the value returned by the Java API <a href="/reference/android/hardware/Sensor#getId()">
1065 * android.hardware.Sensor's getId()</a> and no mapping exists between the values.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001066 *
1067 * Available since API level 29.
Brian Stack8228fa72019-01-04 14:15:13 -08001068 */
Elliott Hughes3d70e532019-10-29 08:59:39 -07001069int ASensor_getHandle(ASensor const* sensor) __INTRODUCED_IN(29);
Brian Stack8228fa72019-01-04 14:15:13 -08001070
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001071#ifdef __cplusplus
1072};
1073#endif
1074
1075#endif // ANDROID_SENSOR_H
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001076
1077/** @} */