Updated: October 28, 2024 |
Applications use a handle provided through the Sensor API to access each of the logical sensor units that are configured in the sensor configuration file.
Before you can do anything with a sensor, you need to first request a handle to a logical sensor unit from the Sensor library. Your application uses this handle to make use of a given sensor through the Sensor API. To request a sensor handle, call sensor_open(). For example:
int err; sensor_unit_t unit = SENSOR_UNIT_1; sensor_handle_t handle = SENSOR_HANDLE_INVALID; ... err = sensor_open(unit, SENSOR_ACCESSMODE_DATA, &handle); ...
When you call sensor_open(), you must specify the following:
When sensor_open() returns successfully, the library provides you with a handle, in the handle argument of the function call, that you can use throughout your application to access the specified sensor.
After you are finished using a sensor data unit, you must close the connection so the Sensor library releases all the resources that it allocated for this sensor unit. To close a connection to a sensor, call sensor_close(). For example:
int err; ... err = sensor_close(handle); ...
The handle that you pass into the sensor_close() function must have been a handle that was requested with sensor_open().