#ifndef __SENSOR_H__
#define __SENSOR_H__
-#include <tizen_error.h>
-#include <tizen_type.h>
+#include <tizen.h>
#ifdef __cplusplus
extern "C"
SENSOR_MOTION_SNAP_NONE, /**< No Snap */
SENSOR_MOTION_SNAP_LEFT, /**< Snap left to right */
SENSOR_MOTION_SNAP_RIGHT, /**< Snap right to left */
+ SENSOR_MOTION_SNAP_X_POSITIVE = SENSOR_MOTION_SNAP_RIGHT, /**< Snap to positive direction in X-axis, it is the same as @SENSOR_MOTION_SNAP_RIGHT */
+ SENSOR_MOTION_SNAP_X_NEGATIVE = SENSOR_MOTION_SNAP_LEFT, /**< Snap to negative direction in X-axis, it is the same as @SENSOR_MOTION_SNAP_LEFT */
+ SENSOR_MOTION_SNAP_Y_POSITIVE, /**< Snap to positive direction in Y-axis */
+ SENSOR_MOTION_SNAP_Y_NEGATIVE, /**< Snap to Negative direction in Y-axis */
+ SENSOR_MOTION_SNAP_Z_POSITIVE, /**< Snap to positive direction in Z-axis */
+ SENSOR_MOTION_SNAP_Z_NEGATIVE, /**< Snap to Negative direction in Z-axis */
} sensor_motion_snap_e;
/**
* @}
/**
* @brief Called when an accelerometer event occurs.
*
+ * @param[in] timestamp The time in nanosecond at which the event ahppened
* @param[in] accuracy The accuracy of @a x, @a y, and @a z values
* @param[in] x The acceleration minus Gx on the x-axis in [m/s^2]
* @param[in] y The acceleration minus Gy on the y-axis in [m/s^2]
* @see sensor_accelerometer_set_cb()
* @see sensor_accelerometer_unset_cb()
*/
-typedef void (*sensor_accelerometer_event_cb)(
+typedef void (*sensor_accelerometer_event_cb)( unsigned long long timestamp,
sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data);
/**
* @}
* Measure the rate of rotation around X, Y and Z axis in radians/second values.
* All values is observed by positive value in the counter-clockwise direction.
*
+ * @param[in] timestamp The time in nanosecond at which the event ahppened
* @param[in] accuracy The accuracy of @a x, @a y, and @a z values
* @param[in] x Angular speed around the x-axis in degree per second
* @param[in] y Angular speed around the y-axis in degree per second
* @see sensor_gyroscope_set_cb()
* @see sensor_gyroscope_unset_cb()
*/
-typedef void (*sensor_gyroscope_event_cb)(
+typedef void (*sensor_gyroscope_event_cb)( unsigned long long timestamp,
sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data);
/**
* @}
* You should use lux between min and max values obtained \n
* with #sensor_get_spec().
*
- * @param[in] accuracy The accuracy of @a level, @a y, and @a z values
+ * @param[in] timestamp The time in nanosecond at which the event ahppened
* @param[in] lux The ambient light level in SI lux units \n
* @a lux is between min and max values obtained with #sensor_get_spec().\n
* @param[in] user_data The user data passed from the callback registration function
* @see sensor_light_set_cb()
* @see sensor_light_unset_cb()
*/
-typedef void (*sensor_light_event_cb)(
- sensor_data_accuracy_e accuracy, float lux, void *user_data);
+typedef void (*sensor_light_event_cb)( unsigned long long timestamp, float lux, void *user_data);
/**
* @}
*/
*
* @remark @a x, @a y, and @a z values are in micro-Teslas(uT) and measure the ambient magnetic field in the X, Y and Z axis.
*
+ * @param[in] timestamp The time in nanosecond at which the event ahppened
* @param[in] accuracy The accuracy of @a x, @a y, and @a z values
* @param[in] x Micro-Tesla value from ambient magnetic field on the x-axis
* @param[in] y Micro-Tesla value from ambient magnetic field on the y-axis
* @see sensor_magnetic_set_cb()
* @see sensor_magnetic_unset_cb()
*/
-typedef void (*sensor_magnetic_event_cb)(
+typedef void (*sensor_magnetic_event_cb)( unsigned long long timestamp,
sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data);
/**
* @}
*
* @remark All values are angles in degrees.
*
+ * @param[in] timestamp The time in nanosecond at which the event ahppened
* @param[in] accuracy The accuracy of @a x, @a y, and @a z values
* @param[in] azimuth The angle between the magnetic north direction and the y-axis, around the z-axis [0 ~ 359]. \n
* 0 = North, 90 = East, 180 = South, 270 = West
* @see sensor_orientation_set_cb()
* @see sensor_orientation_unset_cb()
*/
-typedef void (*sensor_orientation_event_cb)(
+typedef void (*sensor_orientation_event_cb)( unsigned long long timestamp,
sensor_data_accuracy_e accuracy, float azimuth, float pitch, float roll, void *user_data);
/**
* @}
/**
* @brief Called when a proximity event occurs.
*
+ * @param[in] timestamp The time in nanosecond at which the event ahppened
* @param[in] distance The distance measured in centemeters
- * @param[in] user_data The user data passed from the callback registration function
+ * @param[in] user_data The user data passed from the callback registration function
* @pre sensor_start() will invoke this callback if you register this callback using sensor_proximity_set_cb().
* @see sensor_proximity_set_cb()
* @see sensor_proximity_unset_cb()
*/
-typedef void (*sensor_proximity_event_cb)(sensor_data_accuracy_e accuracy, float distance, void *user_data);
+typedef void (*sensor_proximity_event_cb)( unsigned long long timestamp, float distance, void *user_data);
/**
* @}
*/
* @brief Called when a snap motion event occurs.
* @image html phone_snap.png
*
+ * @param[in] timestamp The time in nanosecond at which the event ahppened
* @param[in] snap The type of motion snap
* @param[in] user_data The user data passed from the callback registration function
* @pre sensor_start() will invoke this callback if you register this callback using sensor_motion_snap_set_cb().
* @see sensor_motion_snap_set_cb()
* @see sensor_motion_snap_unset_cb()
*/
-typedef void (*sensor_motion_snap_event_cb) (sensor_motion_snap_e snap, void *user_data);
+typedef void (*sensor_motion_snap_event_cb) ( unsigned long long timestamp, sensor_motion_snap_e snap, void *user_data);
/**
* @}
*/
/**
* @brief Called when a shake motion event occurs.
*
+ * @param[in] timestamp The time in nanosecond at which the event ahppened
* @param[in] shake The type of motion shake
* @param[in] user_data The user data passed from the callback registration function
* @pre sensor_start() will invoke this callback if you register this callback using sensor_motion_shake_set_cb().
* @see sensor_motion_shake_set_cb()
* @see sensor_motion_shake_unset_cb()
*/
-typedef void (*sensor_motion_shake_event_cb) (sensor_motion_shake_e shake, void *user_data);
+typedef void (*sensor_motion_shake_event_cb) ( unsigned long long timestamp, sensor_motion_shake_e shake, void *user_data);
/**
* @}
*/
/**
* @brief Called when a double tap motion event occurs.
*
+ * @param[in] timestamp The time in nanosecond at which the event ahppened
* @param[in] user_data The user data passed from the callback registration function
* @pre sensor_start() will invoke this callback if you register this callback using sensor_motion_doubletap_set_cb().
* @see sensor_motion_doubletap_set_cb()
* @see sensor_motion_doubletap_unset_cb()
*/
-typedef void (*sensor_motion_doubletap_event_cb) (void *user_data);
+typedef void (*sensor_motion_doubletap_event_cb) ( unsigned long long timestamp, void *user_data);
/**
* @}
*/
* @brief Called when a panning tap motion event occurs.
* @image html phone_panning.png
*
+ * @param[in] timestamp The time in nanosecond at which the event ahppened
* @param[in] x 1/10 angle on x-axis
* @param[in] y 1/10 angle on y-axis
* @param[in] user_data The user data passed from the callback registration function
* @see sensor_motion_panning_set_cb()
* @see sensor_motion_panning_unset_cb()
*/
-typedef void (*sensor_motion_panning_event_cb) (int x, int y, void *user_data);
+typedef void (*sensor_motion_panning_event_cb) ( unsigned long long timestamp, int x, int y, void *user_data);
/**
* @}
*/
* This motion event will fire only when the device is flipped from face to back.
* It will not occur when the device is flipped from back to face.
*
+ * @param[in] timestamp The time in nanosecond at which the event ahppened
* @param[in] user_data The user data passed from the callback registration function
* @pre sensor_start() will invoke this callback if you register this callback using sensor_motion_facedown_set_cb().
* @see sensor_motion_facedown_set_cb()
* @see sensor_motion_facedown_unset_cb()
*/
-typedef void (*sensor_motion_facedown_event_cb) (void *user_data);
+typedef void (*sensor_motion_facedown_event_cb) ( unsigned long long timestamp, void *user_data);
/**
* @}
*/
* @remark When the given @a type is one of the motion sensors, this function returns #SENSOR_ERROR_INVALID_PARAMETER.
*
* @param[in] type The sensor type to check
+ * @param[out] vendor The vendor name of the sensor
+ * @param[out] model The model name of the sensor
* @param[out] max The maximum range of the sensor in the sensor's unit
* @param[out] min The minimum range of the sensor in the sensor's unit
* @param[out] resolution The resolution of the sensor
*
* @pre #sensor_is_supported()
*/
-int sensor_get_spec(sensor_type_e type, float *max, float *min, float *resolution);
+int sensor_get_spec(sensor_type_e type, char** vendor, char** model, float *max, float *min, float *resolution);
/**
*/
int sensor_stop(sensor_h sensor, sensor_type_e type);
+/**
+ * @brief Retrieve minimum and maximum interval time that can use to measuring specific sensor.
+ *
+ * @param[in] type The sensor type
+ * @param[out] min The minimum interval time
+ * @param[out] max The maximum interval time
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ */
+int sensor_get_delay_boundary(sensor_type_e type, int *min, int *max);
+
+/**
+ * @brief Retrieve whether supported or not supported the awaken from specific sensor.
+ *
+ * @param[in] type The sensor type
+ * @param[out] supported @c true if this sensor type is supported, otherwise @c false
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ */
+int sensor_awake_is_supported(sensor_type_e type, bool *supported);
+
+/**
+ * @brief Set the awaken behavior from specific sensor.
+ *
+ * @param[in] type The sensor type
+ * @param[in] enable @c true if set enable the awaken behavior from the sensor, or @c false
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ */
+int sensor_awake_set(sensor_type_e type, bool enable);
+
+/**
+ * @brief Set the awaken behavior from specific sensor.
+ *
+ * @param[in] type The sensor type
+ * @param[out] enable @c true if set enable the awaken behavior from the sensor, or @c false
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ */
+int sensor_awake_is_enabled(sensor_type_e type, bool *enable);
+
+/**
+ * @brief Called when a device awaken.
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ *
+ * @see sensor_awake_is_supported()
+ * @see sensor_awake_set()
+ * @see sensor_awake_set_cb()
+ * @see sensor_awake_unset_cb()
+ */
+typedef void (*sensor_awake_cb) (void *user_data);
+
+/**
+ * @brief Set the callback that called when device awaken.
+ *
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ */
+int sensor_awake_set_cb(sensor_awake_cb callback, void* user_data);
+
+/**
+ * @brief Unset the callback that called when device awaken.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ */
+int sensor_awake_unset_cb();
/**
* @}
*/
int sensor_accelerometer_unset_cb(sensor_h sensor);
+/**
+ * @brief change the interval at accelerometer measurements.
+ *
+ * @param[in] sensor The sensor handle
+ * @param[in] interval_ms in milliseconds.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see sensor_accelerometer_set_cb()
+ */
+int sensor_accelerometer_set_interval(sensor_h sensor, int interval_ms);
+
/**
* @brief Gets sensor data from the accelerometer sensor.
int sensor_gyroscope_unset_cb(sensor_h sensor);
/**
+ * @brief change the interval at gyroscope measurements.
+ *
+ * @param[in] sensor The sensor handle
+ * @param[in] interval_ms in milliseconds.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see sensor_gyroscope_set_cb()
+ */
+int sensor_gyroscope_set_interval(sensor_h sensor, int interval_ms);
+
+/**
* @brief
* Gets sensor data from the gyroscope sensor.
*
int sensor_light_unset_cb(sensor_h sensor);
/**
+ * @brief change the interval at light sensor measurements.
+ *
+ * @param[in] sensor The sensor handle
+ * @param[in] interval_ms in milliseconds.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see sensor_light_set_cb()
+ */
+int sensor_light_set_interval(sensor_h sensor, int interval_ms);
+
+/**
* @brief Gets sensor data from the light sensor.
*
* @remark
* with #sensor_get_spec().
*
* @param[in] sensor The sensor handle
- * @param[out] accuracy The accuracy of this data
* @param[out] lux The ambient light level in SI lux units \n
* @a lux is between min and max values obtained with #sensor_get_spec().\n
*
* @see #sensor_data_accuracy_e
* @see sensor_start()
*/
-int sensor_light_read_data(sensor_h sensor, sensor_data_accuracy_e *accuracy, float *lux);
+int sensor_light_read_data(sensor_h sensor, float *lux);
/**
* @}
int sensor_magnetic_unset_cb(sensor_h sensor);
/**
+ * @brief change the interval at magnetic sensor measurements.
+ *
+ * @param[in] sensor The sensor handle
+ * @param[in] interval_ms in milliseconds.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see sensor_magnetic_set_cb()
+ */
+int sensor_magnetic_set_interval(sensor_h sensor, int interval_ms);
+
+/**
* @brief Gets sensor data from the magnetic sensor.
*
* @remark All values are in micro-Teslas (uT) and measure the ambient magnetic field in the X, Y and Z axis.
int sensor_orientation_unset_calibration_cb(sensor_h sensor);
/**
+ * @brief change the interval at orientation measurements.
+ *
+ * @param[in] sensor The sensor handle
+ * @param[in] interval_ms in milliseconds.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see sensor_orientation_set_cb()
+ */
+int sensor_orientation_set_interval(sensor_h sensor, int interval_ms);
+
+/**
* @brief Gets sensor data from the orientation sensor.
*
* @remark
int sensor_proximity_unset_cb(sensor_h sensor);
/**
+ * @brief change the interval at proximity measurements.
+ *
+ * @param[in] sensor The sensor handle
+ * @param[in] interval_ms in milliseconds.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see sensor_proximity_set_cb()
+ */
+int sensor_proximity_set_interval(sensor_h sensor, int interval_ms);
+
+/**
* @brief Gets sensor data from the Proximity sensor.
*
* @remark
* All values are angles in degrees.
*
* @param[in] sensor The sensor handle
- * @param[out] accuracy The accuracy of this data
* @param[out] distance The distance measured in centemeters
*
* @return 0 on success, otherwise a negative error value
* @pre In order to read sensor data, an application should call sensor_start().
* @see sensor_start()
*/
-int sensor_proximity_read_data(sensor_h sensor, sensor_data_accuracy_e *accuracy, float *distance);
+int sensor_proximity_read_data(sensor_h sensor, float *distance);
/**
* @}
*
*
* @see sensor_motion_facedown_set_cb()
*/
+
int sensor_motion_facedown_unset_cb(sensor_h sensor);
/**
* @}
*
+ * @addtogroup CAPI_SYSTEM_SENSOR_ROTATION_VECTOR_MODULE
+ * @{
+ */
+
+/**
+ * @brief Called when an rotation vector event occurs.
+ * @details
+ * The values of rotation vector represents orientation of the device as a combination of an angle and an axis.
+ * Each value of the rotation vector is not have unit. the x,y,z axis is same unit as accelerometer.
+ *
+ * @param[in] accuracy The accuracy of @a x, @a y, and @a z values
+ * @param[in] x x*sin(θ/2)
+ * @param[in] y y*sin(θ/2)
+ * @param[in] z z*sin(θ/2)
+ * @param[in] w cos(θ/2)
+ * @param[in] user_data The user data passed from the callback registration function
+ *
+ * @pre sensor_start() will invoke this callback if you register this callback using sensor_rotation_vector_set_cb().
+ *
+ * @see sensor_rotation_vector_set_cb()
+ * @see sensor_rotation_vector_unset_cb()
+ */
+typedef void (*sensor_rotation_vector_event_cb)(
+ sensor_data_accuracy_e accuracy, float x, float y, float z, float w, void *user_data);
+
+/**
+ * @brief Registers a callback function to be invoked when an rotation vector event occurs.
+ *
+ * @param[in] sensor The sensor handle
+ * @param[in] interval_ms The interval sensor events are delivered at (in milliseconds) \n
+ * If @a rate is zero, it uses default value(100ms)
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @post sensor_accelerometer_event_cb() will be invoked.
+ *
+ * @see sensor_accelerometer_event_cb()
+ * @see sensor_accelerometer_unset_cb()
+ */
+int sensor_rotation_vector_set_cb(sensor_h sensor, int interval_ms, sensor_rotation_vector_event_cb callback, void* user_data);
+
+/**
+ * @brief Unregister the rotation vector callback function.
+ *
+ * @param[in] sensor The sensor handle
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see sensor_rotation_vector_set_cb()
+ */
+int sensor_rotation_vector_unset_cb(sensor_h sensor);
+
+/**
+ * @brief Gets sensor data from the rotation vector sensor.
+ *
+ * @details
+ * The rotation vector sensor retrieves quaternion elements <cos(θ/2), x*sin(θ/2), y*sin(θ/2), z*sin(θ/2)>. \n
+ * Last three elements of the quaternion represents rotation vector. \n
+ * Each axis value of rotation vector is composed of the angle from magnitude equal to sin(θ/2) and the axis. \n
+ * The value of rotation vector in each axis don't have unit. the axis x,y and z have same unit as the acceleration sensor.
+ *
+ *
+ *
+ * @param[in] sensor The sensor handle
+ * @param[out] accuracy The accuracy of this data
+ * @param[in] x x*sin(θ/2)
+ * @param[in] y y*sin(θ/2)
+ * @param[in] z z*sin(θ/2)
+ * @param[in] w cos(θ/2)
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ *
+ * @pre In order to read sensor data, an application should call sensor_start().
+ */
+int sensor_rotation_vector_read_data(sensor_h sensor, sensor_data_accuracy_e* accuracy, float* x, float* y, float* z, float* w);
+/**
+ * @}
+ */
+
+
+/**
+ * @addtogroup CAPI_SYSTEM_SENSOR_GRAVITY_MODULE
+ * @{
+ */
+
+/**
+ * @brief Called when an gravity event occurs.
+ *
+ * @param[in] accuracy The accuracy of @a x, @a y, and @a z values
+ * @param[in] x m/s^2
+ * @param[in] y m/s^2
+ * @param[in] z m/s^2
+ * @param[in] user_data The user data passed from the callback registration function
+ *
+ * @pre sensor_start() will invoke this callback if you register this callback using sensor_rotation_vector_set_cb().
+ *
+ * @see sensor_rotation_vector_set_cb()
+ * @see sensor_rotation_vector_unset_cb()
+ */
+typedef void (*sensor_gravity_event_cb)(
+ sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data);
+
+/**
+ * @brief Registers a callback function to be invoked when an gravity event occurs.
+ *
+ * @param[in] sensor The sensor handle
+ * @param[in] interval_ms The interval sensor events are delivered at (in milliseconds) \n
+ * If @a rate is zero, it uses default value(100ms)
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @post sensor_accelerometer_event_cb() will be invoked.
+ *
+ * @see sensor_accelerometer_event_cb()
+ * @see sensor_accelerometer_unset_cb()
+ */
+int sensor_gravity_set_cb(sensor_h sensor, int interval_ms, sensor_gravity_event_cb callback, void* user_data);
+
+/**
+ * @brief Unregister the gravity callback function.
+ *
+ * @param[in] sensor The sensor handle
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see sensor_rotation_vector_set_cb()
+ */
+int sensor_gravity_unset_cb(sensor_h sensor);
+
+/**
+ * @brief change the interval at gravity measurements.
+ *
+ * @param[in] sensor The sensor handle
+ * @param[in] interval_ms in milliseconds.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see sensor_gravity_set_cb()
+ */
+int sensor_gravity_set_interval(sensor_h sensor, int interval_ms);
+
+/**
+ * @brief Gets sensor data from the gravity sensor.
+ *
+ * @param[in] sensor The sensor handle
+ * @param[out] accuracy The accuracy of this data
+ * @param[in] x m/s^2
+ * @param[in] y m/s^2
+ * @param[in] z m/s^2
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_IO_ERROR I/O error
+ *
+ * @pre In order to read sensor data, an application should call sensor_start().
+ */
+int sensor_gravity_read_data(sensor_h sensor, sensor_data_accuracy_e* accuracy, float* x, float* y, float* z);
+
+
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup CAPI_SYSTEM_SENSOR_UTILITY_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumerations of Axis used in #sensor_util_remap_coordinate_system
+ *
+ * @see #sensor_util_remap_coordinate_system
+ */
+typedef enum
+{
+ sensor_util_axis_minus_x,
+ sensor_util_axis_minus_y,
+ sensor_util_axis_minus_z,
+ sensor_util_axis_x,
+ sensor_util_axis_y,
+ sensor_util_axis_z,
+} sensor_util_axis_e;
+/**
+ * @}
+ */
+
+/**
+ * @brief
+ * Getting Inclination matrix "I" and Rotation matrix "R" transforming a vector from the device coordinate to the world's coordinate.
+ *
+ * @details
+ * [0 0 g] = R * gravity (g = magnitude of gravity) \n
+ * [0 m 0] = I * R * geomagnetic (m = magnitude of geomagnetic field) \n
+ * 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 toward East, the Y axis points to the North Pole and the device is facing the sky. \n
+ * 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
+ *
+ * @remark
+ * Parameter Gx, Gy, Gz can be got from the values returned by a #sensor_gravity_event_cb or #sensor_gravity_read_data. \n
+ * Parameter Mx, My, Mz can be got from the values returned by a #sensor_magnetic_event_cb or #sensor_magnetic_read_data.
+ * Output parameter R and I is always returned 3x3 matrix array of 9 floats like this form:
+ * <pre>
+ * { R[0], R[1], R[2],
+ * R[3], R[4], R[5],
+ * R[6], R[7], R[6] }
+ * </pre>
+ *
+ *
+ * @param[in] Gx X-axis gravity vector in the device's coordinate.
+ * @param[in] Gy Y-axis gravity vector in the device's coordinate.
+ * @param[in] Gz Z-axis gravity vector in the device's coordinate.
+ * @param[in] Mx X-axis geomagnetic vector in the device's coordinate.
+ * @param[in] My Y-axis geomagnetic vector in the device's coordinate.
+ * @param[in] Mz Z-axis geomagnetic vector in the device's coordinate.
+ * @param[out] R Array of 9 floats that represents the rotation matrix "R". It can be null.
+ * @param[out] I Array of 9 floats that represents the inclination matrix "I". It can be null.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int sensor_util_get_rotation_matrix(float Gx, float Gy, float Gz,
+ float Mx, float My, float Mz,
+ float R[], float I[]);
+
+/**
+ * @brief
+ * Convert a rotation vector to a rotation matrix.
+ *
+ * @details
+ * rotation vectors (Vx, Vy, Vz) can be got from #sensor_rotation_vector_event_cb or #sensor_rotation_vector_read_data.
+ * It returns a 9 elements rotation matrix in the array R. R must have langth 9.
+ *
+ * @param[in] Vx X-axis rotation vector.
+ * @param[in] Vy Y-axis rotation vector.
+ * @param[in] Vz Z-axis rotation vector.
+ * @param[out] R A 9 elements ration matrix in the array R that must have length 9.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see sensor_util_rotation_matrix3
+ * @see sensor_util_rotation_matrix4
+ */
+int sensor_util_get_rotation_matrix_from_vector(float Vx, float Vy, float Vz, float R[]);
+
+/**
+ * @brief
+ * Rotates the supplied rotation matrix so it is expressed in a different coordinate system.
+ *
+ * @details
+ * This is typically used when an application needs to compute the three orientation angles of the device in a different coordinate system.
+ *
+ * @remark
+ * inR and outR can be the same array, but it is not recommended for performance reason.
+ * Return error when X and Y defines the same axis.
+ *
+ * @param[in] inR the rotation matrix (3x3) to be transformed. Usually it is the matrix returned by get #sensor_util_rotation_matrix3 or #sensor_util_rotation_matrix4.
+ * @param[in] x defines on which world axis and direction the X axis of the device is mapped.
+ * @param[in] y defines on which world axis and direction the Y axis of the device is mapped.
+ * @param[out] outR the transformed rotation matrix (3x3).
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see sensor_util_rotation_matrix3
+ * @see sensor_util_rotation_matrix4
+ * @see sensor_util_rotation_matrix_from_vector
+ * @see sensor_util_rotation_matrix_from_quaternion
+ */
+int sensor_util_remap_coordinate_system(float inR[], sensor_util_axis_e x, sensor_util_axis_e y, float outR[]);
+
+/**
+ * @brief
+ * Computes the geomagnetic inclination angle in radians from the inclination matrix I returned by #sensor_util_get_rotation_matrix()
+ *
+ * @param[in] I inclination matrix from #sensor_util_get_rotation_matrix()
+ * @param[out] inclination The geomagnetic inclination angle in radians.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see sensor_util_get_rotation_matrix()
+ */
+int sensor_util_get_inclination(float I[], float* inclination);
+
+/**
+ * @brief
+ * Compute the device's orientation based on the rotation matrix
+ *
+ * @details
+ * When it returns, they array values is filled with the result:
+ * - values[0]: azimuth, rotation around the Z axis.
+ * - values[1]: pitch, rotation around the X axis.
+ * - values[2]: roll, rotation around the Y axis.
+ *
+ * @remark
+ * Parameter R must be array of 9 floats from #sensor_util_get_rotation_matrix() \n
+ * Returned values are always array of 3 floats.
+ *
+ *
+ * @param[in] R A 9 elements ration matrix in the array.
+ * @param[values] values An array of 3 floats to hold the result.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see sensor_util_get_rotation_matrix()
+ *
+ */
+int sensor_util_get_orientation(float R[], float values[]);
+
+/**
+ * @brief
+ * Helper function to compute the angle change between two rotation matrices.
+ *
+ * @details
+ * Given a current rotation matrix (R) and a previous rotation matrix (prevR) computes
+ * the rotation around the x,y, and z axes which transforms prevR to R.
+ * outputs a 3 element vector containing the x,y, and z angle change at indexes 0, 1, and 2 respectively. \n
+ *
+ * @remark
+ * Each input matrix is 3x3 matrix like this form:
+ * <pre>
+ * { R[0], R[1], R[2],
+ * R[3], R[4], R[5],
+ * R[6], R[7], R[6] }
+ * </pre>
+ *
+ * @param[in] R current rotation matrix
+ * @param[in] prevR previous rotation matrix
+ * @param[out] angleChange an array of floats in which the angle change is stored
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int sensor_util_get_angle_change(float R[], float prevR[], float angleChange[]);
+
+/**
+ * @brief
+ * Getting the declination of the horizontal component of the magnetic field from true north, in degrees
+ *
+ * @param[in] latitude Latitude in geodetic coordinates
+ * @param[in] longitude Longitude in geodetic coordinates
+ * @param[in] altitude Altitude in geodetic coordinates
+ * @param[out] declination The declination of the horizontal component of the magnetic field in degrees.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int sensor_util_get_declination(float latitude, float longitude, float altitude, float* declination);
+
+/**
+ * @brief Determines whether or not to be near from proximity sensor's distance value.
+ *
+ * @remark
+ * This function can be used to determine the proximity to device from other object like human face.
+ *
+ * @param[in] distance Distance in centimeter from proximity sensor.
+ * @param[out] is_near proximity to device from other object.
+ */
+int sensor_util_is_near(float distance, bool *is_near);
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ *
* @}
*/
#include <stdlib.h>
#include <string.h>
+#include <sys/time.h>
#include <sensor.h>
#include <sensor_accel.h>
#define RETURN_IF_ERROR(val) \
RETURN_VAL_IF(val < 0, val)
+#define MICROSECONDS(tv) ((tv.tv_sec * 1000000ll) + tv.tv_usec)
+
sensor_data_accuracy_e _accu_table[] = {
SENSOR_ACCURACY_UNDEFINED,
SENSOR_ACCURACY_BAD,
sensor_panning_data_t *panning_data = NULL;
int motion = 0;
int nid = 0;
+
+ struct timeval sv;
+ unsigned long long motion_time_stamp = 0;
// bool proximity = 0;
sensor_h sensor = (sensor_h)udata;
switch(event_type)
{
case MOTION_ENGINE_EVENT_SNAP:
- ((sensor_motion_snap_event_cb)sensor->cb_func[nid])(motion, sensor->cb_user_data[nid]);
+ gettimeofday(&sv, NULL);
+ motion_time_stamp = MICROSECONDS(sv);
+ ((sensor_motion_snap_event_cb)sensor->cb_func[nid])(motion_time_stamp, motion, sensor->cb_user_data[nid]);
break;
case MOTION_ENGINE_EVENT_SHAKE:
- ((sensor_motion_shake_event_cb)sensor->cb_func[nid])(motion, sensor->cb_user_data[nid]);
+ gettimeofday(&sv, NULL);
+ motion_time_stamp = MICROSECONDS(sv);
+ ((sensor_motion_shake_event_cb)sensor->cb_func[nid])(motion_time_stamp,motion, sensor->cb_user_data[nid]);
break;
case MOTION_ENGINE_EVENT_DOUBLETAP:
- ((sensor_motion_doubletap_event_cb)sensor->cb_func[nid])(sensor->cb_user_data[nid]);
+ gettimeofday(&sv, NULL);
+ motion_time_stamp = MICROSECONDS(sv);
+ ((sensor_motion_doubletap_event_cb)sensor->cb_func[nid])(motion_time_stamp,sensor->cb_user_data[nid]);
break;
case MOTION_ENGINE_EVENT_TOP_TO_BOTTOM:
- ((sensor_motion_facedown_event_cb)sensor->cb_func[nid])(sensor->cb_user_data[nid]);
+ gettimeofday(&sv, NULL);
+ motion_time_stamp = MICROSECONDS(sv);
+ ((sensor_motion_facedown_event_cb)sensor->cb_func[nid])(motion_time_stamp,sensor->cb_user_data[nid]);
break;
case MOTION_ENGINE_EVENT_PANNING:
- ((sensor_motion_panning_event_cb)sensor->cb_func[nid])(panning_data->x, panning_data->y,
- sensor->cb_user_data[nid]);
+ gettimeofday(&sv, NULL);
+ motion_time_stamp = MICROSECONDS(sv);
+ ((sensor_motion_panning_event_cb)sensor->cb_func[nid])(motion_time_stamp,panning_data->x, panning_data->y, sensor->cb_user_data[nid]);
break;
case ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME :
for(i=0; i<data_num; i++){
((sensor_accelerometer_event_cb)sensor->cb_func[nid])
- (_ACCU(data[i].data_accuracy),
+ (data[i].time_stamp, _ACCU(data[i].data_accuracy),
data[i].values[0], data[i].values[1], data[i].values[2],
sensor->cb_user_data[nid]);
}
case GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME :
for(i=0; i<data_num; i++){
((sensor_magnetic_event_cb)sensor->cb_func[nid])
- (_ACCU(data[i].data_accuracy),
+ (data[i].time_stamp,_ACCU(data[i].data_accuracy),
data[i].values[0], data[i].values[1], data[i].values[2],
sensor->cb_user_data[nid]);
}
case GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME :
for(i=0; i<data_num; i++){
((sensor_orientation_event_cb)sensor->cb_func[nid])
- (_ACCU(data[i].data_accuracy),
+ (data[i].time_stamp,_ACCU(data[i].data_accuracy),
data[i].values[0], data[i].values[1], data[i].values[2],
sensor->cb_user_data[nid]);
}
case GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME :
for(i=0; i<data_num; i++){
((sensor_gyroscope_event_cb)sensor->cb_func[nid])
- (_ACCU(data[i].data_accuracy),
+ (data[i].time_stamp,_ACCU(data[i].data_accuracy),
data[i].values[0], data[i].values[1], data[i].values[2],
sensor->cb_user_data[nid]);
}
case LIGHT_EVENT_LUX_DATA_REPORT_ON_TIME :
for(i=0; i<data_num; i++){
((sensor_light_event_cb)sensor->cb_func[nid])
- (_ACCU(data[i].data_accuracy),
+ (data[i].time_stamp,
data[i].values[0],
sensor->cb_user_data[nid]);
}
case PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME :
for(i=0; i<data_num; i++){
((sensor_proximity_event_cb)sensor->cb_func[nid])
- (_ACCU(data[i].data_accuracy),
+ (data[i].time_stamp,
data[i].values[0],
sensor->cb_user_data[nid]);
}
return SENSOR_ERROR_NONE;
}
-int sensor_get_spec(sensor_type_e type, float* max, float* min, float* resolution)
+int sensor_get_spec(sensor_type_e type, char** vendor, char** model, float* max, float* min, float* resolution)
{
- sensor_data_properties_t properties;
-
+ sensor_data_properties_t data_properties;
+ sensor_properties_t properties;
+
DEBUG_PRINT("sensor_get_spec");
RETURN_IF_MOTION_TYPE(type);
RETURN_IF_NOT_TYPE(type);
- if(sf_get_data_properties(_DTYPE[type], &properties) < 0)
+ if(sf_get_data_properties(_DTYPE[type], &data_properties) < 0)
RETURN_ERROR(SENSOR_ERROR_NOT_SUPPORTED);
- *max = properties.sensor_max_range;
- *min = properties.sensor_min_range;
- *resolution = properties.sensor_resolution;
+ if(sf_get_properties(_TYPE[type], &properties) < 0)
+ RETURN_ERROR(SENSOR_ERROR_NOT_SUPPORTED);
+
+ if(vendor != NULL)
+ *vendor = properties.sensor_vendor;
+ if(model != NULL)
+ *model = properties.sensor_name;
+
+ *max = data_properties.sensor_max_range;
+ *min = data_properties.sensor_min_range;
+ *resolution = data_properties.sensor_resolution;
DEBUG_PRINTF("success get %s's format max=%f, min=%f, res=%f\n", TYPE_NAME(type), *max, *min, *resolution);
return SENSOR_ERROR_NONE;
}
-int sensor_light_read_data (sensor_h handle, sensor_data_accuracy_e* accuracy, float* lux)
+int sensor_light_read_data (sensor_h handle, float* lux)
{
float values[1] = {0};
- int err = _sensor_read_data(handle, SENSOR_LIGHT, accuracy, values, 1);
+ int err = _sensor_read_data(handle, SENSOR_LIGHT, NULL, values, 1);
if(err < 0) return err;
if(lux == NULL)
return SENSOR_ERROR_NONE;
}
-int sensor_proximity_read_data (sensor_h handle, sensor_data_accuracy_e* accuracy, float* distance)
+int sensor_proximity_read_data (sensor_h handle, float* distance)
{
float values[1] = {0};
- int err = _sensor_read_data(handle, SENSOR_PROXIMITY, accuracy, values, 1);
+ int err = _sensor_read_data(handle, SENSOR_PROXIMITY, NULL, values, 1);
if(err < 0) return err;
if(distance == NULL)
--- /dev/null
+/*
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * This software is the confidential and proprietary information of SAMSUNG
+ * ELECTRONICS ("Confidential Information"). You agree and acknowledge that
+ * this software is owned by Samsung and you shall not disclose such
+ * Confidential Information and shall use it only in accordance with the terms
+ * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG
+ * make no representations or warranties about the suitability of the software,
+ * either express or implied, including but not limited to the implied
+ * warranties of merchantability, fitness for a particular purpose, or
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by
+ * licensee arising out of or related to this software.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <sensors.h>
+
+static GMainLoop *mainloop;
+
+static char* TYPE_NAME[] = {
+ "ACCELEROMETER",
+ "MAGNETIC",
+ "ORIENTATION",
+ "GYROSCOPE",
+ "LIGHT",
+ "PROXIMITY",
+ "MOTION_SNAP",
+ "MOTION_SHAKE",
+ "MOTION_DOUBLETAP",
+ "MOTION_PANNING",
+ "MOTION_FACEDOWN"
+};
+
+static char* SNAP[] = {
+ "NONE",
+ "LEFT",
+ "RIGHT"
+};
+
+static char* SHAKE[] = {
+ "NONE",
+ "DETECTION",
+ "CONTINUING",
+ "FINISH",
+ "BREAK"
+};
+
+static void test_calibration_cb(void *user_data)
+{
+ char* xx = (char*)user_data;
+ printf("%s sensor is calibration needed!!!!!!!!!!!!!!!!!!\n", xx);
+}
+
+static void test_accelerometer_cb(sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
+{
+ printf("ACCELEROMETER sensor acc=%d x=%f y=%f z=%f\n", accuracy, x, y, z);
+}
+
+static void test_magnetic_cb(sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
+{
+ printf("MAGNETIC sensor acc=%d x=%f y=%f z=%f\n", accuracy, x, y, z);
+}
+
+static void test_orientation_cb(sensor_data_accuracy_e accuracy, float azimuth, float pitch, float roll, void *user_data)
+{
+ printf("ORIENTATION sensor acc=%d azimuth=%f pitch=%f roll=%f\n", accuracy, azimuth, pitch, roll);
+}
+
+static void test_gyroscope_cb(sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
+{
+ printf("GYROSCOPE sensor acc=%d x=%f y=%f z=%f\n", accuracy, x, y, z);
+}
+
+static void test_light_cb(sensor_data_accuracy_e accuracy, float lux, void *user_data)
+{
+ printf("LIGHT sensor acc=%d lux=%f\n", accuracy, lux);
+}
+
+static void test_proximity_cb(sensor_data_accuracy_e accuracy, float distance, void *user_data)
+{
+ printf("PROXIMITY sensor distance = %fcm\n", distance);
+}
+
+static void test_motion_snap_cb (sensor_motion_snap_e snap, void *user_data)
+{
+ printf("MOTION_SNAP [%s]\n", SNAP[snap]);
+}
+
+static void test_motion_shake_cb (sensor_motion_shake_e shake, void *user_data)
+{
+ printf("MOTION_SHAKE [%s]\n", SHAKE[shake]);
+}
+
+static void test_motion_doubletap_cb (void *user_data)
+{
+ printf("MOTION_DOUBLETAP \n");
+}
+
+static void test_motion_panning_cb (int x, int y, void *user_data)
+{
+ printf("MOTION_PANNING x=[%5d] y=[%5d]\n", x, y);
+}
+
+static void test_motion_facedown_cb (void *user_data)
+{
+ printf("MOTION_FACEDOWN \n");
+}
+
+static void sig_quit(int signo)
+{
+ if(mainloop)
+ {
+ g_main_loop_quit(mainloop);
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ int i;
+ int type;
+ sensor_h handle;
+ bool is_supported;
+
+ float max = 0, min = 0, res = 0;
+
+ if(argc < 2)
+ {
+ printf("input sensor type\n");
+ for(i=0; i<=SENSOR_MOTION_FACEDOWN; i++){
+ printf("%d : %s\n", i, TYPE_NAME[i]);
+ }
+ return 0;
+ }
+
+ type = atoi(argv[1]);
+ /*
+ if(sensor_is_supported(type, &is_supported) != SENSOR_ERROR_NONE){
+ printf("unknown error\n");
+ return 0;
+ }
+ if(!is_supported){
+ printf("unsupported sensor\n");
+ return 0;
+ }
+ */
+
+ if(type < 0 || type > SENSOR_MOTION_FACEDOWN)
+ printf("unknown sensor!\n");
+ else
+ printf("selected sensor is (%d)%s\n", type, TYPE_NAME[type]);
+
+ signal(SIGINT, sig_quit);
+ signal(SIGTERM, sig_quit);
+ signal(SIGQUIT, sig_quit);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+
+
+ if(type < SENSOR_MOTION_SNAP){
+ if(sensor_get_spec(type, &max, &min, &res) == SENSOR_ERROR_NONE){
+ printf("max=%f, min=%f, res=%f\n", max, min, res);
+ }else{
+ printf("Error!!!!\n");
+ }
+ }
+
+ sensor_create(&handle);
+
+ switch(type){
+ case SENSOR_ACCELEROMETER:
+ sensor_accelerometer_set_cb(handle, 0, test_accelerometer_cb, TYPE_NAME[type]);
+ break;
+ case SENSOR_MAGNETIC:
+ sensor_magnetic_set_cb(handle, 0, test_magnetic_cb, TYPE_NAME[type]);
+ sensor_magnetic_set_calibration_cb(handle, test_calibration_cb, TYPE_NAME[type]);
+ break;
+ case SENSOR_ORIENTATION:
+ sensor_orientation_set_cb(handle, 0, test_orientation_cb, TYPE_NAME[type]);
+ sensor_orientation_set_calibration_cb(handle, test_calibration_cb, TYPE_NAME[type]);
+ break;
+ case SENSOR_GYROSCOPE:
+ sensor_gyroscope_set_cb(handle, 0, test_gyroscope_cb, TYPE_NAME[type]);
+ break;
+ case SENSOR_LIGHT:
+ sensor_light_set_cb(handle, 0, test_light_cb, TYPE_NAME[type]);
+ break;
+ case SENSOR_PROXIMITY:
+ sensor_proximity_set_cb(handle, 0, test_proximity_cb, TYPE_NAME[type]);
+ break;
+ case SENSOR_MOTION_SNAP:
+ sensor_motion_snap_set_cb(handle, test_motion_snap_cb, TYPE_NAME[type]);
+ break;
+ case SENSOR_MOTION_SHAKE:
+ sensor_motion_shake_set_cb(handle, test_motion_shake_cb, TYPE_NAME[type]);
+ break;
+ case SENSOR_MOTION_DOUBLETAP:
+ sensor_motion_doubletap_set_cb(handle, test_motion_doubletap_cb, TYPE_NAME[type]);
+ break;
+ case SENSOR_MOTION_PANNING:
+ sensor_motion_panning_set_cb(handle, test_motion_panning_cb, TYPE_NAME[type]);
+ break;
+ case SENSOR_MOTION_FACEDOWN:
+ sensor_motion_facedown_set_cb(handle, test_motion_facedown_cb, TYPE_NAME[type]);
+ break;
+ default:
+ goto _ending;
+ }
+
+ printf("Success register callback \n");
+
+ if(sensor_start(handle, type) == SENSOR_ERROR_NONE)
+ printf("Success start \n");
+
+ g_main_loop_run(mainloop);
+ g_main_loop_unref(mainloop);
+
+ switch(type){
+ case SENSOR_ACCELEROMETER:
+ sensor_accelerometer_unset_cb(handle);
+ break;
+ case SENSOR_MAGNETIC:
+ sensor_magnetic_unset_calibration_cb(handle);
+ sensor_magnetic_unset_cb(handle);
+ break;
+ case SENSOR_ORIENTATION:
+ sensor_orientation_unset_calibration_cb(handle);
+ sensor_orientation_unset_cb(handle);
+ break;
+ case SENSOR_GYROSCOPE:
+ sensor_gyroscope_unset_cb(handle);
+ break;
+ case SENSOR_LIGHT:
+ sensor_light_unset_cb(handle);
+ break;
+ case SENSOR_PROXIMITY:
+ sensor_proximity_unset_cb(handle);
+ break;
+ case SENSOR_MOTION_SNAP:
+ sensor_motion_snap_unset_cb(handle);
+ break;
+ case SENSOR_MOTION_SHAKE:
+ sensor_motion_shake_unset_cb(handle);
+ break;
+ case SENSOR_MOTION_DOUBLETAP:
+ sensor_motion_doubletap_unset_cb(handle);
+ break;
+ case SENSOR_MOTION_PANNING:
+ sensor_motion_panning_unset_cb(handle);
+ break;
+ case SENSOR_MOTION_FACEDOWN:
+ sensor_motion_facedown_unset_cb(handle);
+ break;
+
+ default:
+ goto _ending;
+ }
+
+ if(sensor_stop(handle, type) == SENSOR_ERROR_NONE)
+ printf("Success stop \n");
+
+_ending:
+ sensor_destroy(handle);
+ return 0;
+}