2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
28 * @addtogroup CAPI_SYSTEM_SENSOR_MODULE
33 * @brief The upper bound of #sensor_event_s::value_count.
34 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
36 #define MAX_VALUE_SIZE 16
40 * @brief Sensor handle.
41 * @details The handle for controlling a specific sensor can be retrieved using sensor_get_default_sensor().@n
42 * The function returns the handle of the default sensor of a given type, and usually,
43 * a device has one sensor for one type.
44 * However, if the device supports multiple sensors of the same type,
45 * sensor_get_sensor_list() function can be used to get the list of all the sensors of the type.
46 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
48 typedef void* sensor_h;
52 * @brief Sensor listener handle.
53 * @details For each #sensor_h, one or more sensor listeners can be created by using sensor_create_listener().
54 * Then the sensor's data can observed asynchronously, can be read synchronously if available, via the listener.
55 * Applications are also able to control the behavior of each sensor, for example,
56 * update interval of sensor readings.
57 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
59 typedef struct sensor_listener_s *sensor_listener_h;
63 * @brief Sensor data event delivered via sensor_event_cb().
64 * @details A sensor data is delivered as a structure, which contains the accuracy of the data,
65 * the time when the data was observed, and the data array.
66 * The data array is a fixed size @c float array, and the number of data fields
67 * stored in the array varies with the sensor type.
68 * For example, #SENSOR_ACCELEROMETER reports 3-dimensional data,
69 * #sensor_event_s::value_count is thus set to 3.@n
70 * Note that, even if the data values are @c float, in some cases,
71 * it may contain one or more categorical data as in #sensor_proximity_e.
72 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
73 * @see #sensor_pedometer_state_e
74 * @see #sensor_sleep_state_e
78 int accuracy; /**< Accuracy of sensor data */
79 unsigned long long timestamp; /**< Time when the sensor data was observed */
80 int value_count; /**< Number of sensor data values stored in #sensor_event_s::values */
81 float values[MAX_VALUE_SIZE]; /**< Sensor data values */
86 * @brief Enumeration for sensor data accuracy.
87 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
91 SENSOR_DATA_ACCURACY_UNDEFINED = -1, /**< Undefined */
92 SENSOR_DATA_ACCURACY_BAD = 0, /**< Not accurate */
93 SENSOR_DATA_ACCURACY_NORMAL = 1, /**< Moderately accurate */
94 SENSOR_DATA_ACCURACY_GOOD = 2, /**< Highly accurate */
95 SENSOR_DATA_ACCURACY_VERYGOOD = 3 /**< Very highly accurate */
96 } sensor_data_accuracy_e;
100 * @brief Enumeration for errors.
101 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
105 SENSOR_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
106 SENSOR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
107 SENSOR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
108 SENSOR_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
109 SENSOR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
110 SENSOR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
111 SENSOR_ERROR_NOT_NEED_CALIBRATION = TIZEN_ERROR_SENSOR | 0x03, /**< Sensor doesn't need calibration */
112 SENSOR_ERROR_OPERATION_FAILED = TIZEN_ERROR_SENSOR | 0x06, /**< Operation failed */
117 * @brief Enumeration for proximity sensor events.
118 * @details In its #sensor_event_s, #SENSOR_PROXIMITY reports the existence of
119 * nearby objects in front of the sensor as one of the followings.
120 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
124 SENSOR_PROXIMITY_NEAR = 0, /**< An object is placed near the proximity sensor */
125 SENSOR_PROXIMITY_FAR = 5, /**< No object is placed near the proximity sensor */
126 } sensor_proximity_e;
130 * @brief Enumeration for pedestrian state.
131 * @details In its #sensor_event_s, #SENSOR_HUMAN_PEDOMETER reports the user's
132 * pedestrian state as one of the followings.
137 SENSOR_PEDOMETER_STATE_UNKNOWN = -1, /**< Uncertain */
138 SENSOR_PEDOMETER_STATE_STOP, /**< The user is not moving */
139 SENSOR_PEDOMETER_STATE_WALK, /**< The user is walking */
140 SENSOR_PEDOMETER_STATE_RUN, /**< The user is running */
141 } sensor_pedometer_state_e;
145 * @brief Enumeration for sleep state.
146 * @details In its #sensor_event_s, #SENSOR_HUMAN_SLEEP_MONITOR reports the user's
147 * sleep state as one of the followings.
152 SENSOR_SLEEP_STATE_UNKNOWN = -1, /**< Uncertain */
153 SENSOR_SLEEP_STATE_WAKE, /**< The user is awake */
154 SENSOR_SLEEP_STATE_SLEEP, /**< The user is asleep */
155 } sensor_sleep_state_e;
159 * @brief Enumeration for sensor types.
160 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
164 SENSOR_ALL = -1, /**< All sensors. This can be used to retrieve #sensor_h for all available sensors. */
165 SENSOR_ACCELEROMETER, /**< Accelerometer */
166 SENSOR_GRAVITY, /**< Gravity sensor */
167 SENSOR_LINEAR_ACCELERATION, /**< Linear acceleration sensor */
168 SENSOR_MAGNETIC, /**< Magnetic sensor */
169 SENSOR_ROTATION_VECTOR, /**< Rotation vector sensor */
170 SENSOR_ORIENTATION, /**< Orientation sensor */
171 SENSOR_GYROSCOPE, /**< Gyroscope */
172 SENSOR_LIGHT, /**< Light sensor */
173 SENSOR_PROXIMITY, /**< Proximity sensor */
174 SENSOR_PRESSURE, /**< Pressure sensor */
175 SENSOR_ULTRAVIOLET, /**< Ultraviolet sensor */
176 SENSOR_TEMPERATURE, /**< Temperature sensor */
177 SENSOR_HUMIDITY, /**< Humidity sensor */
178 SENSOR_HRM, /**< Heart-rate monitor (Since 2.3.1)
179 @n Privilege : http://tizen.org/privilege/healthinfo */
180 SENSOR_HRM_LED_GREEN, /**< Green LED sensor of HRM (Since 2.3.1)
181 @n Privilege : http://tizen.org/privilege/healthinfo */
182 SENSOR_HRM_LED_IR, /**< Infra-Red LED sensor of HRM (Since 2.3.1)
183 @n Privilege : http://tizen.org/privilege/healthinfo */
184 SENSOR_HRM_LED_RED, /**< Red LED sensor of HRM (Since 2.3.1)
185 @n Privilege : http://tizen.org/privilege/healthinfo */
186 SENSOR_GYROSCOPE_UNCALIBRATED, /**< Uncalibrated Gyroscope sensor
187 @if MOBILE (Since 2.4) @elseif WEARABLE (Since 3.0) @endif */
188 SENSOR_GEOMAGNETIC_UNCALIBRATED, /**< Uncalibrated Geomagnetic sensor
189 @if MOBILE (Since 2.4) @elseif WEARABLE (Since 3.0) @endif */
190 SENSOR_GYROSCOPE_ROTATION_VECTOR, /**< Gyroscope-based rotation vector sensor
191 @if MOBILE (Since 2.4) @elseif WEARABLE (Since 3.0) @endif */
192 SENSOR_GEOMAGNETIC_ROTATION_VECTOR, /**< Geomagnetic-based rotation vector sensor
193 @if MOBILE (Since 2.4) @elseif WEARABLE (Since 3.0) @endif */
194 SENSOR_HUMAN_PEDOMETER = 0x300, /**< Pedometer (Since 3.0)
195 @n Privilege : http://tizen.org/privilege/healthinfo */
196 SENSOR_HUMAN_SLEEP_MONITOR, /**< Sleep monitor (Since 3.0)
197 @n Privilege : http://tizen.org/privilege/healthinfo */
198 SENSOR_LAST, /**< End of sensor enum values (Deprecated since 3.0) */
199 SENSOR_CUSTOM = 0x2710, /**< Custom sensor (Deprecated since 3.0) */
204 * @brief Enumeration for sensor options.
205 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
207 #ifndef __SENSOR_COMMON_H__
210 SENSOR_OPTION_DEFAULT, /**< Does not receive data when the LCD is off and in the power save mode */
211 SENSOR_OPTION_ON_IN_SCREEN_OFF, /**< Receives data when the LCD is off */
212 SENSOR_OPTION_ON_IN_POWERSAVE_MODE, /**< Receives data in the power save mode */
213 SENSOR_OPTION_ALWAYS_ON, /**< Receives data when the LCD is off and in the power save mode */
219 * @brief Enumeration for sensor listener behavior attributes
224 SENSOR_ATTRIBUTE_AXIS_ORIENTATION = 1, /**< Reference orientation of sensor data to be reported.@n
225 See #sensor_axis_e for available attribute values. */
226 SENSOR_ATTRIBUTE_PAUSE_POLICY, /**< Pause-and-resume policy of sensors.@n
227 See #sensor_pause_e for available attribute values. */
228 } sensor_attribute_e;
232 * @brief Enumeration for reference orientations of sensor data
233 * @details The sensor's physical orientation may differ from what applications are aware of,
234 * in cases that the device has a rotated screen, physically or logically.
235 * For example, a watch device may have right hand mode, which logically rotates
236 * the display 180 degrees.
237 * Applications may not be aware of such situations, thus they may receives
238 * sensor data inverted in X and Y directions.
239 * With #SENSOR_AXIS_DISPLAY_ORIENTED option, applications can get data that
240 * are properly aligned with the orientation of which they are aware.@n
241 * By default, #SENSOR_AXIS_DISPLAY_ORIENTED is used.
242 * If you need to use the data that are not affected by display orientations,
243 * #SENSOR_AXIS_DEVICE_ORIENTED needs to be set.
248 SENSOR_AXIS_DEVICE_ORIENTED = 1, /**< Using the device orientation as the reference coordinate system */
249 SENSOR_AXIS_DISPLAY_ORIENTED, /**< Using the display orientation as the reference coordinate system */
254 * @brief Enumeration for pause policies of sensor listeners
255 * @details To be power-efficient, you can set the policy of how to pause and resume
256 * a sensor listener regarding the system status.
257 * By default, #SENSOR_PAUSE_ALL is used to obtain the maximum power efficiency.
262 SENSOR_PAUSE_NONE = 0, /**< The sensor will not pause, unless the system goes into sleep mode */
263 SENSOR_PAUSE_ON_DISPLAY_OFF = 1, /**< The sensor pauses while the display is off*/
264 SENSOR_PAUSE_ON_POWERSAVE_MODE = 2, /**< The sensor pauses while the power-save mode is enabled */
265 SENSOR_PAUSE_ALL = 3, /**< The sensor pauses in all the above cases */
270 * @brief Checks whether a given sensor type is supported in the current device.
271 * @details If the given sensor type is not supported, sensor_get_default_sensor() will return an error.
272 * It is thus recommended to check the availability of the sensor before actually acquiring #sensor_h.
273 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
275 * @param[in] type A sensor type to check
276 * @param[out] supported If supported, @c true; Otherwise @c false
278 * @return #SENSOR_ERROR_NONE on success; Otherwise a negative error value
279 * @retval #SENSOR_ERROR_NONE Successful
280 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
282 int sensor_is_supported(sensor_type_e type, bool *supported);
286 * @brief Gets the handle for the default sensor of a given type.
287 * @details This function returns the handle for the sensor of a given type,
288 * if the device has one sensor of the given type.
289 * In case that the device has more than one sensors of the type,
290 * this returns only the default sensor, which is designated by the device.@n
291 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
293 * @remarks Some sensor types are privileged. An application should have the privilege
294 * http://tizen.org/privilege/healthinfo to get handles for the following sensors:
295 * #SENSOR_HRM, #SENSOR_HRM_LED_GREEN, #SENSOR_HRM_LED_IR, #SENSOR_HRM_LED_RED,
296 * #SENSOR_HUMAN_PEDOMETER, and #SENSOR_HUMAN_SLEEP_MONITOR.
298 * @param[in] type A sensor type to get the handle of its default sensor
299 * @param[out] sensor The sensor handle of the default sensor
301 * @return #SENSOR_ERROR_NONE on success; Otherwise a negative error value
302 * @retval #SENSOR_ERROR_NONE Successful
303 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
304 * @retval #SENSOR_ERROR_NOT_SUPPORTED The sensor type is not supported in the current device
305 * @retval #SENSOR_ERROR_PERMISSION_DENIED Permission denied
307 * @see sensor_get_sensor_list()
309 int sensor_get_default_sensor(sensor_type_e type, sensor_h *sensor);
313 * @brief Gets the handle list of the sensors of a given type.
314 * @details A device may have more than one sensors of the given type.
315 * In such case, this function can be used to get the handles of all sensors of the type.@n
316 * The first element of the @c list denotes the default sensor,
317 * which can be retrieved by sensor_get_default_sensor().
318 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
320 * @remarks Some sensor types are privileged. An application should have the privilege
321 * http://tizen.org/privilege/healthinfo to get handles for the following sensors:
322 * #SENSOR_HRM, #SENSOR_HRM_LED_GREEN, #SENSOR_HRM_LED_IR, #SENSOR_HRM_LED_RED,
323 * #SENSOR_HUMAN_PEDOMETER, and #SENSOR_HUMAN_SLEEP_MONITOR.@n
324 * Instead of specifying a sensor type, by using #SENSOR_ALL,
325 * applications can get the list of handles for all available sensors.@n
326 * The @c list must be released using @c free(), if not being used anymore.@n
328 * @param[in] type A sensor type to get the list of sensor handles
329 * @param[out] list An array of the sensor handles
330 * @param[out] sensor_count The number of handles contained in @c list
332 * @return #SENSOR_ERROR_NONE on success; Otherwise a negative error value
333 * @retval #SENSOR_ERROR_NONE Successful
334 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
335 * @retval #SENSOR_ERROR_NOT_SUPPORTED The sensor type is not supported in the current device
336 * @retval #SENSOR_ERROR_PERMISSION_DENIED Permission denied
337 * @retval #SENSOR_ERROR_OUT_OF_MEMORY Out of memory
339 int sensor_get_sensor_list(sensor_type_e type, sensor_h **list, int *sensor_count);
343 * @brief Checks whether a given sensor is a wake-up sensor or not.
344 * @details If a sensor is a wake-up sensor, the sensor is able to wake-up the system
345 * to report its sensor data even if the system is in sleep mode.
348 * @param[in] sensor A sensor handle to check
349 * @param[out] wakeup If the sensor is a wake-up sensor, @c true;
352 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
353 * @retval #SENSOR_ERROR_NONE Successful
354 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
356 * @pre The handle @c sensor needs to be initialized using
357 * sensor_get_default_sensor() or sensor_get_sensor_list() in advance.
359 int sensor_is_wake_up(sensor_h sensor, bool *wakeup);
363 * @brief Called when a sensor event occurs.
364 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
366 * @param[in] sensor The corresponding sensor handle
367 * @param[in] event A sensor event
368 * @param[in] data The user data had passed to sensor_listener_set_event_cb()
370 * @pre The sensor needs to be started regarding a listener handle, using sensor_listener_start().
372 typedef void (*sensor_event_cb)(sensor_h sensor, sensor_event_s *event, void *data);
376 * @brief Creates a sensor listener.
377 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
379 * @remarks The @c listener must be released using sensor_destroy_listener().
381 * @param[in] sensor A sensor handle
382 * @param[out] listener A listener handle of @c sensor
384 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
385 * @retval #SENSOR_ERROR_NONE Successful
386 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
387 * @retval #SENSOR_ERROR_OUT_OF_MEMORY Out of memory
388 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
390 * @pre The handle @c sensor needs to be initialized using
391 * sensor_get_default_sensor() or sensor_get_sensor_list() in advance.
393 int sensor_create_listener(sensor_h sensor, sensor_listener_h *listener);
397 * @brief Releases all the resources allocated for a listener.
398 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
400 * @remarks If this function is called while the sensor is still running,
401 * that is, sensor_listener_start() was called but sensor_listener_stop() was not,
402 * then it is implicitly stopped.
404 * @param[in] listener A listener handle
406 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
407 * @retval #SENSOR_ERROR_NONE Successful
408 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
410 * @see sensor_create_listener()
412 int sensor_destroy_listener(sensor_listener_h listener);
416 * @brief Starts observing the sensor events regarding a given sensor listener.
417 * @details If a sensor listener is started, its event callback function starts to be called
418 * whenever the corresponding sensor events occur.@n
419 * For example, #SENSOR_ACCELEROMETER reports its sensor readings repeatedly,
420 * with a specific update interval.
421 * Note that, unlike the accelerometer, sensors like #SENSOR_PROXIMITY emit events
422 * only if their states change.
423 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
425 * @param[in] listener A listener handle
427 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
428 * @retval #SENSOR_ERROR_NONE Successful
429 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
430 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
432 * @pre The @c listener needs to be created in advance, by using sensor_create_listener().
433 * Then the callback function needs to be attached to the @c listener, by using
434 * sensor_listener_set_event_cb().
435 * @see sensor_listener_stop()
437 int sensor_listener_start(sensor_listener_h listener);
441 * @brief Stops observing the sensor events regarding a given sensor listener.
442 * @details The listener's event callback function stops being called.
443 * But the sensor itself may not be stopped if there are other listeners
444 * that are using the same sensor.
445 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
447 * @param[in] listener A listener handle
449 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
450 * @retval #SENSOR_ERROR_NONE Successful
451 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
452 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
454 * @see sensor_listener_start()
456 int sensor_listener_stop(sensor_listener_h listener);
460 * @brief Registers the callback function to be invoked when sensor events are delivered via a sensor listener.
461 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
463 * @param[in] listener A listener handle
464 * @param[in] interval_ms A desired update interval between sensor events in milliseconds.@n
465 * If 0, it will be automatically set to the default interval of the corresponding sensor.@n
466 * See sensor_listener_set_interval() for more details.
467 * @param[in] callback A callback function to attach with the @c listener handle
468 * @param[in] data A user data to be passed to the callback function
470 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
471 * @retval #SENSOR_ERROR_NONE Successful
472 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
473 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
475 * @see sensor_listener_unset_event_cb()
477 int sensor_listener_set_event_cb(sensor_listener_h listener, unsigned int interval_ms, sensor_event_cb callback, void *data);
481 * @brief Unregisters the sensor event callback function attached to a given sensor listener.
482 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
484 * @param[in] listener A listener handle
486 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
487 * @retval #SENSOR_ERROR_NONE Successful
488 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
489 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
491 * @see sensor_listener_set_event_cb()
493 int sensor_listener_unset_event_cb(sensor_listener_h listener);
497 * @brief Called when the accuracy of a sensor changes.
498 * @details Sensors can be affected by the environment.
499 * For example, #SENSOR_MAGNETIC is sensitive to any surrounding objects that can influence
500 * electromagnetic fields. This function is called if the accuracy of the corresponding sensor is changed.
501 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
503 * @param[in] sensor A sensor handle
504 * @param[in] timestamp The time in milliseconds when the accuracy changed
505 * @param[in] accuracy The current accuracy of the sensor
506 * @param[in] data The user data had passed to sensor_listener_set_accuracy_cb()
508 typedef void (*sensor_accuracy_changed_cb)(sensor_h sensor, unsigned long long timestamp, sensor_data_accuracy_e accuracy, void *data);
512 * @brief Registers the callback function to be invoked when the accuracy of a sensor changes.
513 * @details In addition to sensor_event_cb(), sensor_accuracy_changed_cb() also can be attached
514 * to sensor listeners. With this accuracy callback function, applications can be notified
515 * the changes of the corresponding sensors separately.
516 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
518 * @param[in] listener A listener handle
519 * @param[in] callback A callback function to attach with the @c listener handle
520 * @param[in] data A user data to be passed to the callback function
522 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
523 * @retval #SENSOR_ERROR_NONE Successful
524 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
525 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
527 * @pre The @c listener needs to be started to get the change callbacks.
528 * @see sensor_listener_unset_accuracy_cb()
530 int sensor_listener_set_accuracy_cb(sensor_listener_h listener, sensor_accuracy_changed_cb callback, void *data);
534 * @brief Unregisters the sensor accuracy change callback function attached to a given sensor listener.
535 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
537 * @param[in] listener A listener handle
539 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
540 * @retval #SENSOR_ERROR_NONE Successful
541 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
542 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
544 * @see sensor_listener_set_accuracy_cb()
546 int sensor_listener_unset_accuracy_cb(sensor_listener_h listener);
550 * @brief Reads the current sensor data via a given sensor listener.
551 * @details This function synchronously reads the sensor reading of the corresponding sensor, if available.
552 * Otherwise, if the sensor is not ready to report its values, this function fails and returns
553 * #SENSOR_ERROR_OPERATION_FAILED.
554 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
556 * @remark As a sensor usually works in an event-driven manner, it may not be able to read its data on demand.
557 * Then this function tries to return the last known values.@n
558 * To be able to read the current values or the last known values, the sensor needs to be
559 * enabled in advance. As an application cannot be sure that the sensor is already enabled
560 * by other applications, it is recommended to start the sensor explicitly by using sensor_listener_start().@n
561 * But note that, even if the sensor is started, on-demand reading can fail always,
562 * thus it would be better to use the asynchronous callback approach.
564 * @param[in] listener A listener handle
565 * @param[out] event The retrieved sensor data
567 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
568 * @retval #SENSOR_ERROR_NONE Successful
569 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
570 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
572 int sensor_listener_read_data(sensor_listener_h listener, sensor_event_s *event);
576 * @brief Changes the update interval of a sensor.
577 * @details The specified interval is only a suggested interval between sensor measurements.
578 * You will get at least one sensor measurement within the interval you specify,
579 * but the actual interval between sensor measurements can be affected by other applications and the system.
580 * To reduce the system overhead, it is recommended to set the longest interval that you can,
581 * because the system usually chooses the shortest interval among all intervals specified.
582 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
584 * @remarks Normally, a sensor's default update interval is 100 ms,
585 * and you can use the default interval by setting the interval to 0.
586 * However, please note that, the default interval varies with the sensor and the device.@n
587 * In addition, a sensor has the lower and the upper bound of its update interval,
588 * usually 10 and 1000 ms respectively.
589 * These lower and upper bounds also can vary with the sensor and the device,
590 * any invalid input values exceeding the bounds will be implicitly adjusted into the valid range.
592 * @param[in] listener A listener handle
593 * @param[in] interval_ms A desired update interval between sensor events in milliseconds.
594 * If 0, it will be automatically set to the default interval of the corresponding sensor.
596 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
597 * @retval #SENSOR_ERROR_NONE Successful
598 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
599 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
601 * @see sensor_get_min_interval()
603 int sensor_listener_set_interval(sensor_listener_h listener, unsigned int interval_ms);
607 * @brief Sets the desired max batch latency of a sensor.
608 * @details Sensors that support batching may allow applications to change their maximum batch latencies.
609 * For example, if you set the latency as 10,000 ms, the sensor may store its data
610 * up to 10,000 ms, before delivering the data through the HAL.@n
611 * In cases of non-batching sensors, this function returns #SENSOR_ERROR_NONE,
612 * but nothing is affected by the input latency value.
613 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
615 * @remarks Even if you set a batch latency, the sensor may not work as you intended,
616 * as one sensor can be used by more than one listeners.
617 * In addition, some batch sensors may already have fixed batching latency
618 * or batching queue size, which cannot be altered by applications.
620 * @param[in] listener A listener handle
621 * @param[in] max_batch_latency A desired batch latency in milliseconds
623 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
624 * @retval #SENSOR_ERROR_NONE Successful
625 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
627 int sensor_listener_set_max_batch_latency(sensor_listener_h listener, unsigned int max_batch_latency);
631 * @brief Sets an attribute to control the behavior of a sensor listener.
632 * @details Applications can change the behavior of a sensor listener, for example,
633 * what is the reference coordinate of the sensor values,
634 * and when the system is allowed to turn off the sensor implicitly to reduce the power consumption.
635 * See #sensor_attribute_e for more details about the available control parameters.
638 * @param[in] listener A listener handle
639 * @param[in] attribute An attribute to change
640 * @param[in] value An attribute value
642 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
643 * @retval #SENSOR_ERROR_NONE Successful
644 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
646 int sensor_listener_set_attribute_int(sensor_listener_h listener, sensor_attribute_e attribute, int value);
650 * @brief Changes the power-saving behavior of a sensor listener.
651 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
653 * @remark sensor_listener_set_attribute_int() with #SENSOR_ATTRIBUTE_PAUSE_POLICY replaces this function.
655 * @param[in] listener A listener handle
656 * @param[in] option A sensor option
658 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
659 * @retval #SENSOR_ERROR_NONE Successful
660 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
661 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
663 int sensor_listener_set_option(sensor_listener_h listener, sensor_option_e option);
670 * @addtogroup CAPI_SYSTEM_SENSOR_INFORMATION_MODULE
675 * @brief Gets the name of a sensor.
676 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
678 * @param[in] sensor A sensor handle
679 * @param[out] name The name of the sensor
681 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
682 * @retval #SENSOR_ERROR_NONE Successful
683 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
685 int sensor_get_name(sensor_h sensor, char **name);
689 * @brief Gets the vendor of a sensor.
690 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
692 * @param[in] sensor A sensor handle
693 * @param[out] vendor The vendor of the sensor
695 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
696 * @retval #SENSOR_ERROR_NONE Successful
697 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
699 int sensor_get_vendor(sensor_h sensor, char **vendor);
703 * @brief Gets the sensor type of a sensor.
704 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
706 * @param[in] sensor A sensor handle
707 * @param[out] type The type of the sensor
709 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
710 * @retval #SENSOR_ERROR_NONE Successful
711 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
712 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
714 int sensor_get_type(sensor_h sensor, sensor_type_e *type);
718 * @brief Gets the lower bound of the sensor reading of a sensor.
719 * @details This function returns the lower bound of the range of possible sensor values,
720 * which are generated by the corresponding sensor denoted by a sensor handle.@n
721 * If all sensor values are in the same unit, e.g., \f$\mbox{m/s}^2\f$ or degrees,
722 * the lower bound of all sensor values is returned.
723 * Otherwise, the lower bound of the representative sensor value, e.g.,
724 * the step count of #SENSOR_HUMAN_PEDOMETER, is returned.
725 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
727 * @param[in] sensor A sensor handle
728 * @param[out] min_range The lower bound
730 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
731 * @retval #SENSOR_ERROR_NONE Successful
732 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
733 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
735 * @see sensor_get_max_range()
737 int sensor_get_min_range(sensor_h sensor, float *min_range);
741 * @brief Gets the upper bound of the sensor readings of a sensor.
742 * @details This function returns the upper bound of the range of possible sensor values,
743 * which are generated by the corresponding sensor denoted by a sensor handle.@n
744 * If all sensor values are in the same unit, e.g., \f$\mbox{m/s}^2\f$ or degrees,
745 * the upper bound of all sensor values is returned.
746 * Otherwise, the upper bound of the representative sensor value, e.g.,
747 * the step count of #SENSOR_HUMAN_PEDOMETER, is returned.
748 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
750 * @param[in] sensor A sensor handle
751 * @param[out] max_range The upper bound
753 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
754 * @retval #SENSOR_ERROR_NONE Successful
755 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
756 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
758 * @see sensor_get_min_range()
760 int sensor_get_max_range(sensor_h sensor, float *max_range);
764 * @brief Gets the resolution of the sensor readings of a sensor.
765 * @details This function returns the resolution of the sensor readings.
766 * The resolution denotes the smallest difference between sensor readings,
767 * each of which is in the range that can be verified by
768 * sensor_get_min_range() and sensor_get_max_range().
769 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
771 * @param[in] sensor A sensor handle
772 * @param[out] resolution The resolution
774 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
775 * @retval #SENSOR_ERROR_NONE Successful
776 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
777 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
779 int sensor_get_resolution(sensor_h sensor, float *resolution);
783 * @brief Gets the possible shorted update interval of a sensor.
784 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
786 * @param[in] sensor A sensor handle
787 * @param[out] min_interval The shorted interval in milliseconds
789 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
790 * @retval #SENSOR_ERROR_NONE Successful
791 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
792 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
794 int sensor_get_min_interval(sensor_h sensor, int *min_interval);
798 * @brief Gets the size of the hardware FIFO of a sensor.
799 * @details This function returns the size of the hardware FIFO that may be used by
800 * a specific sensor to support batching.
801 * However, regarding the underlying hardware configuration,
802 * the returned count may not mean the maximum number of sensor data that can be batched.
803 * See sensor_get_max_batch_count() for such purpose, finding out the
804 * possible maximum number of batched data.
805 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
807 * @param[in] sensor A sensor handle
808 * @param[out] fifo_count The FIFO count
810 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
811 * @retval #SENSOR_ERROR_NONE Successful
812 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
813 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
815 int sensor_get_fifo_count(sensor_h sensor, int *fifo_count);
819 * @brief Gets the maximum batch count of a sensor.
820 * @details This function returns the maximum number of sensor data events
821 * that can be possibly delivered when the batched data are flushed.
822 * Therefore, this count can be used to check whether the sensor supports
824 * If this returns a positive count, i.e., the sensor supports batching,
825 * the count also can be used to guess the possible longest batch latency
826 * of the sensor, with respect to the update interval to use.
827 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
829 * @param[in] sensor A sensor handle
830 * @param[out] max_batch_count If the sensor does not support batching, 0;
831 * Otherwise a positive integer.
833 * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
834 * @retval #SENSOR_ERROR_NONE Successful
835 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
836 * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
838 * @see sensor_listener_set_max_batch_latency()
840 int sensor_get_max_batch_count(sensor_h sensor, int *max_batch_count);
846 * @addtogroup CAPI_SYSTEM_SENSOR_UTILITY_MODULE
851 * @brief Enumeration of the axis used in sensor_util_remap_coordinate_system().
852 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
856 SENSOR_UTIL_AXIS_MINUS_X = 0, /**< -X */
857 SENSOR_UTIL_AXIS_MINUS_Y, /**< -Y */
858 SENSOR_UTIL_AXIS_MINUS_Z, /**< -Z */
859 SENSOR_UTIL_AXIS_X, /**< +X */
860 SENSOR_UTIL_AXIS_Y, /**< +Y */
861 SENSOR_UTIL_AXIS_Z, /**< +Z */
862 sensor_util_axis_minus_x = SENSOR_UTIL_AXIS_MINUS_X,
863 sensor_util_axis_minus_y,
864 sensor_util_axis_minus_z,
868 } sensor_util_axis_e;
871 * @brief Gets the inclination matrix "I" and rotation matrix "R" transforming a vector from the device coordinate to the world's coordinate.
873 * @details [0 0 g] = R * gravity (g = magnitude of gravity) \n
874 * [0 m 0] = I * R * geomagnetic (m = magnitude of the geomagnetic field) \n
875 * R is the identity matrix when the device is aligned with the world's coordinate system, that is, when the device's X axis points towards the East, the Y axis points to the North Pole and the device is facing the sky. \n
876 * I is a rotation matrix transforming the geomagnetic vector into the same coordinate space as gravity (the world's coordinate space). I is a simple rotation around the X axis. \n
877 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
879 * @remarks Parameters Gx, Gy, and Gz can be obtained from the values returned by #SENSOR_GRAVITY. \n
880 * Parameters Mx, My, and Mz can be obtained from the values returned by #SENSOR_MAGNETIC.
881 * Output parameter R and I are always returned as a 3x3 matrix array of 9 floats like this form:
883 * { R[0], R[1], R[2],
889 * @param[in] Gx The X-axis gravity vector in the device's coordinate
890 * @param[in] Gy The Y-axis gravity vector in the device's coordinate
891 * @param[in] Gz The Z-axis gravity vector in the device's coordinate
892 * @param[in] Mx The X-axis geomagnetic vector in the device's coordinate
893 * @param[in] My The Y-axis geomagnetic vector in the device's coordinate
894 * @param[in] Mz The Z-axis geomagnetic vector in the device's coordinate
895 * @param[out] R The array of 9 floats that represent the rotation matrix "R" \n
897 * @param[out] I The array of 9 floats that represent the inclination matrix "I" \n
900 * @return #SENSOR_ERROR_NONE on success; Otherwise a negative error value
901 * @retval #SENSOR_ERROR_NONE Successful
902 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
904 int sensor_util_get_rotation_matrix(float Gx, float Gy, float Gz,
905 float Mx, float My, float Mz,
906 float R[], float I[]);
909 * @brief Converts a rotation vector to a rotation matrix.
911 * @details Rotation vectors (Vx, Vy, Vz) can be obtained from #SENSOR_ROTATION_VECTOR.
912 * It returns a 9 element rotation matrix in the array R. R must have length as 9.
913 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
915 * @param[in] Vx The X-axis rotation vector
916 * @param[in] Vy The Y-axis rotation vector
917 * @param[in] Vz The Z-axis rotation vector
918 * @param[out] R A 9 element rotation matrix in the array R that must have length as 9
920 * @return #SENSOR_ERROR_NONE on success; Otherwise a negative error value
921 * @retval #SENSOR_ERROR_NONE Successful
922 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
924 int sensor_util_get_rotation_matrix_from_vector(float Vx, float Vy, float Vz, float R[]);
927 * @brief Rotates the supplied rotation matrix so that it is expressed in a different coordinate system.
929 * @details This is typically used when an application needs to compute the three orientation angles of the device in a different coordinate system.
930 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
932 * @remarks inR and outR can be the same array, but this is not recommended for performance reasons.
933 * This returns an error when X and Y define the same axis.
935 * @param[in] inR The rotation matrix (3x3) to be transformed
936 * @param[in] x The world axis and direction on which the X axis of the device is mapped
937 * @param[in] y The world axis and direction on which the Y axis of the device is mapped
938 * @param[out] outR The transformed rotation matrix (3x3)
940 * @return #SENSOR_ERROR_NONE on success; Otherwise a negative error value
941 * @retval #SENSOR_ERROR_NONE Successful
942 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
945 int sensor_util_remap_coordinate_system(float inR[], sensor_util_axis_e x, sensor_util_axis_e y, float outR[]);
948 * @brief Computes the geomagnetic inclination angle in radians from the inclination matrix I returned by sensor_util_get_rotation_matrix().
949 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
951 * @param[in] I The inclination matrix from sensor_util_get_rotation_matrix()
952 * @param[out] inclination The geomagnetic inclination angle in radians
954 * @return #SENSOR_ERROR_NONE on success; Otherwise a negative error value
955 * @retval #SENSOR_ERROR_NONE Successful
956 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
958 * @see sensor_util_get_rotation_matrix()
960 int sensor_util_get_inclination(float I[], float* inclination);
963 * @brief Computes the device's orientation based on the rotation matrix.
965 * @details When it returns, the array values are filled with the result:
966 * - values[0]: azimuth, rotation around the Z axis.
967 * - values[1]: pitch, rotation around the X axis.
968 * - values[2]: roll, rotation around the Y axis.
969 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
971 * @remarks Parameter R must be an array of 9 floats from sensor_util_get_rotation_matrix() \n
972 * Returned values are always arrays of 3 floats.
974 * @param[in] R A 9 element rotation matrix in the array
975 * @param[out] values An array of 3 floats to hold the result
977 * @return #SENSOR_ERROR_NONE on success; Otherwise a negative error value
978 * @retval #SENSOR_ERROR_NONE Successful
979 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
981 * @see sensor_util_get_rotation_matrix()
984 int sensor_util_get_orientation(float R[], float values[]);
987 * @brief Computes the angle change between two rotation matrices.
989 * @details Given a current rotation matrix (R) and a previous rotation matrix (prevR), it computes
990 * the rotation around the x,y, and z axes which transforms prevR to R.
991 * It outputs a 3 element vector containing the x,y, and z angle change at indexes 0, 1, and 2 respectively. \n
992 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
994 * @remarks Each input matrix is a 3x3 matrix like this form:
996 * { R[0], R[1], R[2],
1001 * @param[in] R The current rotation matrix
1002 * @param[in] prevR The previous rotation matrix
1003 * @param[out] angleChange An array of floats in which the angle change is stored
1005 * @return #SENSOR_ERROR_NONE on success; Otherwise a negative error value
1006 * @retval #SENSOR_ERROR_NONE Successful
1007 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
1009 int sensor_util_get_angle_change(float R[], float prevR[], float angleChange[]);
1012 * @brief Gets the declination of the horizontal component of the magnetic field from true north, in degrees.
1013 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
1015 * @param[in] latitude The latitude in geodetic coordinates
1016 * @param[in] longitude The longitude in geodetic coordinates
1017 * @param[in] altitude The altitude in geodetic coordinates
1018 * @param[out] declination The declination of the horizontal component of the magnetic field in degrees
1020 * @return #SENSOR_ERROR_NONE on success; Otherwise a negative error value
1021 * @retval #SENSOR_ERROR_NONE Successful
1022 * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
1024 int sensor_util_get_declination(float latitude, float longitude, float altitude, float* declination);
1033 #endif /* __SENSOR_H__ */