1 /* 2 __ 3 / _| 4 __ _ _ _ _ __ ___ _ __ __ _ | |_ ___ ___ ___ 5 / _` | | | | '__/ _ \| '__/ _` | | _/ _ \/ __/ __| 6 | (_| | |_| | | | (_) | | | (_| | | || (_) \__ \__ \ 7 \__,_|\__,_|_| \___/|_| \__,_| |_| \___/|___/___/ 8 9 Copyright (C) 2010 The Android Open Source Project. 10 Copyright (C) 2018-2019 Aurora Free Open Source Software. 11 12 This file is part of the Aurora Free Open Source Software. This 13 organization promote free and open source software that you can 14 redistribute and/or modify under the terms of the GNU Lesser General 15 Public License Version 3 as published by the Free Software Foundation or 16 (at your option) any later version approved by the Aurora Free Open Source 17 Software Organization. The license is available in the package root path 18 as 'LICENSE' file. Please review the following information to ensure the 19 GNU Lesser General Public License version 3 requirements will be met: 20 https://www.gnu.org/licenses/lgpl.html . 21 22 Alternatively, this file may be used under the terms of the GNU General 23 Public License version 3 or later as published by the Free Software 24 Foundation. Please review the following information to ensure the GNU 25 General Public License requirements will be met: 26 https://www.gnu.org/licenses/gpl-3.0.html. 27 28 NOTE: All products, services or anything associated to trademarks and 29 service marks used or referenced on this file are the property of their 30 respective companies/owners or its subsidiaries. Other names and brands 31 may be claimed as the property of others. 32 33 For more info about intellectual property visit: aurorafoss.org or 34 directly send an email to: contact (at) aurorafoss.org . 35 36 This file has bindings for an existing code, part of The Android Open Source 37 Project implementation. Check it out at android.googlesource.com . 38 */ 39 40 module aurorafw.android.platform.sensor; 41 42 /** 43 * @addtogroup Sensor 44 * @{ 45 */ 46 47 /** 48 * @file aurorafw/android/platform/sensor.d 49 */ 50 51 import core.stdc.math; 52 import core.sys.posix.sys.types; 53 54 version (Android): 55 extern (C): 56 @system: 57 nothrow: 58 @nogc: 59 60 /****************************************************************** 61 * 62 * IMPORTANT NOTICE: 63 * 64 * This file is part of Android's set of stable system headers 65 * exposed by the Android NDK (Native Development Kit). 66 * 67 * Third-party source AND binary code relies on the definitions 68 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. 69 * 70 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) 71 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS 72 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY 73 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES 74 */ 75 76 /** 77 * Structures and functions to receive and process sensor events in 78 * native code. 79 * 80 */ 81 82 struct AHardwareBuffer; 83 84 enum ASENSOR_RESOLUTION_INVALID = nanf(""); 85 enum ASENSOR_FIFO_COUNT_INVALID = -1; 86 enum ASENSOR_DELAY_INVALID = INT32_MIN; 87 88 /* (Keep in sync with hardware/sensors-base.h and Sensor.java.) */ 89 90 /** 91 * Sensor types. 92 * 93 * See 94 * [android.hardware.SensorEvent#values](https://developer.android.com/reference/android/hardware/SensorEvent.html#values) 95 * for detailed explanations of the data returned for each of these types. 96 */ 97 enum 98 { 99 /** 100 * Invalid sensor type. Returned by {@link ASensor_getType} as error value. 101 */ 102 ASENSOR_TYPE_INVALID = -1, 103 /** 104 * {@link ASENSOR_TYPE_ACCELEROMETER} 105 * reporting-mode: continuous 106 * 107 * All values are in SI units (m/s^2) and measure the acceleration of the 108 * device minus the force of gravity. 109 */ 110 ASENSOR_TYPE_ACCELEROMETER = 1, 111 /** 112 * {@link ASENSOR_TYPE_MAGNETIC_FIELD} 113 * reporting-mode: continuous 114 * 115 * All values are in micro-Tesla (uT) and measure the geomagnetic 116 * field in the X, Y and Z axis. 117 */ 118 ASENSOR_TYPE_MAGNETIC_FIELD = 2, 119 /** 120 * {@link ASENSOR_TYPE_GYROSCOPE} 121 * reporting-mode: continuous 122 * 123 * All values are in radians/second and measure the rate of rotation 124 * around the X, Y and Z axis. 125 */ 126 ASENSOR_TYPE_GYROSCOPE = 4, 127 /** 128 * {@link ASENSOR_TYPE_LIGHT} 129 * reporting-mode: on-change 130 * 131 * The light sensor value is returned in SI lux units. 132 */ 133 ASENSOR_TYPE_LIGHT = 5, 134 /** 135 * {@link ASENSOR_TYPE_PRESSURE} 136 * 137 * The pressure sensor value is returned in hPa (millibar). 138 */ 139 ASENSOR_TYPE_PRESSURE = 6, 140 /** 141 * {@link ASENSOR_TYPE_PROXIMITY} 142 * reporting-mode: on-change 143 * 144 * The proximity sensor which turns the screen off and back on during calls is the 145 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing 146 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag 147 * SENSOR_FLAG_WAKE_UP. 148 * The value corresponds to the distance to the nearest object in centimeters. 149 */ 150 ASENSOR_TYPE_PROXIMITY = 8, 151 /** 152 * {@link ASENSOR_TYPE_GRAVITY} 153 * 154 * All values are in SI units (m/s^2) and measure the direction and 155 * magnitude of gravity. When the device is at rest, the output of 156 * the gravity sensor should be identical to that of the accelerometer. 157 */ 158 ASENSOR_TYPE_GRAVITY = 9, 159 /** 160 * {@link ASENSOR_TYPE_LINEAR_ACCELERATION} 161 * reporting-mode: continuous 162 * 163 * All values are in SI units (m/s^2) and measure the acceleration of the 164 * device not including the force of gravity. 165 */ 166 ASENSOR_TYPE_LINEAR_ACCELERATION = 10, 167 /** 168 * {@link ASENSOR_TYPE_ROTATION_VECTOR} 169 */ 170 ASENSOR_TYPE_ROTATION_VECTOR = 11, 171 /** 172 * {@link ASENSOR_TYPE_RELATIVE_HUMIDITY} 173 * 174 * The relative humidity sensor value is returned in percent. 175 */ 176 ASENSOR_TYPE_RELATIVE_HUMIDITY = 12, 177 /** 178 * {@link ASENSOR_TYPE_AMBIENT_TEMPERATURE} 179 * 180 * The ambient temperature sensor value is returned in Celcius. 181 */ 182 ASENSOR_TYPE_AMBIENT_TEMPERATURE = 13, 183 /** 184 * {@link ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED} 185 */ 186 ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14, 187 /** 188 * {@link ASENSOR_TYPE_GAME_ROTATION_VECTOR} 189 */ 190 ASENSOR_TYPE_GAME_ROTATION_VECTOR = 15, 191 /** 192 * {@link ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED} 193 */ 194 ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 16, 195 /** 196 * {@link ASENSOR_TYPE_SIGNIFICANT_MOTION} 197 */ 198 ASENSOR_TYPE_SIGNIFICANT_MOTION = 17, 199 /** 200 * {@link ASENSOR_TYPE_STEP_DETECTOR} 201 */ 202 ASENSOR_TYPE_STEP_DETECTOR = 18, 203 /** 204 * {@link ASENSOR_TYPE_STEP_COUNTER} 205 */ 206 ASENSOR_TYPE_STEP_COUNTER = 19, 207 /** 208 * {@link ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR} 209 */ 210 ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20, 211 /** 212 * {@link ASENSOR_TYPE_HEART_RATE} 213 */ 214 ASENSOR_TYPE_HEART_RATE = 21, 215 /** 216 * {@link ASENSOR_TYPE_POSE_6DOF} 217 */ 218 ASENSOR_TYPE_POSE_6DOF = 28, 219 /** 220 * {@link ASENSOR_TYPE_STATIONARY_DETECT} 221 */ 222 ASENSOR_TYPE_STATIONARY_DETECT = 29, 223 /** 224 * {@link ASENSOR_TYPE_MOTION_DETECT} 225 */ 226 ASENSOR_TYPE_MOTION_DETECT = 30, 227 /** 228 * {@link ASENSOR_TYPE_HEART_BEAT} 229 */ 230 ASENSOR_TYPE_HEART_BEAT = 31, 231 /** 232 * {@link ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT} 233 */ 234 ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT = 34, 235 /** 236 * {@link ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED} 237 */ 238 ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35 239 } 240 241 /** 242 * Sensor accuracy measure. 243 */ 244 enum 245 { 246 /** no contact */ 247 ASENSOR_STATUS_NO_CONTACT = -1, 248 /** unreliable */ 249 ASENSOR_STATUS_UNRELIABLE = 0, 250 /** low accuracy */ 251 ASENSOR_STATUS_ACCURACY_LOW = 1, 252 /** medium accuracy */ 253 ASENSOR_STATUS_ACCURACY_MEDIUM = 2, 254 /** high accuracy */ 255 ASENSOR_STATUS_ACCURACY_HIGH = 3 256 } 257 258 /** 259 * Sensor Reporting Modes. 260 */ 261 enum 262 { 263 /** invalid reporting mode */ 264 AREPORTING_MODE_INVALID = -1, 265 /** continuous reporting */ 266 AREPORTING_MODE_CONTINUOUS = 0, 267 /** reporting on change */ 268 AREPORTING_MODE_ON_CHANGE = 1, 269 /** on shot reporting */ 270 AREPORTING_MODE_ONE_SHOT = 2, 271 /** special trigger reporting */ 272 AREPORTING_MODE_SPECIAL_TRIGGER = 3 273 } 274 275 /** 276 * Sensor Direct Report Rates. 277 */ 278 enum 279 { 280 /** stopped */ 281 ASENSOR_DIRECT_RATE_STOP = 0, 282 /** nominal 50Hz */ 283 ASENSOR_DIRECT_RATE_NORMAL = 1, 284 /** nominal 200Hz */ 285 ASENSOR_DIRECT_RATE_FAST = 2, 286 /** nominal 800Hz */ 287 ASENSOR_DIRECT_RATE_VERY_FAST = 3 288 } 289 290 /** 291 * Sensor Direct Channel Type. 292 */ 293 enum 294 { 295 /** shared memory created by ASharedMemory_create */ 296 ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1, 297 /** AHardwareBuffer */ 298 ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2 299 } 300 301 /* 302 * A few useful constants 303 */ 304 305 /** Earth's gravity in m/s^2 */ 306 enum ASENSOR_STANDARD_GRAVITY = 9.80665f; 307 /** Maximum magnetic field on Earth's surface in uT */ 308 enum ASENSOR_MAGNETIC_FIELD_EARTH_MAX = 60.0f; 309 /** Minimum magnetic field on Earth's surface in uT*/ 310 enum ASENSOR_MAGNETIC_FIELD_EARTH_MIN = 30.0f; 311 312 /** 313 * A sensor event. 314 */ 315 316 /* NOTE: changes to these structs have to be backward compatible */ 317 struct ASensorVector 318 { 319 union 320 { 321 float[3] v; 322 323 struct 324 { 325 float x; 326 float y; 327 float z; 328 } 329 330 struct 331 { 332 float azimuth; 333 float pitch; 334 float roll; 335 } 336 } 337 338 byte status; 339 ubyte[3] reserved; 340 } 341 342 struct AMetaDataEvent 343 { 344 int what; 345 int sensor; 346 } 347 348 struct AUncalibratedEvent 349 { 350 union 351 { 352 float[3] uncalib; 353 354 struct 355 { 356 float x_uncalib; 357 float y_uncalib; 358 float z_uncalib; 359 } 360 } 361 362 union 363 { 364 float[3] bias; 365 366 struct 367 { 368 float x_bias; 369 float y_bias; 370 float z_bias; 371 } 372 } 373 } 374 375 struct AHeartRateEvent 376 { 377 float bpm; 378 byte status; 379 } 380 381 struct ADynamicSensorEvent 382 { 383 int connected; 384 int handle; 385 } 386 387 struct AAdditionalInfoEvent 388 { 389 int type; 390 int serial; 391 392 union 393 { 394 int[14] data_int32; 395 float[14] data_float; 396 } 397 } 398 399 /* NOTE: changes to this struct has to be backward compatible */ 400 struct ASensorEvent 401 { 402 int version_; /* sizeof(struct ASensorEvent) */ 403 int sensor; 404 int type; 405 int reserved0; 406 long timestamp; 407 408 union 409 { 410 union 411 { 412 float[16] data; 413 ASensorVector vector; 414 ASensorVector acceleration; 415 ASensorVector magnetic; 416 float temperature; 417 float distance; 418 float light; 419 float pressure; 420 float relative_humidity; 421 AUncalibratedEvent uncalibrated_gyro; 422 AUncalibratedEvent uncalibrated_magnetic; 423 AMetaDataEvent meta_data; 424 AHeartRateEvent heart_rate; 425 ADynamicSensorEvent dynamic_sensor_meta; 426 AAdditionalInfoEvent additional_info; 427 } 428 429 union _Anonymous_0 430 { 431 ulong[8] data; 432 ulong step_counter; 433 } 434 435 _Anonymous_0 u64; 436 } 437 438 uint flags; 439 int[3] reserved1; 440 } 441 442 struct ASensorManager; 443 /** 444 * {@link ASensorManager} is an opaque type to manage sensors and 445 * events queues. 446 * 447 * {@link ASensorManager} is a singleton that can be obtained using 448 * ASensorManager_getInstance(). 449 * 450 * This file provides a set of functions that uses {@link 451 * ASensorManager} to access and list hardware sensors, and 452 * create and destroy event queues: 453 * - ASensorManager_getSensorList() 454 * - ASensorManager_getDefaultSensor() 455 * - ASensorManager_getDefaultSensorEx() 456 * - ASensorManager_createEventQueue() 457 * - ASensorManager_destroyEventQueue() 458 */ 459 460 struct ASensorEventQueue; 461 /** 462 * {@link ASensorEventQueue} is an opaque type that provides access to 463 * {@link ASensorEvent} from hardware sensors. 464 * 465 * A new {@link ASensorEventQueue} can be obtained using ASensorManager_createEventQueue(). 466 * 467 * This file provides a set of functions to enable and disable 468 * sensors, check and get events, and set event rates on a {@link 469 * ASensorEventQueue}. 470 * - ASensorEventQueue_enableSensor() 471 * - ASensorEventQueue_disableSensor() 472 * - ASensorEventQueue_hasEvents() 473 * - ASensorEventQueue_getEvents() 474 * - ASensorEventQueue_setEventRate() 475 */ 476 477 struct ASensor; 478 /** 479 * {@link ASensor} is an opaque type that provides information about 480 * an hardware sensors. 481 * 482 * A {@link ASensor} pointer can be obtained using 483 * ASensorManager_getDefaultSensor(), 484 * ASensorManager_getDefaultSensorEx() or from a {@link ASensorList}. 485 * 486 * This file provides a set of functions to access properties of a 487 * {@link ASensor}: 488 * - ASensor_getName() 489 * - ASensor_getVendor() 490 * - ASensor_getType() 491 * - ASensor_getResolution() 492 * - ASensor_getMinDelay() 493 * - ASensor_getFifoMaxEventCount() 494 * - ASensor_getFifoReservedEventCount() 495 * - ASensor_getStringType() 496 * - ASensor_getReportingMode() 497 * - ASensor_isWakeUpSensor() 498 */ 499 /** 500 * {@link ASensorRef} is a type for constant pointers to {@link ASensor}. 501 * 502 * This is used to define entry in {@link ASensorList} arrays. 503 */ 504 alias ASensorRef = const(ASensor)*; 505 /** 506 * {@link ASensorList} is an array of reference to {@link ASensor}. 507 * 508 * A {@link ASensorList} can be initialized using ASensorManager_getSensorList(). 509 */ 510 alias ASensorList = const(ASensor*)*; 511 512 /*****************************************************************************/ 513 514 /** 515 * Get a reference to the sensor manager. ASensorManager is a singleton 516 * per package as different packages may have access to different sensors. 517 * 518 * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead. 519 * 520 * Example: 521 * 522 * ASensorManager* sensorManager = ASensorManager_getInstance(); 523 * 524 */ 525 ASensorManager* ASensorManager_getInstance (); 526 527 /** 528 * Get a reference to the sensor manager. ASensorManager is a singleton 529 * per package as different packages may have access to different sensors. 530 * 531 * Example: 532 * 533 * ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz"); 534 * 535 */ 536 ASensorManager* ASensorManager_getInstanceForPackage (const(char)* packageName); 537 538 /** 539 * Returns the list of available sensors. 540 */ 541 int ASensorManager_getSensorList (ASensorManager* manager, ASensorList* list); 542 543 /** 544 * Returns the default sensor for the given type, or NULL if no sensor 545 * of that type exists. 546 */ 547 const(ASensor)* ASensorManager_getDefaultSensor (ASensorManager* manager, int type); 548 549 /** 550 * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor 551 * of this type and wakeUp properties exists. 552 */ 553 const(ASensor)* ASensorManager_getDefaultSensorEx (ASensorManager* manager, int type, bool wakeUp); 554 555 /** 556 * Creates a new sensor event queue and associate it with a looper. 557 * 558 * "ident" is a identifier for the events that will be returned when 559 * calling ALooper_pollOnce(). The identifier must be >= 0, or 560 * ALOOPER_POLL_CALLBACK if providing a non-NULL callback. 561 */ 562 ASensorEventQueue* ASensorManager_createEventQueue ( 563 ASensorManager* manager, 564 ALooper* looper, 565 int ident, 566 ALooper_callbackFunc callback, 567 void* data); 568 569 /** 570 * Destroys the event queue and free all resources associated to it. 571 */ 572 int ASensorManager_destroyEventQueue (ASensorManager* manager, ASensorEventQueue* queue); 573 574 /** 575 * Create direct channel based on shared memory 576 * 577 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} to be used 578 * for configuring sensor direct report. 579 * 580 * \param manager the {@link ASensorManager} instance obtained from 581 * {@link ASensorManager_getInstanceForPackage}. 582 * \param fd file descriptor representing a shared memory created by 583 * {@link ASharedMemory_create} 584 * \param size size to be used, must be less or equal to size of shared memory. 585 * 586 * \return a positive integer as a channel id to be used in 587 * {@link ASensorManager_destroyDirectChannel} and 588 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures. 589 */ 590 int ASensorManager_createSharedMemoryDirectChannel (ASensorManager* manager, int fd, size_t size); 591 592 /** 593 * Create direct channel based on AHardwareBuffer 594 * 595 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER} type to be used 596 * for configuring sensor direct report. 597 * 598 * \param manager the {@link ASensorManager} instance obtained from 599 * {@link ASensorManager_getInstanceForPackage}. 600 * \param buffer {@link AHardwareBuffer} instance created by {@link AHardwareBuffer_allocate}. 601 * \param size the intended size to be used, must be less or equal to size of buffer. 602 * 603 * \return a positive integer as a channel id to be used in 604 * {@link ASensorManager_destroyDirectChannel} and 605 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures. 606 */ 607 int ASensorManager_createHardwareBufferDirectChannel ( 608 ASensorManager* manager, 609 const(AHardwareBuffer)* buffer, 610 size_t size); 611 612 /** 613 * Destroy a direct channel 614 * 615 * Destroy a direct channel previously created using {@link ASensorManager_createDirectChannel}. 616 * The buffer used for creating direct channel does not get destroyed with 617 * {@link ASensorManager_destroy} and has to be close or released separately. 618 * 619 * \param manager the {@link ASensorManager} instance obtained from 620 * {@link ASensorManager_getInstanceForPackage}. 621 * \param channelId channel id (a positive integer) returned from 622 * {@link ASensorManager_createSharedMemoryDirectChannel} or 623 * {@link ASensorManager_createHardwareBufferDirectChannel}. 624 */ 625 void ASensorManager_destroyDirectChannel (ASensorManager* manager, int channelId); 626 627 /** 628 * Configure direct report on channel 629 * 630 * Configure sensor direct report on a direct channel: set rate to value other than 631 * {@link ASENSOR_DIRECT_RATE_STOP} so that sensor event can be directly 632 * written into the shared memory region used for creating the buffer. It returns a positive token 633 * which can be used for identify sensor events from different sensors on success. Calling with rate 634 * {@link ASENSOR_DIRECT_RATE_STOP} will stop direct report of the sensor specified in the channel. 635 * 636 * To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to 637 * {@link ASENSOR_DIRECT_RATE_STOP}. 638 * 639 * In order to successfully configure a direct report, the sensor has to support the specified rate 640 * and the channel type, which can be checked by {@link ASensor_getHighestDirectReportRateLevel} and 641 * {@link ASensor_isDirectChannelTypeSupported}, respectively. 642 * 643 * Example: 644 * 645 * ASensorManager *manager = ...; 646 * ASensor *sensor = ...; 647 * int channelId = ...; 648 * 649 * ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST); 650 * 651 * \param manager the {@link ASensorManager} instance obtained from 652 * {@link ASensorManager_getInstanceForPackage}. 653 * \param sensor a {@link ASensor} to denote which sensor to be operate. It can be NULL if rate 654 * is {@link ASENSOR_DIRECT_RATE_STOP}, denoting stopping of all active sensor 655 * direct report. 656 * \param channelId channel id (a positive integer) returned from 657 * {@link ASensorManager_createSharedMemoryDirectChannel} or 658 * {@link ASensorManager_createHardwareBufferDirectChannel}. 659 * 660 * \return positive token for success or negative error code. 661 */ 662 int ASensorManager_configureDirectReport ( 663 ASensorManager* manager, 664 const(ASensor)* sensor, 665 int channelId, 666 int rate); 667 /* __ANDROID_API__ >= 26 */ 668 669 /*****************************************************************************/ 670 671 /** 672 * Enable the selected sensor with sampling and report parameters 673 * 674 * Enable the selected sensor at a specified sampling period and max batch report latency. 675 * To disable sensor, use {@link ASensorEventQueue_disableSensor}. 676 * 677 * \param queue {@link ASensorEventQueue} for sensor event to be report to. 678 * \param sensor {@link ASensor} to be enabled. 679 * \param samplingPeriodUs sampling period of sensor in microseconds. 680 * \param maxBatchReportLatencyus maximum time interval between two batch of sensor events are 681 * delievered in microseconds. For sensor streaming, set to 0. 682 * \return 0 on success or a negative error code on failure. 683 */ 684 int ASensorEventQueue_registerSensor ( 685 ASensorEventQueue* queue, 686 const(ASensor)* sensor, 687 int samplingPeriodUs, 688 long maxBatchReportLatencyUs); 689 690 /** 691 * Enable the selected sensor at default sampling rate. 692 * 693 * Start event reports of a sensor to specified sensor event queue at a default rate. 694 * 695 * \param queue {@link ASensorEventQueue} for sensor event to be report to. 696 * \param sensor {@link ASensor} to be enabled. 697 * 698 * \return 0 on success or a negative error code on failure. 699 */ 700 int ASensorEventQueue_enableSensor (ASensorEventQueue* queue, const(ASensor)* sensor); 701 702 /** 703 * Disable the selected sensor. 704 * 705 * Stop event reports from the sensor to specified sensor event queue. 706 * 707 * \param queue {@link ASensorEventQueue} to be changed 708 * \param sensor {@link ASensor} to be disabled 709 * \return 0 on success or a negative error code on failure. 710 */ 711 int ASensorEventQueue_disableSensor (ASensorEventQueue* queue, const(ASensor)* sensor); 712 713 /** 714 * Sets the delivery rate of events in microseconds for the given sensor. 715 * 716 * This function has to be called after {@link ASensorEventQueue_enableSensor}. 717 * Note that this is a hint only, generally event will arrive at a higher 718 * rate. It is an error to set a rate inferior to the value returned by 719 * ASensor_getMinDelay(). 720 * 721 * \param queue {@link ASensorEventQueue} to which sensor event is delivered. 722 * \param sensor {@link ASensor} of which sampling rate to be updated. 723 * \param usec sensor sampling period (1/sampling rate) in microseconds 724 * \return 0 on sucess or a negative error code on failure. 725 */ 726 int ASensorEventQueue_setEventRate (ASensorEventQueue* queue, const(ASensor)* sensor, int usec); 727 728 /** 729 * Determine if a sensor event queue has pending event to be processed. 730 * 731 * \param queue {@link ASensorEventQueue} to be queried 732 * \return 1 if the queue has events; 0 if it does not have events; 733 * or a negative value if there is an error. 734 */ 735 int ASensorEventQueue_hasEvents (ASensorEventQueue* queue); 736 737 /** 738 * Retrieve pending events in sensor event queue 739 * 740 * Retrieve next available events from the queue to a specified event array. 741 * 742 * \param queue {@link ASensorEventQueue} to get events from 743 * \param events pointer to an array of {@link ASensorEvents}. 744 * \param count max number of event that can be filled into array event. 745 * \return number of events returned on success; negative error code when 746 * no events are pending or an error has occurred. 747 * 748 * Examples: 749 * 750 * ASensorEvent event; 751 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1); 752 * 753 * ASensorEvent eventBuffer[8]; 754 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8); 755 * 756 */ 757 ssize_t ASensorEventQueue_getEvents (ASensorEventQueue* queue, ASensorEvent* events, size_t count); 758 759 /*****************************************************************************/ 760 761 /** 762 * Returns this sensor's name (non localized) 763 */ 764 const(char)* ASensor_getName (const(ASensor)* sensor); 765 766 /** 767 * Returns this sensor's vendor's name (non localized) 768 */ 769 const(char)* ASensor_getVendor (const(ASensor)* sensor); 770 771 /** 772 * Return this sensor's type 773 */ 774 int ASensor_getType (const(ASensor)* sensor); 775 776 /** 777 * Returns this sensors's resolution 778 */ 779 float ASensor_getResolution (const(ASensor)* sensor); 780 781 /** 782 * Returns the minimum delay allowed between events in microseconds. 783 * A value of zero means that this sensor doesn't report events at a 784 * constant rate, but rather only when a new data is available. 785 */ 786 int ASensor_getMinDelay (const(ASensor)* sensor); 787 788 /** 789 * Returns the maximum size of batches for this sensor. Batches will often be 790 * smaller, as the hardware fifo might be used for other sensors. 791 */ 792 int ASensor_getFifoMaxEventCount (const(ASensor)* sensor); 793 794 /** 795 * Returns the hardware batch fifo size reserved to this sensor. 796 */ 797 int ASensor_getFifoReservedEventCount (const(ASensor)* sensor); 798 799 /** 800 * Returns this sensor's string type. 801 */ 802 const(char)* ASensor_getStringType (const(ASensor)* sensor); 803 804 /** 805 * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants. 806 */ 807 int ASensor_getReportingMode (const(ASensor)* sensor); 808 809 /** 810 * Returns true if this is a wake up sensor, false otherwise. 811 */ 812 bool ASensor_isWakeUpSensor (const(ASensor)* sensor); 813 /* __ANDROID_API__ >= 21 */ 814 815 /** 816 * Test if sensor supports a certain type of direct channel. 817 * 818 * \param sensor a {@link ASensor} to denote the sensor to be checked. 819 * \param channelType Channel type constant, either 820 * {@ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} 821 * or {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER}. 822 * \returns true if sensor supports the specified direct channel type. 823 */ 824 bool ASensor_isDirectChannelTypeSupported (const(ASensor)* sensor, int channelType); 825 826 /** 827 * Get the highest direct rate level that a sensor support. 828 * 829 * \param sensor a {@link ASensor} to denote the sensor to be checked. 830 * 831 * \return a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor. 832 * If return value is {@link ASENSOR_DIRECT_RATE_STOP}, it means the sensor 833 * does not support direct report. 834 */ 835 int ASensor_getHighestDirectReportRateLevel (const(ASensor)* sensor); 836 /* __ANDROID_API__ >= 26 */ 837 838 // ANDROID_SENSOR_H 839 840 /** @} */