Tizen Native API
5.0
|
The Sensor API provides functions to make use of sensors in the device.
#include <sensor.h>
This Sensor API provides functions to make use of sensors in the device, define new sensor instances from applications, request to record sensor events, and acquire the recorded events. It also provides functions for getting information of a sensor, for example, the vendor and the resolution of its data.
A variety of sensors are typically available on mobile and wearable devices. Regarding the types of sensors, this API is related with the following features:
It is recommended to design feature related codes in your application for reliability.
You can check if a device supports the related features for this API by using System Information, thereby controlling the procedure of your application.
To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.
More details on featuring your application can be found from Feature Element.
Functions | |
int | sensor_is_supported (sensor_type_e type, bool *supported) |
Checks whether a given sensor type is supported in the current device. | |
int | sensor_is_supported_by_uri (const char *uri, bool *supported) |
Checks whether a sensor corresponding to a given URI is supported in the current device. | |
int | sensor_is_wake_up (sensor_h sensor, bool *wakeup) |
Checks whether a given sensor is a wake-up sensor or not. | |
int | sensor_get_default_sensor (sensor_type_e type, sensor_h *sensor) |
Gets the handle for the default sensor of a given type. | |
int | sensor_get_default_sensor_by_uri (const char *uri, sensor_h *sensor) |
Gets the handle for the default sensor of a given sensor URI. | |
int | sensor_get_sensor_list (sensor_type_e type, sensor_h **list, int *sensor_count) |
Gets the handle list of the sensors of a given type. | |
int | sensor_get_sensor_list_by_uri (const char *uri, sensor_h **list, int *sensor_count) |
Gets the handle list of the sensors of a given URI. | |
int | sensor_get_uri (sensor_h sensor, char **uri) |
Gets the URI of a sensor. | |
int | sensor_get_name (sensor_h sensor, char **name) |
Gets the name of a sensor. | |
int | sensor_get_vendor (sensor_h sensor, char **vendor) |
Gets the vendor of a sensor. | |
int | sensor_get_type (sensor_h sensor, sensor_type_e *type) |
Gets the type of a sensor, if it belongs to the known types defined in sensor_type_e. | |
int | sensor_get_min_range (sensor_h sensor, float *min_range) |
Gets the lower bound of the sensor reading of a sensor. | |
int | sensor_get_max_range (sensor_h sensor, float *max_range) |
Gets the upper bound of the sensor readings of a sensor. | |
int | sensor_get_resolution (sensor_h sensor, float *resolution) |
Gets the resolution of the sensor readings of a sensor. | |
int | sensor_get_min_interval (sensor_h sensor, int *min_interval) |
Gets the possible shorted update interval of a sensor. | |
int | sensor_get_fifo_count (sensor_h sensor, int *fifo_count) |
Gets the size of the hardware FIFO of a sensor. | |
int | sensor_get_max_batch_count (sensor_h sensor, int *max_batch_count) |
Gets the maximum batch count of a sensor. | |
int | sensor_add_sensor_added_cb (sensor_added_cb callback, void *user_data) |
Adds a callback function to be invoked when a new sensor is added. | |
int | sensor_remove_sensor_added_cb (sensor_added_cb callback) |
Removes a callback function added using sensor_add_sensor_added_cb(). | |
int | sensor_add_sensor_removed_cb (sensor_removed_cb callback, void *user_data) |
Adds a callback function to be invoked when a sensor is removed. | |
int | sensor_remove_sensor_removed_cb (sensor_removed_cb callback) |
Removes a callback function added using sensor_add_sensor_removed_cb(). | |
Typedefs | |
typedef void * | sensor_h |
Sensor handle. | |
typedef void(* | sensor_added_cb )(const char *uri, void *user_data) |
Called when a new sensor is added. | |
typedef void(* | sensor_removed_cb )(const char *uri, void *user_data) |
Called when a sensor is removed. |
typedef void(* sensor_added_cb)(const char *uri, void *user_data) |
Called when a new sensor is added.
[in] | uri | The URI of the newly added sensor |
[in] | user_data | The user data had passed to sensor_add_sensor_added_cb(). |
typedef void* sensor_h |
Sensor handle.
The handle for controlling a specific sensor can be retrieved using sensor_get_default_sensor().
The function returns the handle of the default sensor of a given type, and usually, a device has one sensor for one type. However, if the device supports multiple sensors of the same type, sensor_get_sensor_list() function can be used to get the list of all the sensors of the type.
typedef void(* sensor_removed_cb)(const char *uri, void *user_data) |
Called when a sensor is removed.
[in] | uri | The URI of the removed sensor |
[in] | user_data | The user data had passed to sensor_add_sensor_removed_cb() |
enum sensor_error_e |
Enumeration for errors.
Enumeration for pedestrian state.
In its sensor_event_s, SENSOR_HUMAN_PEDOMETER reports the user's pedestrian state as one of the followings.
enum sensor_proximity_e |
Enumeration for proximity sensor events.
In its sensor_event_s, SENSOR_PROXIMITY reports the existence of nearby objects in front of the sensor as one of the followings.
enum sensor_sleep_state_e |
Enumeration for sleep state.
In its sensor_event_s, SENSOR_HUMAN_SLEEP_MONITOR reports the user's sleep state as one of the followings.
enum sensor_type_e |
Enumeration for sensor types.
SENSOR_ALL |
All sensors. This can be used to retrieve sensor_h for all available sensors. |
SENSOR_ACCELEROMETER |
Accelerometer |
SENSOR_GRAVITY |
Gravity sensor |
SENSOR_LINEAR_ACCELERATION |
Linear acceleration sensor |
SENSOR_MAGNETIC |
Magnetic sensor |
SENSOR_ROTATION_VECTOR |
Rotation vector sensor |
SENSOR_ORIENTATION |
Orientation sensor |
SENSOR_GYROSCOPE |
Gyroscope |
SENSOR_LIGHT |
Light sensor |
SENSOR_PROXIMITY |
Proximity sensor |
SENSOR_PRESSURE |
Pressure sensor |
SENSOR_ULTRAVIOLET |
Ultraviolet sensor |
SENSOR_TEMPERATURE |
Temperature sensor |
SENSOR_HUMIDITY |
Humidity sensor |
SENSOR_HRM |
Heart-rate monitor (Since 2.3.1) |
SENSOR_HRM_LED_GREEN |
Green LED sensor of HRM (Since 2.3.1) |
SENSOR_HRM_LED_IR |
Infra-Red LED sensor of HRM (Since 2.3.1) |
SENSOR_HRM_LED_RED |
Red LED sensor of HRM (Since 2.3.1) |
SENSOR_GYROSCOPE_UNCALIBRATED |
Uncalibrated Gyroscope sensor (Since 2.4) |
SENSOR_GEOMAGNETIC_UNCALIBRATED |
Uncalibrated Geomagnetic sensor (Since 2.4) |
SENSOR_GYROSCOPE_ROTATION_VECTOR |
Gyroscope-based rotation vector sensor (Since 2.4) |
SENSOR_GEOMAGNETIC_ROTATION_VECTOR |
Geomagnetic-based rotation vector sensor (Since 2.4) |
SENSOR_SIGNIFICANT_MOTION |
Significant motion sensor (Since 4.0) |
SENSOR_HUMAN_PEDOMETER |
Pedometer (Since 3.0) |
SENSOR_HUMAN_SLEEP_MONITOR |
Sleep monitor (Since 3.0) |
SENSOR_HUMAN_SLEEP_DETECTOR |
Sleep detector (Since 3.0) |
SENSOR_HUMAN_STRESS_MONITOR |
Stress monitor (Since 3.0) |
SENSOR_LAST |
End of sensor enum values (Deprecated since 3.0) |
SENSOR_CUSTOM |
Custom sensor (Deprecated since 3.0) |
int sensor_add_sensor_added_cb | ( | sensor_added_cb | callback, |
void * | user_data | ||
) |
Adds a callback function to be invoked when a new sensor is added.
[in] | callback | A callback function to be added |
[in] | user_data | A user data to be passed to the callback function |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_OPERATION_FAILED | Operation failed |
int sensor_add_sensor_removed_cb | ( | sensor_removed_cb | callback, |
void * | user_data | ||
) |
Adds a callback function to be invoked when a sensor is removed.
[in] | callback | A callback function to be removed |
[in] | user_data | A user data to be passed to the callback function |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_OPERATION_FAILED | Operation failed |
int sensor_get_default_sensor | ( | sensor_type_e | type, |
sensor_h * | sensor | ||
) |
Gets the handle for the default sensor of a given type.
This function returns the handle for the sensor of a given type. If the device has more than one sensor of the given type, this function returns the default sensor of the given type, which is designated by the device.
[in] | type | A sensor type to get the handle of its default sensor |
[out] | sensor | The sensor handle of the default sensor |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_NOT_SUPPORTED | The sensor type is not supported in the current device |
SENSOR_ERROR_PERMISSION_DENIED | Permission denied |
int sensor_get_default_sensor_by_uri | ( | const char * | uri, |
sensor_h * | sensor | ||
) |
Gets the handle for the default sensor of a given sensor URI.
This function returns the handle for the sensor of a given URI. If the device has more than one sensor of the given URI, this function returns the default sensor of the URI, which is designated by the device.
See Sensor URIs for more details about the URI format.
[in] | uri | A sensor or a sensor type URI to get the handle of its default sensor |
[out] | sensor | The default sensor handle |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_NOT_SUPPORTED | The URI is not supported in the current device |
SENSOR_ERROR_PERMISSION_DENIED | Permission denied |
int sensor_get_fifo_count | ( | sensor_h | sensor, |
int * | fifo_count | ||
) |
Gets the size of the hardware FIFO of a sensor.
This function returns the size of the hardware FIFO that may be used by a specific sensor to support batching. However, regarding the underlying hardware configuration, the returned count may not mean the maximum number of sensor data that can be batched. See sensor_get_max_batch_count() for such purpose, finding out the possible maximum number of batched data.
[in] | sensor | A sensor handle |
[out] | fifo_count | The FIFO count |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_OPERATION_FAILED | Operation failed |
int sensor_get_max_batch_count | ( | sensor_h | sensor, |
int * | max_batch_count | ||
) |
Gets the maximum batch count of a sensor.
This function returns the maximum number of sensor data events that can be possibly delivered when the batched data are flushed. Therefore, this count can be used to check whether the sensor supports batching or not.
If this returns a positive count, i.e., the sensor supports batching, the count also can be used to guess the possible longest batch latency of the sensor, with respect to the update interval to use.
[in] | sensor | A sensor handle |
[out] | max_batch_count | If the sensor does not support batching, 0; Otherwise a positive integer. |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_OPERATION_FAILED | Operation failed |
int sensor_get_max_range | ( | sensor_h | sensor, |
float * | max_range | ||
) |
Gets the upper bound of the sensor readings of a sensor.
This function returns the upper bound of the range of possible sensor values, which are generated by the corresponding sensor denoted by a sensor handle.
If all sensor values are in the same unit, e.g., or degrees, the upper bound of all sensor values is returned. Otherwise, the upper bound of the representative sensor value, e.g., the step count of SENSOR_HUMAN_PEDOMETER, is returned.
[in] | sensor | A sensor handle |
[out] | max_range | The upper bound |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_OPERATION_FAILED | Operation failed |
int sensor_get_min_interval | ( | sensor_h | sensor, |
int * | min_interval | ||
) |
Gets the possible shorted update interval of a sensor.
[in] | sensor | A sensor handle |
[out] | min_interval | The shorted interval in milliseconds |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_OPERATION_FAILED | Operation failed |
int sensor_get_min_range | ( | sensor_h | sensor, |
float * | min_range | ||
) |
Gets the lower bound of the sensor reading of a sensor.
This function returns the lower bound of the range of possible sensor values, which are generated by the corresponding sensor denoted by a sensor handle.
If all sensor values are in the same unit, e.g., or degrees, the lower bound of all sensor values is returned. Otherwise, the lower bound of the representative sensor value, e.g., the step count of SENSOR_HUMAN_PEDOMETER, is returned.
[in] | sensor | A sensor handle |
[out] | min_range | The lower bound |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_OPERATION_FAILED | Operation failed |
int sensor_get_name | ( | sensor_h | sensor, |
char ** | name | ||
) |
Gets the name of a sensor.
[in] | sensor | A sensor handle |
[out] | name | The name of the sensor |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
int sensor_get_resolution | ( | sensor_h | sensor, |
float * | resolution | ||
) |
Gets the resolution of the sensor readings of a sensor.
This function returns the resolution of the sensor readings. The resolution denotes the smallest difference between sensor readings, each of which is in the range that can be verified by sensor_get_min_range() and sensor_get_max_range().
[in] | sensor | A sensor handle |
[out] | resolution | The resolution |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_OPERATION_FAILED | Operation failed |
int sensor_get_sensor_list | ( | sensor_type_e | type, |
sensor_h ** | list, | ||
int * | sensor_count | ||
) |
Gets the handle list of the sensors of a given type.
A device may have more than one sensors of the given type. In such case, this function can be used to get the handles of all sensors of the type.
The first element of the list denotes the default sensor, which can be retrieved by sensor_get_default_sensor().
[in] | type | A sensor type to get the list of sensor handles |
[out] | list | An array of the sensor handles |
[out] | sensor_count | The number of handles contained in list |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_NOT_SUPPORTED | The sensor type is not supported in the current device |
SENSOR_ERROR_PERMISSION_DENIED | Permission denied |
SENSOR_ERROR_OUT_OF_MEMORY | Out of memory |
int sensor_get_sensor_list_by_uri | ( | const char * | uri, |
sensor_h ** | list, | ||
int * | sensor_count | ||
) |
Gets the handle list of the sensors of a given URI.
A device may have more than one sensor of the given URI. In such case, this function can be used to get the handles of all sensors of the given URI.
See Sensor URIs for more details about the URI format.
[in] | uri | A sensor or a sensor type URI to get the list of sensor handles |
[out] | list | An array of the sensor handles |
[out] | sensor_count | The number of handles contained in list |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_NOT_SUPPORTED | The URI is not supported in the current device |
SENSOR_ERROR_PERMISSION_DENIED | Permission denied |
SENSOR_ERROR_OUT_OF_MEMORY | Out of memory |
int sensor_get_type | ( | sensor_h | sensor, |
sensor_type_e * | type | ||
) |
Gets the type of a sensor, if it belongs to the known types defined in sensor_type_e.
[in] | sensor | A sensor handle |
[out] | type | The type of the sensor |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_NO_DATA | No known sensor type for the given sensor |
SENSOR_ERROR_OPERATION_FAILED | Operation failed |
int sensor_get_uri | ( | sensor_h | sensor, |
char ** | uri | ||
) |
Gets the URI of a sensor.
[in] | sensor | A sensor handle |
[out] | uri | The URI of the sensor |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
int sensor_get_vendor | ( | sensor_h | sensor, |
char ** | vendor | ||
) |
Gets the vendor of a sensor.
[in] | sensor | A sensor handle |
[out] | vendor | The vendor of the sensor |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
int sensor_is_supported | ( | sensor_type_e | type, |
bool * | supported | ||
) |
Checks whether a given sensor type is supported in the current device.
If the given sensor type is not supported, sensor_get_default_sensor() will return an error. It is thus recommended to check the availability of the sensor before actually acquiring sensor_h.
[in] | type | A sensor type to check |
[out] | supported | If supported, true ; Otherwise false |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
int sensor_is_supported_by_uri | ( | const char * | uri, |
bool * | supported | ||
) |
Checks whether a sensor corresponding to a given URI is supported in the current device.
To correctly check the availability of a sensor, a valid URI should be provided. The valid form of URIs is explained in Sensor URIs.
If a URI with the sensor's name is given, for example, http://tizen.org/sensor/general/light/front, the availability of the "front" light sensor is checked. Otherwise, if a URI without the name, http://tizen.org/sensor/general/light, is given, this function checks the availability of any light sensor in the device.
It is recommended to check the availability of the sensors corresponding to the URI before actually acquiring sensor_h.
[in] | uri | A sensor or a sensor type URI to check |
[out] | supported | If supported, true , otherwise false |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
int sensor_is_wake_up | ( | sensor_h | sensor, |
bool * | wakeup | ||
) |
Checks whether a given sensor is a wake-up sensor or not.
If a sensor is a wake-up sensor, the sensor is able to wake-up the system to report its sensor data even if the system is in sleep mode.
[in] | sensor | A sensor handle to check |
[out] | wakeup | If the sensor is a wake-up sensor, true ; Otherwise false |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
sensor
needs to be initialized using sensor_get_default_sensor() or sensor_get_sensor_list() in advance. int sensor_remove_sensor_added_cb | ( | sensor_added_cb | callback | ) |
Removes a callback function added using sensor_add_sensor_added_cb().
[in] | callback | A callback function to be removed |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_OPERATION_FAILED | Operation failed |
int sensor_remove_sensor_removed_cb | ( | sensor_removed_cb | callback | ) |
Removes a callback function added using sensor_add_sensor_removed_cb().
[in] | callback | A callback function to be removed |
SENSOR_ERROR_NONE | Successful |
SENSOR_ERROR_INVALID_PARAMETER | Invalid parameter |
SENSOR_ERROR_OPERATION_FAILED | Operation failed |