Skip to content

Most visited

Recently visited

navigation

Sensor

Files

file  sensor.h
 

Data Structures

struct  ASensorVector
 
struct  AMetaDataEvent
 
struct  AUncalibratedEvent
 
struct  AHeartRateEvent
 
struct  ADynamicSensorEvent
 
struct  AAdditionalInfoEvent
 
struct  ASensorEvent
 

Typedefs

typedef struct AHardwareBuffer AHardwareBuffer
 
typedef struct ASensorVector ASensorVector
 
typedef struct AMetaDataEvent AMetaDataEvent
 
typedef struct AUncalibratedEvent AUncalibratedEvent
 
typedef struct AHeartRateEvent AHeartRateEvent
 
typedef struct ADynamicSensorEvent ADynamicSensorEvent
 
typedef struct ASensorEvent ASensorEvent
 
typedef struct ASensorManager ASensorManager
 
typedef struct ASensorEventQueue ASensorEventQueue
 
typedef struct ASensor ASensor
 
typedef ASensor const * ASensorRef
 
typedef ASensorRef const * ASensorList
 

Enumerations

enum  {
  ASENSOR_TYPE_INVALID = -1, ASENSOR_TYPE_ACCELEROMETER = 1, ASENSOR_TYPE_MAGNETIC_FIELD = 2, ASENSOR_TYPE_GYROSCOPE = 4,
  ASENSOR_TYPE_LIGHT = 5, ASENSOR_TYPE_PROXIMITY = 8, ASENSOR_TYPE_LINEAR_ACCELERATION = 10
}
 
enum  {
  ASENSOR_STATUS_NO_CONTACT = -1, ASENSOR_STATUS_UNRELIABLE = 0, ASENSOR_STATUS_ACCURACY_LOW = 1, ASENSOR_STATUS_ACCURACY_MEDIUM = 2,
  ASENSOR_STATUS_ACCURACY_HIGH = 3
}
 
enum  {
  AREPORTING_MODE_INVALID = -1, AREPORTING_MODE_CONTINUOUS = 0, AREPORTING_MODE_ON_CHANGE = 1, AREPORTING_MODE_ONE_SHOT = 2,
  AREPORTING_MODE_SPECIAL_TRIGGER = 3
}
 
enum  { ASENSOR_DIRECT_RATE_STOP = 0, ASENSOR_DIRECT_RATE_NORMAL = 1, ASENSOR_DIRECT_RATE_FAST = 2, ASENSOR_DIRECT_RATE_VERY_FAST = 3 }
 
enum  { ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1, ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2 }
 

Functions

 __attribute__ ((deprecated)) ASensorManager *ASensorManager_getInstance()
 
ASensorManagerASensorManager_getInstanceForPackage (const char *packageName)
 
int ASensorManager_getSensorList (ASensorManager *manager, ASensorList *list)
 
ASensor const * ASensorManager_getDefaultSensor (ASensorManager *manager, int type)
 
ASensor const * ASensorManager_getDefaultSensorEx (ASensorManager *manager, int type, bool wakeUp)
 
ASensorEventQueueASensorManager_createEventQueue (ASensorManager *manager, ALooper *looper, int ident, ALooper_callbackFunc callback, void *data)
 
int ASensorManager_destroyEventQueue (ASensorManager *manager, ASensorEventQueue *queue)
 
int ASensorManager_createSharedMemoryDirectChannel (ASensorManager *manager, int fd, size_t size)
 
int ASensorManager_createHardwareBufferDirectChannel (ASensorManager *manager, AHardwareBuffer const *buffer, size_t size)
 
void ASensorManager_destroyDirectChannel (ASensorManager *manager, int channelId)
 
int ASensorManager_configureDirectReport (ASensorManager *manager, ASensor const *sensor, int channelId, int rate)
 
int ASensorEventQueue_registerSensor (ASensorEventQueue *queue, ASensor const *sensor, int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs)
 
int ASensorEventQueue_enableSensor (ASensorEventQueue *queue, ASensor const *sensor)
 
int ASensorEventQueue_disableSensor (ASensorEventQueue *queue, ASensor const *sensor)
 
int ASensorEventQueue_setEventRate (ASensorEventQueue *queue, ASensor const *sensor, int32_t usec)
 
int ASensorEventQueue_hasEvents (ASensorEventQueue *queue)
 
ssize_t ASensorEventQueue_getEvents (ASensorEventQueue *queue, ASensorEvent *events, size_t count)
 
const char * ASensor_getName (ASensor const *sensor)
 
const char * ASensor_getVendor (ASensor const *sensor)
 
int ASensor_getType (ASensor const *sensor)
 
float ASensor_getResolution (ASensor const *sensor)
 
int ASensor_getMinDelay (ASensor const *sensor)
 
int ASensor_getFifoMaxEventCount (ASensor const *sensor)
 
int ASensor_getFifoReservedEventCount (ASensor const *sensor)
 
const char * ASensor_getStringType (ASensor const *sensor)
 
int ASensor_getReportingMode (ASensor const *sensor)
 
bool ASensor_isWakeUpSensor (ASensor const *sensor)
 
bool ASensor_isDirectChannelTypeSupported (ASensor const *sensor, int channelType)
 
int ASensor_getHighestDirectReportRateLevel (ASensor const *sensor)
 

Detailed Description

Typedef Documentation

§ ADynamicSensorEvent

§ AHardwareBuffer

Structures and functions to receive and process sensor events in native code.

§ AHeartRateEvent

§ AMetaDataEvent

§ ASensor

§ ASensorEvent

typedef struct ASensorEvent ASensorEvent

§ ASensorEventQueue

ASensorEventQueue is an opaque type that provides access to ASensorEvent from hardware sensors.

A new ASensorEventQueue can be obtained using ASensorManager_createEventQueue().

This file provides a set of functions to enable and disable sensors, check and get events, and set event rates on a ASensorEventQueue.

§ ASensorList

typedef ASensorRef const* ASensorList

ASensorList is an array of reference to ASensor.

A ASensorList can be initialized using ASensorManager_getSensorList().

§ ASensorManager

ASensorManager is an opaque type to manage sensors and events queues.

ASensorManager is a singleton that can be obtained using ASensorManager_getInstance().

This file provides a set of functions that uses ASensorManager to access and list hardware sensors, and create and destroy event queues:

§ ASensorRef

typedef ASensor const* ASensorRef

ASensorRef is a type for constant pointers to ASensor.

This is used to define entry in ASensorList arrays.

§ ASensorVector

typedef struct ASensorVector ASensorVector

A sensor event.

§ AUncalibratedEvent

Enumeration Type Documentation

§ anonymous enum

anonymous enum

Sensor types. (keep in sync with hardware/sensors.h)

Enumerator
ASENSOR_TYPE_INVALID 

Invalid sensor type. Returned by ASensor_getType as error value.

ASENSOR_TYPE_ACCELEROMETER 

ASENSOR_TYPE_ACCELEROMETER reporting-mode: continuous

All values are in SI units (m/s^2) and measure the acceleration of the device minus the force of gravity.

ASENSOR_TYPE_MAGNETIC_FIELD 

ASENSOR_TYPE_MAGNETIC_FIELD reporting-mode: continuous

All values are in micro-Tesla (uT) and measure the geomagnetic field in the X, Y and Z axis.

ASENSOR_TYPE_GYROSCOPE 

ASENSOR_TYPE_GYROSCOPE reporting-mode: continuous

All values are in radians/second and measure the rate of rotation around the X, Y and Z axis.

ASENSOR_TYPE_LIGHT 

ASENSOR_TYPE_LIGHT reporting-mode: on-change

The light sensor value is returned in SI lux units.

ASENSOR_TYPE_PROXIMITY 

ASENSOR_TYPE_PROXIMITY reporting-mode: on-change

The proximity sensor which turns the screen off and back on during calls is the wake-up proximity sensor. Implement wake-up proximity sensor before implementing a non wake-up proximity sensor. For the wake-up proximity sensor set the flag SENSOR_FLAG_WAKE_UP. The value corresponds to the distance to the nearest object in centimeters.

ASENSOR_TYPE_LINEAR_ACCELERATION 

ASENSOR_TYPE_LINEAR_ACCELERATION reporting-mode: continuous

All values are in SI units (m/s^2) and measure the acceleration of the device not including the force of gravity.

§ anonymous enum

anonymous enum

Sensor accuracy measure.

Enumerator
ASENSOR_STATUS_NO_CONTACT 

no contact

ASENSOR_STATUS_UNRELIABLE 

unreliable

ASENSOR_STATUS_ACCURACY_LOW 

low accuracy

ASENSOR_STATUS_ACCURACY_MEDIUM 

medium accuracy

ASENSOR_STATUS_ACCURACY_HIGH 

high accuracy

§ anonymous enum

anonymous enum

Sensor Reporting Modes.

Enumerator
AREPORTING_MODE_INVALID 

invalid reporting mode

AREPORTING_MODE_CONTINUOUS 

continuous reporting

AREPORTING_MODE_ON_CHANGE 

reporting on change

AREPORTING_MODE_ONE_SHOT 

on shot reporting

AREPORTING_MODE_SPECIAL_TRIGGER 

special trigger reporting

§ anonymous enum

anonymous enum

Sensor Direct Report Rates.

Enumerator
ASENSOR_DIRECT_RATE_STOP 

stopped

ASENSOR_DIRECT_RATE_NORMAL 

nominal 50Hz

ASENSOR_DIRECT_RATE_FAST 

nominal 200Hz

ASENSOR_DIRECT_RATE_VERY_FAST 

nominal 800Hz

§ anonymous enum

anonymous enum

Sensor Direct Channel Type.

Enumerator
ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY 

shared memory created by ASharedMemory_create

ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER 

AHardwareBuffer

Function Documentation

§ __attribute__()

__attribute__ ( (deprecated)  )

Get a reference to the sensor manager. ASensorManager is a singleton per package as different packages may have access to different sensors.

Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead.

Example:

ASensorManager* sensorManager = ASensorManager_getInstance();

§ ASensor_getFifoMaxEventCount()

int ASensor_getFifoMaxEventCount ( ASensor const *  sensor)

Returns the maximum size of batches for this sensor. Batches will often be smaller, as the hardware fifo might be used for other sensors.

§ ASensor_getFifoReservedEventCount()

int ASensor_getFifoReservedEventCount ( ASensor const *  sensor)

Returns the hardware batch fifo size reserved to this sensor.

§ ASensor_getHighestDirectReportRateLevel()

int ASensor_getHighestDirectReportRateLevel ( ASensor const *  sensor)

Get the highest direct rate level that a sensor support.

Parameters
sensora ASensor to denote the sensor to be checked.
Returns
a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor. If return value is ASENSOR_DIRECT_RATE_STOP, it means the sensor does not support direct report.

§ ASensor_getMinDelay()

int ASensor_getMinDelay ( ASensor const *  sensor)

Returns the minimum delay allowed between events in microseconds. A value of zero means that this sensor doesn't report events at a constant rate, but rather only when a new data is available.

§ ASensor_getName()

const char* ASensor_getName ( ASensor const *  sensor)

Returns this sensor's name (non localized)

§ ASensor_getReportingMode()

int ASensor_getReportingMode ( ASensor const *  sensor)

Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants.

§ ASensor_getResolution()

float ASensor_getResolution ( ASensor const *  sensor)

Returns this sensors's resolution

§ ASensor_getStringType()

const char* ASensor_getStringType ( ASensor const *  sensor)

Returns this sensor's string type.

§ ASensor_getType()

int ASensor_getType ( ASensor const *  sensor)

Return this sensor's type

§ ASensor_getVendor()

const char* ASensor_getVendor ( ASensor const *  sensor)

Returns this sensor's vendor's name (non localized)

§ ASensor_isDirectChannelTypeSupported()

bool ASensor_isDirectChannelTypeSupported ( ASensor const *  sensor,
int  channelType 
)

Test if sensor supports a certain type of direct channel.

Parameters
sensora ASensor to denote the sensor to be checked.
channelTypeChannel type constant, either {} or ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER.
Returns
true if sensor supports the specified direct channel type.

§ ASensor_isWakeUpSensor()

bool ASensor_isWakeUpSensor ( ASensor const *  sensor)

Returns true if this is a wake up sensor, false otherwise.

§ ASensorEventQueue_disableSensor()

int ASensorEventQueue_disableSensor ( ASensorEventQueue queue,
ASensor const *  sensor 
)

Disable the selected sensor. Returns a negative error code on failure.

§ ASensorEventQueue_enableSensor()

int ASensorEventQueue_enableSensor ( ASensorEventQueue queue,
ASensor const *  sensor 
)

Enable the selected sensor. Returns a negative error code on failure.

§ ASensorEventQueue_getEvents()

ssize_t ASensorEventQueue_getEvents ( ASensorEventQueue queue,
ASensorEvent events,
size_t  count 
)

Returns the next available events from the queue. Returns a negative value if no events are available or an error has occurred, otherwise the number of events returned.

Examples: ASensorEvent event; ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1);

ASensorEvent eventBuffer[8]; ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8);

§ ASensorEventQueue_hasEvents()

int ASensorEventQueue_hasEvents ( ASensorEventQueue queue)

Returns true if there are one or more events available in the sensor queue. Returns 1 if the queue has events; 0 if it does not have events; and a negative value if there is an error.

§ ASensorEventQueue_registerSensor()

int ASensorEventQueue_registerSensor ( ASensorEventQueue queue,
ASensor const *  sensor,
int32_t  samplingPeriodUs,
int64_t  maxBatchReportLatencyUs 
)

Enable the selected sensor with a specified sampling period and max batch report latency. Returns a negative error code on failure. Note: To disable the selected sensor, use ASensorEventQueue_disableSensor() same as before.

§ ASensorEventQueue_setEventRate()

int ASensorEventQueue_setEventRate ( ASensorEventQueue queue,
ASensor const *  sensor,
int32_t  usec 
)

Sets the delivery rate of events in microseconds for the given sensor. Note that this is a hint only, generally event will arrive at a higher rate. It is an error to set a rate inferior to the value returned by ASensor_getMinDelay(). Returns a negative error code on failure.

§ ASensorManager_configureDirectReport()

int ASensorManager_configureDirectReport ( ASensorManager manager,
ASensor const *  sensor,
int  channelId,
int  rate 
)

Configure direct report on channel

Configure sensor direct report on a direct channel: set rate to value other than ASENSOR_DIRECT_RATE_STOP so that sensor event can be directly written into the shared memory region used for creating the buffer. It returns a positive token which can be used for identify sensor events from different sensors on success. Calling with rate ASENSOR_DIRECT_RATE_STOP will stop direct report of the sensor specified in the channel.

To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to ASENSOR_DIRECT_RATE_STOP.

In order to successfully configure a direct report, the sensor has to support the specified rate and the channel type, which can be checked by ASensor_getHighestDirectReportRateLevel and ASensor_isDirectChannelTypeSupported, respectively.

Example:

ASensorManager *manager = ...;
ASensor *sensor = ...;
int channelId = ...;
manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST);
Parameters
managerthe ASensorManager instance obtained from ASensorManager_getInstanceForPackage.
sensora ASensor to denote which sensor to be operate. It can be NULL if rate is ASENSOR_DIRECT_RATE_STOP, denoting stopping of all active sensor direct report.
channelIdchannel id (a positive integer) returned from ASensorManager_createSharedMemoryDirectChannel or ASensorManager_createHardwareBufferDirectChannel.
Returns
positive token for success or negative error code.

§ ASensorManager_createEventQueue()

ASensorEventQueue* ASensorManager_createEventQueue ( ASensorManager manager,
ALooper looper,
int  ident,
ALooper_callbackFunc  callback,
void *  data 
)

Creates a new sensor event queue and associate it with a looper.

"ident" is a identifier for the events that will be returned when calling ALooper_pollOnce(). The identifier must be >= 0, or ALOOPER_POLL_CALLBACK if providing a non-NULL callback.

§ ASensorManager_createHardwareBufferDirectChannel()

int ASensorManager_createHardwareBufferDirectChannel ( ASensorManager manager,
AHardwareBuffer const *  buffer,
size_t  size 
)

Create direct channel based on AHardwareBuffer

Create a direct channel of ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER type to be used for configuring sensor direct report.

Parameters
managerthe ASensorManager instance obtained from ASensorManager_getInstanceForPackage.
bufferAHardwareBuffer instance created by AHardwareBuffer_allocate.
sizethe intended size to be used, must be less or equal to size of buffer.
Returns
a positive integer as a channel id to be used in ASensorManager_destroyDirectChannel and ASensorManager_configureDirectReport, or value less or equal to 0 for failures.

§ ASensorManager_createSharedMemoryDirectChannel()

int ASensorManager_createSharedMemoryDirectChannel ( ASensorManager manager,
int  fd,
size_t  size 
)

Create direct channel based on shared memory

Create a direct channel of ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY to be used for configuring sensor direct report.

Parameters
managerthe ASensorManager instance obtained from ASensorManager_getInstanceForPackage.
fdfile descriptor representing a shared memory created by ASharedMemory_create
sizesize to be used, must be less or equal to size of shared memory.
Returns
a positive integer as a channel id to be used in ASensorManager_destroyDirectChannel and ASensorManager_configureDirectReport, or value less or equal to 0 for failures.

§ ASensorManager_destroyDirectChannel()

void ASensorManager_destroyDirectChannel ( ASensorManager manager,
int  channelId 
)

Destroy a direct channel

Destroy a direct channel previously created using ASensorManager_createDirectChannel. The buffer used for creating direct channel does not get destroyed with ASensorManager_destroy and has to be close or released separately.

Parameters
managerthe ASensorManager instance obtained from ASensorManager_getInstanceForPackage.
channelIdchannel id (a positive integer) returned from ASensorManager_createSharedMemoryDirectChannel or ASensorManager_createHardwareBufferDirectChannel.

§ ASensorManager_destroyEventQueue()

int ASensorManager_destroyEventQueue ( ASensorManager manager,
ASensorEventQueue queue 
)

Destroys the event queue and free all resources associated to it.

§ ASensorManager_getDefaultSensor()

ASensor const* ASensorManager_getDefaultSensor ( ASensorManager manager,
int  type 
)

Returns the default sensor for the given type, or NULL if no sensor of that type exists.

§ ASensorManager_getDefaultSensorEx()

ASensor const* ASensorManager_getDefaultSensorEx ( ASensorManager manager,
int  type,
bool  wakeUp 
)

Returns the default sensor with the given type and wakeUp properties or NULL if no sensor of this type and wakeUp properties exists.

§ ASensorManager_getInstanceForPackage()

ASensorManager* ASensorManager_getInstanceForPackage ( const char *  packageName)

§ ASensorManager_getSensorList()

int ASensorManager_getSensorList ( ASensorManager manager,
ASensorList list 
)

Returns the list of available sensors.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.