186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Copyright (C) 2010 The Android Open Source Project 386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Licensed under the Apache License, Version 2.0 (the "License"); 586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * you may not use this file except in compliance with the License. 686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * You may obtain a copy of the License at 786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * http://www.apache.org/licenses/LICENSE-2.0 986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 1086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Unless required by applicable law or agreed to in writing, software 1186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * distributed under the License is distributed on an "AS IS" BASIS, 1286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * See the License for the specific language governing permissions and 1486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * limitations under the License. 1586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 1686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 1786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 1886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#ifndef ANDROID_SENSOR_H 1986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#define ANDROID_SENSOR_H 2086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 2186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/****************************************************************** 2286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 2386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * IMPORTANT NOTICE: 2486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 2586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * This file is part of Android's set of stable system headers 2686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * exposed by the Android NDK (Native Development Kit). 2786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 2886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Third-party source AND binary code relies on the definitions 2986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. 3086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 3186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) 3286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS 3386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY 3486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES 3586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 3686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 3786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 3886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Structures and functions to receive and process sensor events in 3986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * native code. 4086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 4186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 4286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 4386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#include <sys/types.h> 4486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 4586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#include <android/looper.h> 4686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 4786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#ifdef __cplusplus 4886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehextern "C" { 4986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#endif 5086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 5186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 5286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 5386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Sensor types 5486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * (keep in sync with hardware/sensor.h) 5586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 5686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 5786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehenum { 5886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASENSOR_TYPE_ACCELEROMETER = 1, 5986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASENSOR_TYPE_MAGNETIC_FIELD = 2, 6086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASENSOR_TYPE_GYROSCOPE = 4, 6186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASENSOR_TYPE_LIGHT = 5, 6286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASENSOR_TYPE_PROXIMITY = 8 6386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh}; 6486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 6586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 6686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Sensor accuracy measure 6786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 6886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehenum { 6986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASENSOR_STATUS_UNRELIABLE = 0, 7086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASENSOR_STATUS_ACCURACY_LOW = 1, 7186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASENSOR_STATUS_ACCURACY_MEDIUM = 2, 7286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASENSOR_STATUS_ACCURACY_HIGH = 3 7386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh}; 7486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 7586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 7686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * A few useful constants 7786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 7886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 7986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* Earth's gravity in m/s^2 */ 8086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#define ASENSOR_STANDARD_GRAVITY (9.80665f) 8186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* Maximum magnetic field on Earth's surface in uT */ 8286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#define ASENSOR_MAGNETIC_FIELD_EARTH_MAX (60.0f) 8386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* Minimum magnetic field on Earth's surface in uT*/ 8486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#define ASENSOR_MAGNETIC_FIELD_EARTH_MIN (30.0f) 8586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 8686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 8786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * A sensor event. 8886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 8986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 9086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* NOTE: Must match hardware/sensors.h */ 9186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehtypedef struct ASensorVector { 9286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh union { 9386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float v[3]; 9486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh struct { 9586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float x; 9686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float y; 9786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float z; 9886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh }; 9986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh struct { 10086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float azimuth; 10186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float pitch; 10286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float roll; 10386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh }; 10486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh }; 10586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh int8_t status; 10686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh uint8_t reserved[3]; 10786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh} ASensorVector; 10886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 10986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehtypedef struct AMetaDataEvent { 11086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh int32_t what; 11186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh int32_t sensor; 11286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh} AMetaDataEvent; 11386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 11486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehtypedef struct AUncalibratedEvent { 11586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh union { 11686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float uncalib[3]; 11786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh struct { 11886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float x_uncalib; 11986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float y_uncalib; 12086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float z_uncalib; 12186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh }; 12286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh }; 12386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh union { 12486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float bias[3]; 12586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh struct { 12686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float x_bias; 12786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float y_bias; 12886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float z_bias; 12986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh }; 13086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh }; 13186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh} AUncalibratedEvent; 13286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 13386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* NOTE: Must match hardware/sensors.h */ 13486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehtypedef struct ASensorEvent { 13586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh int32_t version; /* sizeof(struct ASensorEvent) */ 13686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh int32_t sensor; 13786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh int32_t type; 13886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh int32_t reserved0; 13986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh int64_t timestamp; 14086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh union { 14186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh union { 14286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float data[16]; 14386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASensorVector vector; 14486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASensorVector acceleration; 14586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASensorVector magnetic; 14686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float temperature; 14786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float distance; 14886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float light; 14986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float pressure; 15086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh float relative_humidity; 15186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh AUncalibratedEvent uncalibrated_gyro; 15286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh AUncalibratedEvent uncalibrated_magnetic; 15386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh AMetaDataEvent meta_data; 15486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh }; 15586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh union { 15686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh uint64_t data[8]; 15786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh uint64_t step_counter; 15886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh } u64; 15986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh }; 16086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh int32_t reserved1[4]; 16186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh} ASensorEvent; 16286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 16386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehstruct ASensorManager; 16486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehtypedef struct ASensorManager ASensorManager; 16586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 16686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehstruct ASensorEventQueue; 16786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehtypedef struct ASensorEventQueue ASensorEventQueue; 16886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 16986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehstruct ASensor; 17086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehtypedef struct ASensor ASensor; 17186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehtypedef ASensor const* ASensorRef; 17286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehtypedef ASensorRef const* ASensorList; 17386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 17486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/*****************************************************************************/ 17586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 17686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 17786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Get a reference to the sensor manager. ASensorManager is a singleton. 17886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 17986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Example: 18086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 18186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * ASensorManager* sensorManager = ASensorManager_getInstance(); 18286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 18386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 18486c3b43906389f7a32bbf2bc27013742b29e0109Andrew HsiehASensorManager* ASensorManager_getInstance(); 18586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 18686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 18786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 18886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Returns the list of available sensors. 18986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 19086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehint ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list); 19186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 19286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 19386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Returns the default sensor for the given type, or NULL if no sensor 19486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * of that type exist. 19586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 19686c3b43906389f7a32bbf2bc27013742b29e0109Andrew HsiehASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type); 19786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 19886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 19986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Creates a new sensor event queue and associate it with a looper. 20086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 20186c3b43906389f7a32bbf2bc27013742b29e0109Andrew HsiehASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager, 20286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ALooper* looper, int ident, ALooper_callbackFunc callback, void* data); 20386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 20486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 20586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Destroys the event queue and free all resources associated to it. 20686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 20786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehint ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue); 20886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 20986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 21086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/*****************************************************************************/ 21186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 21286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 21386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Enable the selected sensor. Returns a negative error code on failure. 21486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 21586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehint ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor); 21686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 21786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 21886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Disable the selected sensor. Returns a negative error code on failure. 21986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 22086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehint ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor); 22186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 22286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 22386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Sets the delivery rate of events in microseconds for the given sensor. 22486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Note that this is a hint only, generally event will arrive at a higher 22586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * rate. It is an error to set a rate inferior to the value returned by 22686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * ASensor_getMinDelay(). 22786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Returns a negative error code on failure. 22886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 22986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehint ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec); 23086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 23186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 23286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Returns true if there are one or more events available in the 23386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * sensor queue. Returns 1 if the queue has events; 0 if 23486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * it does not have events; and a negative value if there is an error. 23586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 23686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehint ASensorEventQueue_hasEvents(ASensorEventQueue* queue); 23786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 23886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 23986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Returns the next available events from the queue. Returns a negative 24086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * value if no events are available or an error has occurred, otherwise 24186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * the number of events returned. 24286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 24386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Examples: 24486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * ASensorEvent event; 24586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1); 24686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 24786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * ASensorEvent eventBuffer[8]; 24886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8); 24986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * 25086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 25186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, 25286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh ASensorEvent* events, size_t count); 25386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 25486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 25586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/*****************************************************************************/ 25686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 25786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 25886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Returns this sensor's name (non localized) 25986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 26086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehconst char* ASensor_getName(ASensor const* sensor); 26186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 26286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 26386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Returns this sensor's vendor's name (non localized) 26486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 26586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehconst char* ASensor_getVendor(ASensor const* sensor); 26686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 26786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 26886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Return this sensor's type 26986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 27086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehint ASensor_getType(ASensor const* sensor); 27186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 27286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 27386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Returns this sensors's resolution 27486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 27586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehfloat ASensor_getResolution(ASensor const* sensor) __NDK_FPABI__; 27686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 27786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh/* 27886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * Returns the minimum delay allowed between events in microseconds. 27986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * A value of zero means that this sensor doesn't report events at a 28086c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh * constant rate, but rather only when a new data is available. 28186c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh */ 28286c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsiehint ASensor_getMinDelay(ASensor const* sensor); 28386c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 28486c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 28586c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#ifdef __cplusplus 28686c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh}; 28786c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#endif 28886c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh 28986c3b43906389f7a32bbf2bc27013742b29e0109Andrew Hsieh#endif // ANDROID_SENSOR_H 290