The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1 | /* |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 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 | |
| 17 | #ifndef ANDROID_SENSORS_INTERFACE_H |
| 18 | #define ANDROID_SENSORS_INTERFACE_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/cdefs.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <hardware/hardware.h> |
Mike Lockwood | 21b652f | 2009-05-22 10:05:48 -0400 | [diff] [blame] | 25 | #include <cutils/native_handle.h> |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 26 | |
Andreas Huber | 9219017 | 2016-10-10 13:18:52 -0700 | [diff] [blame] | 27 | #include "sensors-base.h" |
| 28 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 29 | __BEGIN_DECLS |
| 30 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 31 | /*****************************************************************************/ |
| 32 | |
| 33 | #define SENSORS_HEADER_VERSION 1 |
| 34 | #define SENSORS_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) |
| 35 | #define SENSORS_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, SENSORS_HEADER_VERSION) |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 36 | #define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION) |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 37 | #define SENSORS_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, SENSORS_HEADER_VERSION) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 38 | #define SENSORS_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION_2(1, 2, SENSORS_HEADER_VERSION) |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 39 | #define SENSORS_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION_2(1, 3, SENSORS_HEADER_VERSION) |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 40 | #define SENSORS_DEVICE_API_VERSION_1_4 HARDWARE_DEVICE_API_VERSION_2(1, 4, SENSORS_HEADER_VERSION) |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 41 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 42 | /** |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 43 | * Please see the Sensors section of source.android.com for an |
| 44 | * introduction to and detailed descriptions of Android sensor types: |
| 45 | * http://source.android.com/devices/sensors/index.html |
| 46 | */ |
| 47 | |
| 48 | /** |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 49 | * The id of this module |
| 50 | */ |
| 51 | #define SENSORS_HARDWARE_MODULE_ID "sensors" |
| 52 | |
| 53 | /** |
| 54 | * Name of the sensors device to open |
| 55 | */ |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 56 | #define SENSORS_HARDWARE_POLL "poll" |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Handles must be higher than SENSORS_HANDLE_BASE and must be unique. |
| 60 | * A Handle identifies a given sensors. The handle is used to activate |
| 61 | * and/or deactivate sensors. |
| 62 | * In this version of the API there can only be 256 handles. |
| 63 | */ |
| 64 | #define SENSORS_HANDLE_BASE 0 |
| 65 | #define SENSORS_HANDLE_BITS 8 |
| 66 | #define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS) |
| 67 | |
| 68 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 69 | /* |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 70 | * **** Deprecated ***** |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 71 | * flags for (*batch)() |
| 72 | * Availability: SENSORS_DEVICE_API_VERSION_1_0 |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 73 | * see (*batch)() documentation for details. |
| 74 | * Deprecated as of SENSORS_DEVICE_API_VERSION_1_3. |
| 75 | * WAKE_UP_* sensors replace WAKE_UPON_FIFO_FULL concept. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 76 | */ |
| 77 | enum { |
| 78 | SENSORS_BATCH_DRY_RUN = 0x00000001, |
| 79 | SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002 |
| 80 | }; |
| 81 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 82 | /* |
| 83 | * what field for meta_data_event_t |
| 84 | */ |
| 85 | enum { |
| 86 | /* a previous flush operation has completed */ |
Andreas Huber | 9219017 | 2016-10-10 13:18:52 -0700 | [diff] [blame] | 87 | // META_DATA_FLUSH_COMPLETE = 1, |
Mathias Agopian | af32a8d | 2013-08-06 20:33:38 -0700 | [diff] [blame] | 88 | META_DATA_VERSION /* always last, leave auto-assigned */ |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 91 | /* |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 92 | * The permission to use for body sensors (like heart rate monitors). |
| 93 | * See sensor types for more details on what sensors should require this |
| 94 | * permission. |
| 95 | */ |
| 96 | #define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS" |
| 97 | |
| 98 | /* |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 99 | * Availability: SENSORS_DEVICE_API_VERSION_1_4 |
Ashutosh Joshi | 050f2e4 | 2015-04-15 13:56:53 -0700 | [diff] [blame] | 100 | * Sensor HAL modes used in set_operation_mode method |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 101 | */ |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 102 | |
Peng Xu | d156299 | 2016-03-29 18:14:05 -0700 | [diff] [blame] | 103 | #define SENSOR_FLAG_MASK(nbit, shift) (((1<<(nbit))-1)<<(shift)) |
| 104 | #define SENSOR_FLAG_MASK_1(shift) SENSOR_FLAG_MASK(1, shift) |
| 105 | |
| 106 | /* |
| 107 | * Mask and shift for reporting mode sensor flags defined above. |
| 108 | */ |
| 109 | #define REPORTING_MODE_SHIFT (1) |
| 110 | #define REPORTING_MODE_NBIT (3) |
| 111 | #define REPORTING_MODE_MASK SENSOR_FLAG_MASK(REPORTING_MODE_NBIT, REPORTING_MODE_SHIFT) |
| 112 | // 0xE |
| 113 | |
| 114 | /* |
| 115 | * Mask and shift for data_injection mode sensor flags defined above. |
| 116 | */ |
| 117 | #define DATA_INJECTION_SHIFT (4) |
| 118 | #define DATA_INJECTION_MASK SENSOR_FLAG_MASK_1(DATA_INJECTION_SHIFT) //0x10 |
| 119 | |
| 120 | /* |
| 121 | * Mask and shift for dynamic sensor flag. |
| 122 | */ |
| 123 | #define DYNAMIC_SENSOR_SHIFT (5) |
| 124 | #define DYNAMIC_SENSOR_MASK SENSOR_FLAG_MASK_1(DYNAMIC_SENSOR_SHIFT) //0x20 |
| 125 | |
| 126 | /* |
| 127 | * Mask and shift for sensor additional information support. |
| 128 | */ |
| 129 | #define ADDITIONAL_INFO_SHIFT (6) |
| 130 | #define ADDITIONAL_INFO_MASK SENSOR_FLAG_MASK_1(ADDITIONAL_INFO_SHIFT) //0x40 |
| 131 | |
Peng Xu | 08a4dd9 | 2016-11-03 11:56:27 -0700 | [diff] [blame^] | 132 | /* |
| 133 | * Shift for sensor direct report support bits (3 bits denoting maximum rate level) |
| 134 | * @see enums SENSOR_DIRECT_RATE_* for definition of direct report rate level. |
| 135 | * @see SENSOR_FLAG_MASK_DIRECT_REPORT for mask |
| 136 | */ |
| 137 | #define SENSOR_FLAG_SHIFT_DIRECT_REPORT (7) |
| 138 | /* |
| 139 | * Shift for sensor direct channel support bit (2 bits representing direct channel supported) |
| 140 | * @see SENSOR_FLAG_DIRECT_CHANNEL_* for details. |
| 141 | */ |
| 142 | #define SENSOR_FLAG_SHIFT_DIRECT_CHANNEL (10) |
| 143 | |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 144 | #define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 145 | #define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 146 | #define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 147 | #define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 148 | #define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 149 | #define SENSOR_STRING_TYPE_LIGHT "android.sensor.light" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 150 | #define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 151 | #define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 152 | #define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 153 | #define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 154 | #define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 155 | #define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 156 | #define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 157 | #define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 158 | #define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 159 | #define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 160 | #define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 161 | #define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 162 | #define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 163 | #define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 164 | #define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector" |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 165 | #define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate" |
Aravind Akella | 9057e12 | 2014-07-28 18:01:37 -0700 | [diff] [blame] | 166 | #define SENSOR_STRING_TYPE_TILT_DETECTOR "android.sensor.tilt_detector" |
Etienne Le Grand | ba12312 | 2014-05-05 18:20:42 -0700 | [diff] [blame] | 167 | #define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture" |
Jeff Brown | 8df2feb | 2014-07-17 15:11:51 -0700 | [diff] [blame] | 168 | #define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture" |
Aravind Akella | 952471e | 2014-07-17 12:40:54 -0700 | [diff] [blame] | 169 | #define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture" |
Nick Vaccaro | adbfbb7 | 2015-01-13 12:14:28 -0800 | [diff] [blame] | 170 | #define SENSOR_STRING_TYPE_WRIST_TILT_GESTURE "android.sensor.wrist_tilt_gesture" |
Trevor Bunker | f8e7ed3 | 2016-01-08 10:22:23 -0800 | [diff] [blame] | 171 | #define SENSOR_STRING_TYPE_DEVICE_ORIENTATION "android.sensor.device_orientation" |
Ashutosh Joshi | ed021ea | 2016-01-14 22:28:24 -0800 | [diff] [blame] | 172 | #define SENSOR_STRING_TYPE_POSE_6DOF "android.sensor.pose_6dof" |
Ashutosh Joshi | cb96331 | 2016-01-25 18:48:57 -0800 | [diff] [blame] | 173 | #define SENSOR_STRING_TYPE_STATIONARY_DETECT "android.sensor.stationary_detect" |
Ashutosh Joshi | cb96331 | 2016-01-25 18:48:57 -0800 | [diff] [blame] | 174 | #define SENSOR_STRING_TYPE_MOTION_DETECT "android.sensor.motion_detect" |
Ashutosh Joshi | cb96331 | 2016-01-25 18:48:57 -0800 | [diff] [blame] | 175 | #define SENSOR_STRING_TYPE_HEART_BEAT "android.sensor.heart_beat" |
Peng Xu | e641ba9 | 2016-01-20 00:27:21 -0800 | [diff] [blame] | 176 | #define SENSOR_STRING_TYPE_DYNAMIC_SENSOR_META "android.sensor.dynamic_sensor_meta" |
Peng Xu | 0743a5c | 2016-01-21 17:30:02 -0800 | [diff] [blame] | 177 | #define SENSOR_STRING_TYPE_ADDITIONAL_INFO "android.sensor.additional_info" |
Nick Vaccaro | cfd950b | 2016-11-04 13:36:12 -0700 | [diff] [blame] | 178 | #define SENSOR_STRING_TYPE_LOW_LATENCY_OFFBODY_DETECT "android.sensor.low_latency_offbody" |
Peng Xu | 0743a5c | 2016-01-21 17:30:02 -0800 | [diff] [blame] | 179 | |
| 180 | /** |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 181 | * Values returned by the accelerometer in various locations in the universe. |
| 182 | * all values are in SI units (m/s^2) |
| 183 | */ |
| 184 | #define GRAVITY_SUN (275.0f) |
| 185 | #define GRAVITY_EARTH (9.80665f) |
| 186 | |
| 187 | /** Maximum magnetic field on Earth's surface */ |
| 188 | #define MAGNETIC_FIELD_EARTH_MAX (60.0f) |
| 189 | |
| 190 | /** Minimum magnetic field on Earth's surface */ |
| 191 | #define MAGNETIC_FIELD_EARTH_MIN (30.0f) |
| 192 | |
Peng Xu | e641ba9 | 2016-01-20 00:27:21 -0800 | [diff] [blame] | 193 | struct sensor_t; |
| 194 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 195 | /** |
| 196 | * sensor event data |
| 197 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 198 | typedef struct { |
| 199 | union { |
| 200 | float v[3]; |
| 201 | struct { |
| 202 | float x; |
| 203 | float y; |
| 204 | float z; |
| 205 | }; |
| 206 | struct { |
| 207 | float azimuth; |
| 208 | float pitch; |
| 209 | float roll; |
| 210 | }; |
| 211 | }; |
| 212 | int8_t status; |
| 213 | uint8_t reserved[3]; |
| 214 | } sensors_vec_t; |
| 215 | |
| 216 | /** |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 217 | * uncalibrated gyroscope and magnetometer event data |
| 218 | */ |
| 219 | typedef struct { |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 220 | union { |
| 221 | float uncalib[3]; |
| 222 | struct { |
| 223 | float x_uncalib; |
| 224 | float y_uncalib; |
| 225 | float z_uncalib; |
| 226 | }; |
| 227 | }; |
| 228 | union { |
| 229 | float bias[3]; |
| 230 | struct { |
| 231 | float x_bias; |
| 232 | float y_bias; |
| 233 | float z_bias; |
| 234 | }; |
| 235 | }; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 236 | } uncalibrated_event_t; |
| 237 | |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 238 | /** |
| 239 | * Meta data event data |
| 240 | */ |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 241 | typedef struct meta_data_event { |
| 242 | int32_t what; |
| 243 | int32_t sensor; |
| 244 | } meta_data_event_t; |
| 245 | |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 246 | /** |
Peng Xu | e641ba9 | 2016-01-20 00:27:21 -0800 | [diff] [blame] | 247 | * Dynamic sensor meta event. See the description of SENSOR_TYPE_DYNAMIC_SENSOR_META type for |
| 248 | * details. |
| 249 | */ |
| 250 | typedef struct dynamic_sensor_meta_event { |
Peng Xu | e20707a | 2016-01-27 18:26:10 -0800 | [diff] [blame] | 251 | int32_t connected; |
| 252 | int32_t handle; |
Peng Xu | e641ba9 | 2016-01-20 00:27:21 -0800 | [diff] [blame] | 253 | const struct sensor_t * sensor; // should be NULL if connected == false |
Peng Xu | 69b5dba | 2016-04-22 22:34:51 -0700 | [diff] [blame] | 254 | uint8_t uuid[16]; // UUID of a dynamic sensor (using RFC 4122 byte order) |
| 255 | // For UUID 12345678-90AB-CDEF-1122-334455667788 the uuid field |
| 256 | // should be initialized as: |
| 257 | // {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x11, ...} |
Peng Xu | e641ba9 | 2016-01-20 00:27:21 -0800 | [diff] [blame] | 258 | } dynamic_sensor_meta_event_t; |
| 259 | |
| 260 | /** |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 261 | * Heart rate event data |
| 262 | */ |
| 263 | typedef struct { |
| 264 | // Heart rate in beats per minute. |
| 265 | // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT |
| 266 | float bpm; |
| 267 | // Status of the sensor for this reading. Set to one SENSOR_STATUS_... |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 268 | // Note that this value should only be set for sensors that explicitly define |
| 269 | // the meaning of this field. This field is not piped through the framework |
| 270 | // for other sensors. |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 271 | int8_t status; |
| 272 | } heart_rate_event_t; |
| 273 | |
Peng Xu | 0743a5c | 2016-01-21 17:30:02 -0800 | [diff] [blame] | 274 | typedef struct { |
| 275 | int32_t type; // type of payload data, see additional_info_type_t |
| 276 | int32_t serial; // sequence number of this frame for this type |
| 277 | union { |
| 278 | // for each frame, a single data type, either int32_t or float, should be used. |
| 279 | int32_t data_int32[14]; |
| 280 | float data_float[14]; |
| 281 | }; |
| 282 | } additional_info_event_t; |
| 283 | |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 284 | /** |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 285 | * Union of the various types of sensor data |
| 286 | * that can be returned. |
| 287 | */ |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 288 | typedef struct sensors_event_t { |
| 289 | /* must be sizeof(struct sensors_event_t) */ |
| 290 | int32_t version; |
| 291 | |
| 292 | /* sensor identifier */ |
| 293 | int32_t sensor; |
| 294 | |
| 295 | /* sensor type */ |
| 296 | int32_t type; |
| 297 | |
| 298 | /* reserved */ |
| 299 | int32_t reserved0; |
| 300 | |
| 301 | /* time is in nanosecond */ |
| 302 | int64_t timestamp; |
| 303 | |
| 304 | union { |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 305 | union { |
| 306 | float data[16]; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 307 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 308 | /* acceleration values are in meter per second per second (m/s^2) */ |
| 309 | sensors_vec_t acceleration; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 310 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 311 | /* magnetic vector values are in micro-Tesla (uT) */ |
| 312 | sensors_vec_t magnetic; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 313 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 314 | /* orientation values are in degrees */ |
| 315 | sensors_vec_t orientation; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 316 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 317 | /* gyroscope values are in rad/s */ |
| 318 | sensors_vec_t gyro; |
Makarand Karvekar | 3120b58 | 2010-08-11 15:10:10 -0700 | [diff] [blame] | 319 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 320 | /* temperature is in degrees centigrade (Celsius) */ |
| 321 | float temperature; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 322 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 323 | /* distance in centimeters */ |
| 324 | float distance; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 325 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 326 | /* light in SI lux units */ |
| 327 | float light; |
Mathias Agopian | 1832f55 | 2010-07-29 15:22:30 -0700 | [diff] [blame] | 328 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 329 | /* pressure in hectopascal (hPa) */ |
| 330 | float pressure; |
Urs Fleisch | d2ed15a | 2010-12-29 17:00:33 +0100 | [diff] [blame] | 331 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 332 | /* relative humidity in percent */ |
| 333 | float relative_humidity; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 334 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 335 | /* uncalibrated gyroscope values are in rad/s */ |
| 336 | uncalibrated_event_t uncalibrated_gyro; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 337 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 338 | /* uncalibrated magnetometer values are in micro-Teslas */ |
| 339 | uncalibrated_event_t uncalibrated_magnetic; |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 340 | |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 341 | /* heart rate data containing value in bpm and status */ |
| 342 | heart_rate_event_t heart_rate; |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 343 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 344 | /* this is a special event. see SENSOR_TYPE_META_DATA above. |
| 345 | * sensors_meta_data_event_t events are all reported with a type of |
| 346 | * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero. |
| 347 | */ |
| 348 | meta_data_event_t meta_data; |
Peng Xu | e641ba9 | 2016-01-20 00:27:21 -0800 | [diff] [blame] | 349 | |
| 350 | /* dynamic sensor meta event. See SENSOR_TYPE_DYNAMIC_SENSOR_META type for details */ |
| 351 | dynamic_sensor_meta_event_t dynamic_sensor_meta; |
Peng Xu | 0743a5c | 2016-01-21 17:30:02 -0800 | [diff] [blame] | 352 | |
| 353 | /* |
| 354 | * special additional sensor information frame, see |
| 355 | * SENSOR_TYPE_ADDITIONAL_INFO for details. |
| 356 | */ |
| 357 | additional_info_event_t additional_info; |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 358 | }; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 359 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 360 | union { |
| 361 | uint64_t data[8]; |
| 362 | |
| 363 | /* step-counter */ |
| 364 | uint64_t step_counter; |
| 365 | } u64; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 366 | }; |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 367 | |
| 368 | /* Reserved flags for internal use. Set to zero. */ |
| 369 | uint32_t flags; |
| 370 | |
| 371 | uint32_t reserved1[3]; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 372 | } sensors_event_t; |
| 373 | |
| 374 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 375 | /* see SENSOR_TYPE_META_DATA */ |
| 376 | typedef sensors_event_t sensors_meta_data_event_t; |
| 377 | |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 378 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 379 | /** |
| 380 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 381 | * and the fields of this data structure must begin with hw_module_t |
| 382 | * followed by module specific information. |
| 383 | */ |
| 384 | struct sensors_module_t { |
| 385 | struct hw_module_t common; |
| 386 | |
| 387 | /** |
| 388 | * Enumerate all available sensors. The list is returned in "list". |
Colin Cross | 867e1e3 | 2016-10-06 16:44:46 -0700 | [diff] [blame] | 389 | * return number of sensors in the list |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 390 | */ |
| 391 | int (*get_sensors_list)(struct sensors_module_t* module, |
| 392 | struct sensor_t const** list); |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 393 | |
| 394 | /** |
| 395 | * Place the module in a specific mode. The following modes are defined |
| 396 | * |
Ashutosh Joshi | 050f2e4 | 2015-04-15 13:56:53 -0700 | [diff] [blame] | 397 | * 0 - Normal operation. Default state of the module. |
Peng Xu | 0743a5c | 2016-01-21 17:30:02 -0800 | [diff] [blame] | 398 | * 1 - Loopback mode. Data is injected for the supported |
Ashutosh Joshi | 050f2e4 | 2015-04-15 13:56:53 -0700 | [diff] [blame] | 399 | * sensors by the sensor service in this mode. |
Colin Cross | 867e1e3 | 2016-10-06 16:44:46 -0700 | [diff] [blame] | 400 | * return 0 on success |
Ashutosh Joshi | 050f2e4 | 2015-04-15 13:56:53 -0700 | [diff] [blame] | 401 | * -EINVAL if requested mode is not supported |
Aravind Akella | c7f5413 | 2015-06-22 18:26:54 -0700 | [diff] [blame] | 402 | * -EPERM if operation is not allowed |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 403 | */ |
| 404 | int (*set_operation_mode)(unsigned int mode); |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 405 | }; |
| 406 | |
| 407 | struct sensor_t { |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 408 | |
| 409 | /* Name of this sensor. |
| 410 | * All sensors of the same "type" must have a different "name". |
| 411 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 412 | const char* name; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 413 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 414 | /* vendor of the hardware part */ |
| 415 | const char* vendor; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 416 | |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 417 | /* version of the hardware part + driver. The value of this field |
| 418 | * must increase when the driver is updated in a way that changes the |
| 419 | * output of this sensor. This is important for fused sensors when the |
| 420 | * fusion algorithm is updated. |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 421 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 422 | int version; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 423 | |
| 424 | /* handle that identifies this sensors. This handle is used to reference |
| 425 | * this sensor throughout the HAL API. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 426 | */ |
| 427 | int handle; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 428 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 429 | /* this sensor's type. */ |
| 430 | int type; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 431 | |
| 432 | /* maximum range of this sensor's value in SI units */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 433 | float maxRange; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 434 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 435 | /* smallest difference between two values reported by this sensor */ |
| 436 | float resolution; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 437 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 438 | /* rough estimate of this sensor's power consumption in mA */ |
| 439 | float power; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 440 | |
Aravind Akella | c841efd | 2014-06-03 19:21:35 -0700 | [diff] [blame] | 441 | /* this value depends on the reporting mode: |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 442 | * |
| 443 | * continuous: minimum sample period allowed in microseconds |
| 444 | * on-change : 0 |
| 445 | * one-shot :-1 |
| 446 | * special : 0, unless otherwise noted |
| 447 | */ |
Mathias Agopian | 1511e20 | 2010-07-29 15:33:22 -0700 | [diff] [blame] | 448 | int32_t minDelay; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 449 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 450 | /* number of events reserved for this sensor in the batch mode FIFO. |
| 451 | * If there is a dedicated FIFO for this sensor, then this is the |
| 452 | * size of this FIFO. If the FIFO is shared with other sensors, |
| 453 | * this is the size reserved for that sensor and it can be zero. |
| 454 | */ |
| 455 | uint32_t fifoReservedEventCount; |
| 456 | |
| 457 | /* maximum number of events of this sensor that could be batched. |
| 458 | * This is especially relevant when the FIFO is shared between |
| 459 | * several sensors; this value is then set to the size of that FIFO. |
| 460 | */ |
| 461 | uint32_t fifoMaxEventCount; |
| 462 | |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 463 | /* type of this sensor as a string. Set to corresponding |
| 464 | * SENSOR_STRING_TYPE_*. |
| 465 | * When defining an OEM specific sensor or sensor manufacturer specific |
| 466 | * sensor, use your reserve domain name as a prefix. |
| 467 | * ex: com.google.glass.onheaddetector |
| 468 | * For sensors of known type, the android framework might overwrite this |
| 469 | * string automatically. |
| 470 | */ |
| 471 | const char* stringType; |
| 472 | |
| 473 | /* permission required to see this sensor, register to it and receive data. |
| 474 | * Set to "" if no permission is required. Some sensor types like the |
| 475 | * heart rate monitor have a mandatory require_permission. |
| 476 | * For sensors that always require a specific permission, like the heart |
| 477 | * rate monitor, the android framework might overwrite this string |
| 478 | * automatically. |
| 479 | */ |
| 480 | const char* requiredPermission; |
| 481 | |
Aravind Akella | 110d2f2 | 2014-09-04 15:36:31 -0700 | [diff] [blame] | 482 | /* This value is defined only for continuous mode and on-change sensors. It is the delay between |
| 483 | * two sensor events corresponding to the lowest frequency that this sensor supports. When lower |
| 484 | * frequencies are requested through batch()/setDelay() the events will be generated at this |
| 485 | * frequency instead. It can be used by the framework or applications to estimate when the batch |
| 486 | * FIFO may be full. |
Aravind Akella | c841efd | 2014-06-03 19:21:35 -0700 | [diff] [blame] | 487 | * |
| 488 | * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds. |
Aravind Akella | 110d2f2 | 2014-09-04 15:36:31 -0700 | [diff] [blame] | 489 | * continuous, on-change: maximum sampling period allowed in microseconds. |
| 490 | * one-shot, special : 0 |
Aravind Akella | c841efd | 2014-06-03 19:21:35 -0700 | [diff] [blame] | 491 | * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit |
| 492 | * on 64 bit architectures only for binary compatibility reasons. |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 493 | * Availability: SENSORS_DEVICE_API_VERSION_1_3 |
| 494 | */ |
| 495 | #ifdef __LP64__ |
| 496 | int64_t maxDelay; |
| 497 | #else |
| 498 | int32_t maxDelay; |
| 499 | #endif |
| 500 | |
Aravind Akella | c841efd | 2014-06-03 19:21:35 -0700 | [diff] [blame] | 501 | /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here. |
| 502 | * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons. |
| 503 | * Availability: SENSORS_DEVICE_API_VERSION_1_3 |
| 504 | */ |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 505 | #ifdef __LP64__ |
| 506 | uint64_t flags; |
| 507 | #else |
| 508 | uint32_t flags; |
| 509 | #endif |
| 510 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 511 | /* reserved fields, must be zero */ |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 512 | void* reserved[2]; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 513 | }; |
| 514 | |
Peng Xu | 08a4dd9 | 2016-11-03 11:56:27 -0700 | [diff] [blame^] | 515 | /** |
| 516 | * Shared memory information for a direct channel |
| 517 | */ |
| 518 | struct sensors_direct_mem_t { |
| 519 | int type; // enum SENSOR_DIRECT_MEM_... |
| 520 | int format; // enum SENSOR_DIRECT_FMT_... |
| 521 | size_t size; // size of the memory region, in bytes |
| 522 | const struct native_handle *handle; // shared memory handle, which is interpreted differently |
| 523 | // depending on type |
| 524 | }; |
| 525 | |
| 526 | /** |
| 527 | * Direct channel report configuration |
| 528 | */ |
| 529 | struct sensors_direct_cfg_t { |
| 530 | int rate_level; // enum SENSOR_DIRECT_RATE_... |
| 531 | }; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 532 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 533 | /* |
| 534 | * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1 |
| 535 | * and is present for backward binary and source compatibility. |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 536 | * See the Sensors HAL interface section for complete descriptions of the |
| 537 | * following functions: |
| 538 | * http://source.android.com/devices/sensors/index.html#hal |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 539 | */ |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 540 | struct sensors_poll_device_t { |
| 541 | struct hw_device_t common; |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 542 | int (*activate)(struct sensors_poll_device_t *dev, |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 543 | int sensor_handle, int enabled); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 544 | int (*setDelay)(struct sensors_poll_device_t *dev, |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 545 | int sensor_handle, int64_t sampling_period_ns); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 546 | int (*poll)(struct sensors_poll_device_t *dev, |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 547 | sensors_event_t* data, int count); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 548 | }; |
| 549 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 550 | /* |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 551 | * struct sensors_poll_device_1 is used in HAL versions >= SENSORS_DEVICE_API_VERSION_1_0 |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 552 | */ |
| 553 | typedef struct sensors_poll_device_1 { |
| 554 | union { |
| 555 | /* sensors_poll_device_1 is compatible with sensors_poll_device_t, |
| 556 | * and can be down-cast to it |
| 557 | */ |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 558 | struct sensors_poll_device_t v0; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 559 | |
| 560 | struct { |
| 561 | struct hw_device_t common; |
| 562 | |
Peng Xu | aaeeaa4 | 2016-10-05 14:56:54 -0700 | [diff] [blame] | 563 | /* Activate/de-activate one sensor. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 564 | * |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 565 | * sensor_handle is the handle of the sensor to change. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 566 | * enabled set to 1 to enable, or 0 to disable the sensor. |
| 567 | * |
Peng Xu | aaeeaa4 | 2016-10-05 14:56:54 -0700 | [diff] [blame] | 568 | * After sensor de-activation, existing sensor events that have not |
| 569 | * been picked up by poll() should be abandoned immediately so that |
| 570 | * subsequent activation will not get stale sensor events (events |
| 571 | * that is generated prior to the latter activation). |
| 572 | * |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 573 | * Return 0 on success, negative errno code otherwise. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 574 | */ |
| 575 | int (*activate)(struct sensors_poll_device_t *dev, |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 576 | int sensor_handle, int enabled); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 577 | |
| 578 | /** |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 579 | * Set the events's period in nanoseconds for a given sensor. |
| 580 | * If sampling_period_ns > max_delay it will be truncated to |
| 581 | * max_delay and if sampling_period_ns < min_delay it will be |
| 582 | * replaced by min_delay. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 583 | */ |
| 584 | int (*setDelay)(struct sensors_poll_device_t *dev, |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 585 | int sensor_handle, int64_t sampling_period_ns); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 586 | |
| 587 | /** |
Peng Xu | 355e3f6 | 2016-07-19 15:11:53 -0700 | [diff] [blame] | 588 | * Write an array of sensor_event_t to data. The size of the |
| 589 | * available buffer is specified by count. Returns number of |
| 590 | * valid sensor_event_t. |
| 591 | * |
| 592 | * This function should block if there is no sensor event |
| 593 | * available when being called. Thus, return value should always be |
| 594 | * positive. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 595 | */ |
| 596 | int (*poll)(struct sensors_poll_device_t *dev, |
| 597 | sensors_event_t* data, int count); |
| 598 | }; |
| 599 | }; |
| 600 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 601 | |
| 602 | /* |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 603 | * Sets a sensor’s parameters, including sampling frequency and maximum |
| 604 | * report latency. This function can be called while the sensor is |
| 605 | * activated, in which case it must not cause any sensor measurements to |
| 606 | * be lost: transitioning from one sampling rate to the other cannot cause |
| 607 | * lost events, nor can transitioning from a high maximum report latency to |
| 608 | * a low maximum report latency. |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 609 | * See the Batching sensor results page for details: |
| 610 | * http://source.android.com/devices/sensors/batching.html |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 611 | */ |
| 612 | int (*batch)(struct sensors_poll_device_1* dev, |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 613 | int sensor_handle, int flags, int64_t sampling_period_ns, |
| 614 | int64_t max_report_latency_ns); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 615 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 616 | /* |
| 617 | * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t) |
| 618 | * to the end of the "batch mode" FIFO for the specified sensor and flushes |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 619 | * the FIFO. |
| 620 | * If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero), |
Aravind Akella | c841efd | 2014-06-03 19:21:35 -0700 | [diff] [blame] | 621 | * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 622 | * event stream. This applies to all sensors other than one-shot sensors. |
| 623 | * If the sensor is a one-shot sensor, flush must return -EINVAL and not generate |
| 624 | * any flush complete metadata. |
Aravind Akella | a7f2cda | 2014-08-21 16:31:14 -0700 | [diff] [blame] | 625 | * If the sensor is not active at the time flush() is called, flush() should return |
| 626 | * -EINVAL. |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 627 | */ |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 628 | int (*flush)(struct sensors_poll_device_1* dev, int sensor_handle); |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 629 | |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 630 | /* |
Ashutosh Joshi | 050f2e4 | 2015-04-15 13:56:53 -0700 | [diff] [blame] | 631 | * Inject a single sensor sample to be to this device. |
| 632 | * data points to the sensor event to be injected |
Colin Cross | 867e1e3 | 2016-10-06 16:44:46 -0700 | [diff] [blame] | 633 | * return 0 on success |
Aravind Akella | c7f5413 | 2015-06-22 18:26:54 -0700 | [diff] [blame] | 634 | * -EPERM if operation is not allowed |
Ashutosh Joshi | 050f2e4 | 2015-04-15 13:56:53 -0700 | [diff] [blame] | 635 | * -EINVAL if sensor event cannot be injected |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 636 | */ |
| 637 | int (*inject_sensor_data)(struct sensors_poll_device_1 *dev, const sensors_event_t *data); |
| 638 | |
Peng Xu | 08a4dd9 | 2016-11-03 11:56:27 -0700 | [diff] [blame^] | 639 | /* |
| 640 | * Register/unregister direct report channel. |
| 641 | * |
| 642 | * A HAL declares support for direct report by setting non-NULL values for both |
| 643 | * register_direct_channel and config_direct_report. |
| 644 | * |
| 645 | * This function has two operation modes: |
| 646 | * |
| 647 | * Register: mem != NULL, register a channel using supplied shared memory information. By the |
| 648 | * time this function returns, sensors must finish initializing shared memory content |
| 649 | * (format dependent, see SENSOR_DIRECT_FMT_*). |
| 650 | * Parameters: |
| 651 | * mem points to a valid struct sensors_direct_mem_t. |
| 652 | * channel_handle is ignored. |
| 653 | * Return value: |
| 654 | * A handle of channel (>0) when success, which later can be referred in |
| 655 | * unregister or config_direct_report call, or error code (<0) if failed |
| 656 | * Unregister: mem == NULL, unregister a previously registered channel. |
| 657 | * Parameters: |
| 658 | * mem set to NULL |
| 659 | * channel_handle contains handle of channel to be unregistered |
| 660 | * Return value: |
| 661 | * 0, even if the channel_handle is invalid, in which case it will be a no-op. |
| 662 | */ |
| 663 | int (*register_direct_channel)(struct sensors_poll_device_1 *dev, |
| 664 | const struct sensors_direct_mem_t* mem, int channel_handle); |
| 665 | |
| 666 | /* |
| 667 | * Configure direct sensor event report in direct channel. |
| 668 | * |
| 669 | * Start, modify rate or stop direct report of a sensor in a certain direct channel. A special |
| 670 | * case is setting sensor handle -1 to stop means to stop all active sensor report on the |
| 671 | * channel specified. |
| 672 | * |
| 673 | * A HAL declares support for direct report by setting non-NULL values for both |
| 674 | * register_direct_channel and config_direct_report. |
| 675 | * |
| 676 | * Parameters: |
| 677 | * sensor_handle sensor to be configured. The sensor has to support direct report |
| 678 | * mode by setting flags of sensor_t. Also, direct report mode is only |
| 679 | * defined for continuous reporting mode sensors. |
| 680 | * channel_handle channel handle to be configured. |
| 681 | * config direct report parameters, see sensor_direct_cfg_t. |
| 682 | * Return value: |
| 683 | * - when sensor is started or sensor rate level is changed: return positive identifier of |
| 684 | * sensor in specified channel if successful, otherwise return negative error code. |
| 685 | * - when sensor is stopped: return 0 for success or negative error code for failure. |
| 686 | */ |
| 687 | int (*config_direct_report)(struct sensors_poll_device_1 *dev, |
| 688 | int sensor_handle, int channel_handle, const struct sensors_direct_cfg_t *config); |
| 689 | |
| 690 | /* |
| 691 | * Reserved for future use. |
| 692 | */ |
| 693 | void (*reserved_procs[5])(void); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 694 | |
| 695 | } sensors_poll_device_1_t; |
| 696 | |
| 697 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 698 | /** convenience API for opening and closing a device */ |
| 699 | |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 700 | static inline int sensors_open(const struct hw_module_t* module, |
| 701 | struct sensors_poll_device_t** device) { |
| 702 | return module->methods->open(module, |
Colin Cross | cc8d9f9 | 2016-10-06 16:44:23 -0700 | [diff] [blame] | 703 | SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device)); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | static inline int sensors_close(struct sensors_poll_device_t* device) { |
| 707 | return device->common.close(&device->common); |
| 708 | } |
| 709 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 710 | static inline int sensors_open_1(const struct hw_module_t* module, |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 711 | sensors_poll_device_1_t** device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 712 | return module->methods->open(module, |
Colin Cross | cc8d9f9 | 2016-10-06 16:44:23 -0700 | [diff] [blame] | 713 | SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device)); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 714 | } |
| 715 | |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 716 | static inline int sensors_close_1(sensors_poll_device_1_t* device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 717 | return device->common.close(&device->common); |
| 718 | } |
| 719 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 720 | __END_DECLS |
| 721 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 722 | #endif // ANDROID_SENSORS_INTERFACE_H |