From: kibak.yoon Date: Fri, 14 Jul 2017 04:23:32 +0000 (+0900) Subject: sensor: capi: add sensor_util_get_altitude API X-Git-Tag: submit/tizen/20170726.085456~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3e4ab7b1439b89758dbe1543131c7009c93a79ba;p=platform%2Fcore%2Fapi%2Fsensor.git sensor: capi: add sensor_util_get_altitude API - this API computes the altitude in meters from the atmospheric pressure, the pressure at sea level and the temperature. Change-Id: Ic77516aeb067bb53b74720aedc5d49b91eab18ed Signed-off-by: kibak.yoon --- diff --git a/include/sensor.h b/include/sensor.h index 0005065..4449fa4 100644 --- a/include/sensor.h +++ b/include/sensor.h @@ -1900,6 +1900,24 @@ int sensor_util_get_angle_change(float R[], float prevR[], float angleChange[]); * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter */ int sensor_util_get_declination(float latitude, float longitude, float altitude, float* declination); + +/** + * @brief Gets the altitude from the atmospheric pressure, the pressure at sea level and temperature, in meters. + * @since_tizen 4.0 + * + * @param[in] pressure The atmospheric pressure (hPa) + * @param[in] sea_level_pressure The sea level pressure (hPa) @n + * If the sea level pressure is not known, you can use 1013.25 hPa, mean sea level pressure + * @param[in] temperature The temperature (degrees Celsius) @n + * If the temperature is not known, you can use 15 degrees Celsius + * @param[out] altitude The altitude (meters) + * + * @return #SENSOR_ERROR_NONE on success; Otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + */ +int sensor_util_get_altitude(float pressure, float sea_level_pressure, float temperature, float* altitude); + /** * @} */ diff --git a/src/sensor.cpp b/src/sensor.cpp index 4480902..f22b3de 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -973,3 +973,16 @@ int sensor_util_get_rotation_matrix(float Gx, float Gy, float Gz, float Mx, floa return SENSOR_ERROR_NONE; } +int sensor_util_get_altitude(float pressure, float sea_level_pressure, float temperature, float* altitude) +{ + if (pressure <= 0) + return SENSOR_ERROR_INVALID_PARAMETER; + if (sea_level_pressure <= 0) + return SENSOR_ERROR_INVALID_PARAMETER; + if (!altitude) + return SENSOR_ERROR_INVALID_PARAMETER; + + *altitude = (temperature + 273.15f) / 0.0065f * (1.0f - pow(pressure/sea_level_pressure, 1.0f/5.255f)); + + return SENSOR_ERROR_NONE; +}