Accessing sensor data and status

Updated: April 19, 2023

Applications can access the sensor's data and status by binding callback functions or events that are of the structure sigevent to sensor events that are of particular interest.

The Sensor library supports the following ways to access sensor data and status information:

Callback mode

Use callback functions to provide custom code to be executed when a specific sensor event occurs (e.g., encoded data is available). Using callback functions allows you to control what occurs in your application. For example, you can use callback functions to perform image processing or to save data to disk.

Callback functions execute in a separate thread in the Sensor library, so you need to be sure that your code is thread-safe through the use of appropriate thread synchronization primitives (mutexes, semaphores, condvars, etc.).

For more information, see Using callback mode.”

Event mode

Use events when you want the sensor to asynchronously notify your application when the sensor has data available or status has changed..

Event mode allows you to select your own threading model. However, event mode requires that you write your own event loop to handle each sigevent that you've enabled.

For more information, see Using event mode.”

Regardless of the mechanism that you use, it's expected that your application handles at least one buffer at a time. Use the num_user_buffers configuration parameter in your sensor configuration file to specify the number of buffers that are held for applications. The number of buffers that's specified by the num_user_buffers parameter is how many your application requires for processing.