From: Pius Lee Date: Fri, 10 Feb 2012 10:38:06 +0000 (+0900) Subject: light and proximity sensor modified. sensor will be measured lux and centimeter X-Git-Tag: 2.0_alpha~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=86bb504a5c08767178dc71a8b1d4380cb3915e9a;p=platform%2Fcore%2Fapi%2Fsensor.git light and proximity sensor modified. sensor will be measured lux and centimeter --- diff --git a/debian/changelog b/debian/changelog index 2a85778..3830b5c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,19 @@ +capi-system-sensor (0.1.0-8) unstable; urgency=low + + * fix sensor_get_spec for light and proximity (lux, centimeter) + * Git: api/sensor + * Tag: capi-system-sensor_0.1.0-8 + + -- pius lee Thu, 09 Feb 2012 16:01:52 +0900 + +capi-system-sensor (0.1.0-7) unstable; urgency=low + + * light and proximity sensor modified. sensor will be measured lux and centimeter. + * Git: api/sensor + * Tag: capi-system-sensor_0.1.0-7 + + -- pius lee Thu, 02 Feb 2012 18:50:31 +0900 + capi-system-sensor (0.1.0-6) unstable; urgency=low * fix bug for calibration callback's invalidate user data diff --git a/include/sensor_private.h b/include/sensor_private.h index 7147ae8..b3a6b18 100755 --- a/include/sensor_private.h +++ b/include/sensor_private.h @@ -17,8 +17,8 @@ -#ifndef __TIZEN_SYSTEM_SENSOR_PRIVATE_H__ -#define __TIZEN_SYSTEM_SENSOR_PRIVATE_H__ +#ifndef __SENSOR_PRIVATE_H__ +#define __SENSOR_PRIVATE_H__ #ifdef __cplusplus extern "C" @@ -103,4 +103,4 @@ struct sensor_handle_s { } #endif -#endif // __TIZEN_SYSTEM_SENSOR_PRIVATE_H__ +#endif // __SENSOR_PRIVATE_H__ diff --git a/include/sensors.h b/include/sensors.h index fe4fa39..5f7af1d 100755 --- a/include/sensors.h +++ b/include/sensors.h @@ -17,8 +17,8 @@ -#ifndef __TIZEN_SYSTEM_SENSOR_H__ -#define __TIZEN_SYSTEM_SENSOR_H__ +#ifndef __SENSOR_H__ +#define __SENSOR_H__ #include #include @@ -191,12 +191,8 @@ typedef void (*sensor_accelerometer_event_cb)( * @brief Called when a gyroscope event occurs. * * @remark - * All values are in radians/second and measure the rate of rotation around the X, Y and Z axis. \n - * The coordinate system is the same as is used for the acceleration sensor. Rotation is positive \n - * in the counter-clockwise direction. That is, an observer looking from some positive location \n - * on the @a x, @a y, or @a z axis at a device positioned on the origin would report positive rotation if \n - * the device appeared to be rotating counter clockwise. Note that this is the standard mathematical \n - * definition of positive rotation and does not agree with the definition of roll given earlier. + * 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] 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 @@ -222,22 +218,19 @@ typedef void (*sensor_gyroscope_event_cb)( * @brief Called when a light event occurs. * * @remark - * All values are neither SI lux units (lx), nor adc.\n - * Values returned by sensor may vary depending on a hardware. In the case of some\n - * HW, level 1 can mean 1 ~ 100 lux, while in some other case, level 1 can mean 1~50 lux.\n - * You should use light level between min and max values obtained \n - * with #sensor_get_spec(). In most cases min is 1 and max is 10. + * 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] level Actual light level - * @param[in] level Ambient light level between min and max values obtained with #sensor_get_spec().\n + * @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 * @pre sensor_start() will invoke this callback if you register this callback using sensor_light_set_cb(). * @see sensor_light_set_cb() * @see sensor_light_unset_cb() */ typedef void (*sensor_light_event_cb)( - sensor_data_accuracy_e accuracy, int level, void *user_data); + sensor_data_accuracy_e accuracy, float lux, void *user_data); /** * @} */ @@ -303,13 +296,13 @@ typedef void (*sensor_orientation_event_cb)( /** * @brief Called when a proximity event occurs. * - * @param[out] is_near @c true if an object is close to the phone, otherwise @c false - * @param[in] user_data The user data passed from the callback registration function + * @param[in] distance The distance measured in centemeters + * @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)(bool is_near, void *user_data); +typedef void (*sensor_proximity_event_cb)(sensor_data_accuracy_e accuracy, float distance, void *user_data); /** * @} */ @@ -720,16 +713,13 @@ int sensor_light_unset_cb(sensor_h sensor); * @brief Gets sensor data from the light sensor. * * @remark - * All values are neither SI lux units (lx), nor adc.\n - * Values returned by sensor may vary depending on a hardware. In some devices, - * HW level 1 can mean 1 ~ 100 lux, while in others, HW level 1 can mean 1 ~ 50 lux.\n - * You should use light level between min and max values obtained \n - * with #sensor_get_spec(). In most cases min is 1 and max is 10. + * You should use lux between min and max values obtained \n + * with #sensor_get_spec(). * * @param[in] sensor The sensor handle * @param[out] accuracy The accuracy of this data - * @param[out] level The ambient light level in SI lux units \n - * @a level is between min and max values obtained with #sensor_get_spec().\n + * @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 * * @return 0 on success, otherwise a negative error value * @retval #SENSOR_ERROR_NONE Successful @@ -739,7 +729,7 @@ int sensor_light_unset_cb(sensor_h sensor); * @see #sensor_data_accuracy_e * @see sensor_start() */ -int sensor_light_read_data(sensor_h sensor, sensor_data_accuracy_e *accuracy, int *level); +int sensor_light_read_data(sensor_h sensor, sensor_data_accuracy_e *accuracy, float *lux); /** * @} @@ -960,6 +950,7 @@ int sensor_orientation_read_data(sensor_h sensor, sensor_data_accuracy_e *accura * @brief Registers a callback function to be invoked when a proximity event occurs. * * @param[in] sensor The sensor handle + * @param[in] interval_ms The interval sensor events are delivered in (in milliseconds) \n * @param[in] callback The callback function to register * @param[in] user_data The user data to be passed to the callback function * @@ -974,7 +965,7 @@ int sensor_orientation_read_data(sensor_h sensor, sensor_data_accuracy_e *accura * @see sensor_proximity_event_cb() * @see sensor_proximity_unset_cb() */ -int sensor_proximity_set_cb(sensor_h sensor, sensor_proximity_event_cb callback, void *user_data); +int sensor_proximity_set_cb(sensor_h sensor, int interval_ms, sensor_proximity_event_cb callback, void *user_data); /** * @brief Unregister the proximity callback function. @@ -991,6 +982,25 @@ int sensor_proximity_set_cb(sensor_h sensor, sensor_proximity_event_cb callback, */ int sensor_proximity_unset_cb(sensor_h sensor); +/** + * @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 + * @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(). + * @see sensor_start() + */ +int sensor_proximity_read_data(sensor_h sensor, sensor_data_accuracy_e *accuracy, float *distance); /** * @} * diff --git a/src/sensor.c b/src/sensor.c index f0f4cd3..c8c433a 100644 --- a/src/sensor.c +++ b/src/sensor.c @@ -124,20 +124,25 @@ sensor_type_t _TYPE[] = { int _DTYPE[] = { ACCELEROMETER_BASE_DATA_SET, - GEOMAGNETIC_RAW_DATA_SET, // really magnetic? - GEOMAGNETIC_BASE_DATA_SET, // really orientation? + GEOMAGNETIC_RAW_DATA_SET, + GEOMAGNETIC_BASE_DATA_SET, GYRO_BASE_DATA_SET, - LIGHT_BASE_DATA_SET, - PROXIMITY_BASE_DATA_SET, + LIGHT_LUX_DATA_SET, + PROXIMITY_DISTANCE_DATA_SET, + MOTION_SENSOR, + MOTION_SENSOR, + MOTION_SENSOR, + MOTION_SENSOR, + MOTION_SENSOR, }; int _EVENT[] = { ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME, - GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME, // really magnetic? - GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME, // really orientation? + GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME, + GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME, GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME, - LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME, // rate = 500ms - PROXIMITY_EVENT_CHANGE_STATE, + LIGHT_EVENT_LUX_DATA_REPORT_ON_TIME, + PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME, MOTION_ENGINE_EVENT_SNAP, MOTION_ENGINE_EVENT_SHAKE, MOTION_ENGINE_EVENT_DOUBLETAP, @@ -200,7 +205,7 @@ static void _sensor_callback (unsigned int event_type, sensor_event_data_t* even sensor_panning_data_t *panning_data = NULL; int motion = 0; int nid = 0; - bool proximity = 0; +// bool proximity = 0; sensor_h sensor = (sensor_h)udata; @@ -233,10 +238,10 @@ static void _sensor_callback (unsigned int event_type, sensor_event_data_t* even case GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME : nid = SENSOR_GYROSCOPE; break; - case LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME : + case LIGHT_EVENT_LUX_DATA_REPORT_ON_TIME : nid = SENSOR_LIGHT; break; - case PROXIMITY_EVENT_CHANGE_STATE : + case PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME : nid = SENSOR_PROXIMITY; break; } @@ -268,13 +273,16 @@ static void _sensor_callback (unsigned int event_type, sensor_event_data_t* even case GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME : case GEOMAGNETIC_EVENT_ATTITUDE_DATA_REPORT_ON_TIME : case GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME : - case LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME : + case LIGHT_EVENT_LUX_DATA_REPORT_ON_TIME : + case PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME : data = (sensor_data_t*)(event->event_data); data_num = (event->event_data_size)/sizeof(sensor_data_t); break; + /* case PROXIMITY_EVENT_CHANGE_STATE : proximity = *(int*)(event->event_data) == PROXIMITY_STATE_FAR ? 0 : 1; break; + */ default: DEBUG_PRINTF("unknown typed sensor happen!! event=%d\n", event_type); return; @@ -331,17 +339,21 @@ static void _sensor_callback (unsigned int event_type, sensor_event_data_t* even sensor->cb_user_data[nid]); } break; - case LIGHT_EVENT_LEVEL_DATA_REPORT_ON_TIME : + case LIGHT_EVENT_LUX_DATA_REPORT_ON_TIME : for(i=0; icb_func[nid]) (_ACCU(data[i].data_accuracy), - (int)data[i].values[0], + data[i].values[0], sensor->cb_user_data[nid]); } break; - case PROXIMITY_EVENT_CHANGE_STATE : + case PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME : + for(i=0; icb_func[nid]) - (proximity, sensor->cb_user_data[nid]); + (_ACCU(data[i].data_accuracy), + data[i].values[0], + sensor->cb_user_data[nid]); + } break; } } @@ -363,7 +375,7 @@ int sensor_is_supported(sensor_type_e type, bool* supported) int sensor_get_spec(sensor_type_e type, float* max, float* min, float* resolution) { - sensor_properties_t property; + sensor_data_properties_t properties; DEBUG_PRINT("sensor_get_spec"); @@ -371,12 +383,12 @@ int sensor_get_spec(sensor_type_e type, float* max, float* min, float* resolutio RETURN_IF_NOT_TYPE(type); - if(sf_get_properties(_TYPE[type], &property) < 0) + if(sf_get_data_properties(_DTYPE[type], &properties) < 0) RETURN_ERROR(SENSOR_ERROR_NOT_SUPPORTED); - *max = property.sensor_max_range; - *min = property.sensor_min_range; - *resolution = property.sensor_resolution; + *max = properties.sensor_max_range; + *min = properties.sensor_min_range; + *resolution = properties.sensor_resolution; DEBUG_PRINTF("success get %s's format max=%f, min=%f, res=%f\n", TYPE_NAME(type), *max, *min, *resolution); @@ -703,9 +715,9 @@ int sensor_light_unset_cb (sensor_h handle) return _sensor_unset_data_cb(handle, SENSOR_LIGHT); } -int sensor_proximity_set_cb (sensor_h handle, sensor_proximity_event_cb callback, void *user_data) +int sensor_proximity_set_cb (sensor_h handle, int interval_ms, sensor_proximity_event_cb callback, void *user_data) { - return _sensor_set_data_cb(handle, SENSOR_PROXIMITY, 0, (void*) callback, user_data); + return _sensor_set_data_cb(handle, SENSOR_PROXIMITY, interval_ms, (void*) callback, user_data); } int sensor_proximity_unset_cb (sensor_h handle) @@ -809,30 +821,30 @@ int sensor_gyroscope_read_data (sensor_h handle, sensor_data_accuracy_e* acc return SENSOR_ERROR_NONE; } -int sensor_light_read_data (sensor_h handle, sensor_data_accuracy_e* accuracy, int* level) +int sensor_light_read_data (sensor_h handle, sensor_data_accuracy_e* accuracy, float* lux) { float values[1] = {0}; int err = _sensor_read_data(handle, SENSOR_LIGHT, accuracy, values, 1); if(err < 0) return err; - if(level == NULL) + if(lux == NULL) RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); - *level = (int)values[0]; + *lux = values[0]; return SENSOR_ERROR_NONE; } -int sensor_proximity_read_data (sensor_h handle, sensor_data_accuracy_e* accuracy, bool* is_near) +int sensor_proximity_read_data (sensor_h handle, sensor_data_accuracy_e* accuracy, float* distance) { float values[1] = {0}; int err = _sensor_read_data(handle, SENSOR_PROXIMITY, accuracy, values, 1); if(err < 0) return err; - if(is_near == NULL) + if(distance == NULL) RETURN_ERROR(SENSOR_ERROR_INVALID_PARAMETER); - *is_near = (bool)values[0]; + *distance = values[0]; return SENSOR_ERROR_NONE; }