* @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);
+
/**
* @}
*/
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;
+}