Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Steven Moreland | cefd01c | 2016-11-07 19:20:19 -0800 | [diff] [blame] | 17 | #include "convert.h" |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 18 | |
| 19 | #include <android-base/logging.h> |
| 20 | |
| 21 | namespace android { |
| 22 | namespace hardware { |
| 23 | namespace sensors { |
| 24 | namespace V1_0 { |
| 25 | namespace implementation { |
| 26 | |
| 27 | void convertFromSensor(const sensor_t &src, SensorInfo *dst) { |
| 28 | dst->name = src.name; |
| 29 | dst->vendor = src.vendor; |
| 30 | dst->version = src.version; |
| 31 | dst->sensorHandle = src.handle; |
| 32 | dst->type = (SensorType)src.type; |
| 33 | dst->maxRange = src.maxRange; |
| 34 | dst->resolution = src.resolution; |
| 35 | dst->power = src.power; |
| 36 | dst->minDelay = src.minDelay; |
| 37 | dst->fifoReservedEventCount = src.fifoReservedEventCount; |
| 38 | dst->fifoMaxEventCount = src.fifoMaxEventCount; |
| 39 | dst->typeAsString = src.stringType; |
| 40 | dst->requiredPermission = src.requiredPermission; |
| 41 | dst->maxDelay = src.maxDelay; |
| 42 | dst->flags = src.flags; |
| 43 | } |
| 44 | |
| 45 | void convertToSensor( |
| 46 | const ::android::hardware::sensors::V1_0::SensorInfo &src, |
| 47 | sensor_t *dst) { |
| 48 | dst->name = strdup(src.name.c_str()); |
| 49 | dst->vendor = strdup(src.vendor.c_str()); |
| 50 | dst->version = src.version; |
| 51 | dst->handle = src.sensorHandle; |
| 52 | dst->type = (int)src.type; |
| 53 | dst->maxRange = src.maxRange; |
| 54 | dst->resolution = src.resolution; |
| 55 | dst->power = src.power; |
| 56 | dst->minDelay = src.minDelay; |
| 57 | dst->fifoReservedEventCount = src.fifoReservedEventCount; |
| 58 | dst->fifoMaxEventCount = src.fifoMaxEventCount; |
| 59 | dst->stringType = strdup(src.typeAsString.c_str()); |
| 60 | dst->requiredPermission = strdup(src.requiredPermission.c_str()); |
| 61 | dst->maxDelay = src.maxDelay; |
| 62 | dst->flags = src.flags; |
| 63 | dst->reserved[0] = dst->reserved[1] = 0; |
| 64 | } |
| 65 | |
| 66 | void convertFromSensorEvent(const sensors_event_t &src, Event *dst) { |
| 67 | typedef ::android::hardware::sensors::V1_0::SensorType SensorType; |
| 68 | typedef ::android::hardware::sensors::V1_0::MetaDataEventType MetaDataEventType; |
| 69 | |
| 70 | dst->sensorHandle = src.sensor; |
| 71 | dst->sensorType = (SensorType)src.type; |
| 72 | dst->timestamp = src.timestamp; |
| 73 | |
| 74 | switch (dst->sensorType) { |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 75 | case SensorType::META_DATA: |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 76 | { |
| 77 | dst->u.meta.what = (MetaDataEventType)src.meta_data.what; |
Ashutosh Joshi | da270a0 | 2017-02-13 12:52:14 -0800 | [diff] [blame^] | 78 | // Legacy HALs contain the handle reference in the meta data field. |
| 79 | // Copy that over to the handle of the event. In legacy HALs this |
| 80 | // field was expected to be 0. |
| 81 | dst->sensorHandle = src.meta_data.sensor; |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 82 | break; |
| 83 | } |
| 84 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 85 | case SensorType::ACCELEROMETER: |
| 86 | case SensorType::MAGNETIC_FIELD: |
| 87 | case SensorType::ORIENTATION: |
| 88 | case SensorType::GYROSCOPE: |
| 89 | case SensorType::GRAVITY: |
| 90 | case SensorType::LINEAR_ACCELERATION: |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 91 | { |
| 92 | dst->u.vec3.x = src.acceleration.x; |
| 93 | dst->u.vec3.y = src.acceleration.y; |
| 94 | dst->u.vec3.z = src.acceleration.z; |
| 95 | dst->u.vec3.status = (SensorStatus)src.acceleration.status; |
| 96 | break; |
| 97 | } |
| 98 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 99 | case SensorType::ROTATION_VECTOR: |
| 100 | case SensorType::GAME_ROTATION_VECTOR: |
| 101 | case SensorType::GEOMAGNETIC_ROTATION_VECTOR: |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 102 | { |
| 103 | dst->u.vec4.x = src.data[0]; |
| 104 | dst->u.vec4.y = src.data[1]; |
| 105 | dst->u.vec4.z = src.data[2]; |
| 106 | dst->u.vec4.w = src.data[3]; |
| 107 | break; |
| 108 | } |
| 109 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 110 | case SensorType::MAGNETIC_FIELD_UNCALIBRATED: |
| 111 | case SensorType::GYROSCOPE_UNCALIBRATED: |
| 112 | case SensorType::ACCELEROMETER_UNCALIBRATED: |
| 113 | { |
| 114 | dst->u.uncal.x = src.uncalibrated_gyro.x_uncalib; |
| 115 | dst->u.uncal.y = src.uncalibrated_gyro.y_uncalib; |
| 116 | dst->u.uncal.z = src.uncalibrated_gyro.z_uncalib; |
| 117 | dst->u.uncal.x_bias = src.uncalibrated_gyro.x_bias; |
| 118 | dst->u.uncal.y_bias = src.uncalibrated_gyro.y_bias; |
| 119 | dst->u.uncal.z_bias = src.uncalibrated_gyro.z_bias; |
| 120 | break; |
| 121 | } |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 122 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 123 | case SensorType::DEVICE_ORIENTATION: |
| 124 | case SensorType::LIGHT: |
| 125 | case SensorType::PRESSURE: |
| 126 | case SensorType::TEMPERATURE: |
| 127 | case SensorType::PROXIMITY: |
| 128 | case SensorType::RELATIVE_HUMIDITY: |
| 129 | case SensorType::AMBIENT_TEMPERATURE: |
| 130 | case SensorType::SIGNIFICANT_MOTION: |
| 131 | case SensorType::STEP_DETECTOR: |
| 132 | case SensorType::TILT_DETECTOR: |
| 133 | case SensorType::WAKE_GESTURE: |
| 134 | case SensorType::GLANCE_GESTURE: |
| 135 | case SensorType::PICK_UP_GESTURE: |
| 136 | case SensorType::WRIST_TILT_GESTURE: |
| 137 | case SensorType::STATIONARY_DETECT: |
| 138 | case SensorType::MOTION_DETECT: |
| 139 | case SensorType::HEART_BEAT: |
| 140 | { |
| 141 | dst->u.scalar = src.data[0]; |
| 142 | break; |
| 143 | } |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 144 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 145 | case SensorType::STEP_COUNTER: |
| 146 | { |
| 147 | dst->u.stepCount = src.u64.step_counter; |
| 148 | break; |
| 149 | } |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 150 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 151 | case SensorType::HEART_RATE: |
| 152 | { |
| 153 | dst->u.heartRate.bpm = src.heart_rate.bpm; |
| 154 | dst->u.heartRate.status = (SensorStatus)src.heart_rate.status; |
| 155 | break; |
| 156 | } |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 157 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 158 | case SensorType::POSE_6DOF: // 15 floats |
| 159 | { |
| 160 | for (size_t i = 0; i < 15; ++i) { |
| 161 | dst->u.pose6DOF[i] = src.data[i]; |
| 162 | } |
| 163 | break; |
| 164 | } |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 165 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 166 | case SensorType::DYNAMIC_SENSOR_META: |
| 167 | { |
| 168 | dst->u.dynamic.connected = src.dynamic_sensor_meta.connected; |
| 169 | dst->u.dynamic.sensorHandle = src.dynamic_sensor_meta.handle; |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 170 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 171 | memcpy(dst->u.dynamic.uuid.data(), |
| 172 | src.dynamic_sensor_meta.uuid, |
| 173 | 16); |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 174 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 175 | break; |
| 176 | } |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 177 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 178 | case SensorType::ADDITIONAL_INFO: |
| 179 | { |
| 180 | ::android::hardware::sensors::V1_0::AdditionalInfo *dstInfo = |
| 181 | &dst->u.additional; |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 182 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 183 | const additional_info_event_t &srcInfo = src.additional_info; |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 184 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 185 | dstInfo->type = |
| 186 | (::android::hardware::sensors::V1_0::AdditionalInfoType) |
| 187 | srcInfo.type; |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 188 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 189 | dstInfo->serial = srcInfo.serial; |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 190 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 191 | CHECK_EQ(sizeof(dstInfo->u), sizeof(srcInfo.data_int32)); |
| 192 | memcpy(&dstInfo->u, srcInfo.data_int32, sizeof(srcInfo.data_int32)); |
| 193 | break; |
| 194 | } |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 195 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 196 | default: |
| 197 | { |
| 198 | CHECK_GE((int32_t)dst->sensorType, |
| 199 | (int32_t)SensorType::DEVICE_PRIVATE_BASE); |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 200 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 201 | memcpy(dst->u.data.data(), src.data, 16 * sizeof(float)); |
| 202 | break; |
| 203 | } |
| 204 | } |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | void convertToSensorEvent(const Event &src, sensors_event_t *dst) { |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 208 | dst->version = sizeof(sensors_event_t); |
| 209 | dst->sensor = src.sensorHandle; |
| 210 | dst->type = (int32_t)src.sensorType; |
| 211 | dst->reserved0 = 0; |
| 212 | dst->timestamp = src.timestamp; |
| 213 | dst->flags = 0; |
| 214 | dst->reserved1[0] = dst->reserved1[1] = dst->reserved1[2] = 0; |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 215 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 216 | switch (src.sensorType) { |
| 217 | case SensorType::META_DATA: |
| 218 | { |
Ashutosh Joshi | da270a0 | 2017-02-13 12:52:14 -0800 | [diff] [blame^] | 219 | // Legacy HALs expect the handle reference in the meta data field. |
| 220 | // Copy it over from the handle of the event. |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 221 | dst->meta_data.what = (int32_t)src.u.meta.what; |
Ashutosh Joshi | da270a0 | 2017-02-13 12:52:14 -0800 | [diff] [blame^] | 222 | dst->meta_data.sensor = src.sensorHandle; |
| 223 | // Set the sensor handle to 0 to maintain compatibility. |
| 224 | dst->sensor = 0; |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 225 | break; |
| 226 | } |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 227 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 228 | case SensorType::ACCELEROMETER: |
| 229 | case SensorType::MAGNETIC_FIELD: |
| 230 | case SensorType::ORIENTATION: |
| 231 | case SensorType::GYROSCOPE: |
| 232 | case SensorType::GRAVITY: |
| 233 | case SensorType::LINEAR_ACCELERATION: |
| 234 | { |
| 235 | dst->acceleration.x = src.u.vec3.x; |
| 236 | dst->acceleration.y = src.u.vec3.y; |
| 237 | dst->acceleration.z = src.u.vec3.z; |
| 238 | dst->acceleration.status = (int8_t)src.u.vec3.status; |
| 239 | break; |
| 240 | } |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 241 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 242 | case SensorType::ROTATION_VECTOR: |
| 243 | case SensorType::GAME_ROTATION_VECTOR: |
| 244 | case SensorType::GEOMAGNETIC_ROTATION_VECTOR: |
| 245 | { |
| 246 | dst->data[0] = src.u.vec4.x; |
| 247 | dst->data[1] = src.u.vec4.y; |
| 248 | dst->data[2] = src.u.vec4.z; |
| 249 | dst->data[3] = src.u.vec4.w; |
| 250 | break; |
| 251 | } |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 252 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 253 | case SensorType::MAGNETIC_FIELD_UNCALIBRATED: |
| 254 | case SensorType::GYROSCOPE_UNCALIBRATED: |
| 255 | case SensorType::ACCELEROMETER_UNCALIBRATED: |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 256 | { |
| 257 | dst->uncalibrated_gyro.x_uncalib = src.u.uncal.x; |
| 258 | dst->uncalibrated_gyro.y_uncalib = src.u.uncal.y; |
| 259 | dst->uncalibrated_gyro.z_uncalib = src.u.uncal.z; |
| 260 | dst->uncalibrated_gyro.x_bias = src.u.uncal.x_bias; |
| 261 | dst->uncalibrated_gyro.y_bias = src.u.uncal.y_bias; |
| 262 | dst->uncalibrated_gyro.z_bias = src.u.uncal.z_bias; |
| 263 | break; |
| 264 | } |
| 265 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 266 | case SensorType::DEVICE_ORIENTATION: |
| 267 | case SensorType::LIGHT: |
| 268 | case SensorType::PRESSURE: |
| 269 | case SensorType::TEMPERATURE: |
| 270 | case SensorType::PROXIMITY: |
| 271 | case SensorType::RELATIVE_HUMIDITY: |
| 272 | case SensorType::AMBIENT_TEMPERATURE: |
| 273 | case SensorType::SIGNIFICANT_MOTION: |
| 274 | case SensorType::STEP_DETECTOR: |
| 275 | case SensorType::TILT_DETECTOR: |
| 276 | case SensorType::WAKE_GESTURE: |
| 277 | case SensorType::GLANCE_GESTURE: |
| 278 | case SensorType::PICK_UP_GESTURE: |
| 279 | case SensorType::WRIST_TILT_GESTURE: |
| 280 | case SensorType::STATIONARY_DETECT: |
| 281 | case SensorType::MOTION_DETECT: |
| 282 | case SensorType::HEART_BEAT: |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 283 | { |
| 284 | dst->data[0] = src.u.scalar; |
| 285 | break; |
| 286 | } |
| 287 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 288 | case SensorType::STEP_COUNTER: |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 289 | { |
| 290 | dst->u64.step_counter = src.u.stepCount; |
| 291 | break; |
| 292 | } |
| 293 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 294 | case SensorType::HEART_RATE: |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 295 | { |
| 296 | dst->heart_rate.bpm = src.u.heartRate.bpm; |
| 297 | dst->heart_rate.status = (int8_t)src.u.heartRate.status; |
| 298 | break; |
| 299 | } |
| 300 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 301 | case SensorType::POSE_6DOF: // 15 floats |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 302 | { |
| 303 | for (size_t i = 0; i < 15; ++i) { |
| 304 | dst->data[i] = src.u.pose6DOF[i]; |
| 305 | } |
| 306 | break; |
| 307 | } |
| 308 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 309 | case SensorType::DYNAMIC_SENSOR_META: |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 310 | { |
| 311 | dst->dynamic_sensor_meta.connected = src.u.dynamic.connected; |
| 312 | dst->dynamic_sensor_meta.handle = src.u.dynamic.sensorHandle; |
| 313 | dst->dynamic_sensor_meta.sensor = NULL; // to be filled in later |
| 314 | |
| 315 | memcpy(dst->dynamic_sensor_meta.uuid, |
| 316 | src.u.dynamic.uuid.data(), |
| 317 | 16); |
| 318 | |
| 319 | break; |
| 320 | } |
| 321 | |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 322 | case SensorType::ADDITIONAL_INFO: |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 323 | { |
| 324 | const ::android::hardware::sensors::V1_0::AdditionalInfo &srcInfo = |
| 325 | src.u.additional; |
| 326 | |
| 327 | additional_info_event_t *dstInfo = &dst->additional_info; |
| 328 | dstInfo->type = (int32_t)srcInfo.type; |
| 329 | dstInfo->serial = srcInfo.serial; |
| 330 | |
| 331 | CHECK_EQ(sizeof(srcInfo.u), sizeof(dstInfo->data_int32)); |
| 332 | |
| 333 | memcpy(dstInfo->data_int32, |
| 334 | &srcInfo.u, |
| 335 | sizeof(dstInfo->data_int32)); |
| 336 | |
| 337 | break; |
| 338 | } |
| 339 | |
| 340 | default: |
| 341 | { |
| 342 | CHECK_GE((int32_t)src.sensorType, |
Peng Xu | 1f12c7a | 2017-01-11 11:08:45 -0800 | [diff] [blame] | 343 | (int32_t)SensorType::DEVICE_PRIVATE_BASE); |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 344 | |
| 345 | memcpy(dst->data, src.u.data.data(), 16 * sizeof(float)); |
| 346 | break; |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
Peng Xu | 89df2e7 | 2017-01-09 19:12:42 -0800 | [diff] [blame] | 351 | bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t *memOut) { |
| 352 | if (memOut == nullptr) { |
| 353 | return false; |
| 354 | } |
| 355 | |
| 356 | switch(memIn.type) { |
| 357 | case SharedMemType::ASHMEM: |
| 358 | memOut->type = SENSOR_DIRECT_MEM_TYPE_ASHMEM; |
| 359 | break; |
| 360 | case SharedMemType::GRALLOC: |
| 361 | memOut->type = SENSOR_DIRECT_MEM_TYPE_GRALLOC; |
| 362 | break; |
| 363 | default: |
| 364 | return false; |
| 365 | } |
| 366 | |
| 367 | switch(memIn.format) { |
| 368 | case SharedMemFormat::SENSORS_EVENT: |
| 369 | memOut->format = SENSOR_DIRECT_FMT_SENSORS_EVENT; |
| 370 | break; |
| 371 | default: |
| 372 | return false; |
| 373 | } |
| 374 | |
| 375 | memOut->size = memIn.size; |
| 376 | memOut->handle = memIn.memoryHandle; |
| 377 | return true; |
| 378 | } |
| 379 | |
| 380 | int convertFromRateLevel(RateLevel rate) { |
| 381 | switch(rate) { |
| 382 | case RateLevel::STOP: |
| 383 | return SENSOR_DIRECT_RATE_STOP; |
| 384 | case RateLevel::NORMAL: |
| 385 | return SENSOR_DIRECT_RATE_NORMAL; |
| 386 | case RateLevel::FAST: |
| 387 | return SENSOR_DIRECT_RATE_FAST; |
| 388 | case RateLevel::VERY_FAST: |
| 389 | return SENSOR_DIRECT_RATE_VERY_FAST; |
| 390 | default: |
| 391 | return -1; |
| 392 | } |
| 393 | } |
| 394 | |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 395 | } // namespace implementation |
| 396 | } // namespace V1_0 |
| 397 | } // namespace sensors |
| 398 | } // namespace hardware |
| 399 | } // namespace android |
| 400 | |