summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2010-07-29 17:59:58 -0700
committerMathias Agopian <mathias@google.com>2010-07-29 18:18:01 -0700
commit04d7e83e65e246e154b5b346e3eb0081b741ae88 (patch)
tree010c86fa7361f8e09dee2e496a4ed04b2f077d38
parent050b56244ff46d43e4886018d7cd20f0b1dc02b9 (diff)
downloadframeworks_base-04d7e83e65e246e154b5b346e3eb0081b741ae88.zip
frameworks_base-04d7e83e65e246e154b5b346e3eb0081b741ae88.tar.gz
frameworks_base-04d7e83e65e246e154b5b346e3eb0081b741ae88.tar.bz2
Added SensorManager.getAltitude()
this is a helper function to calculate the altitude from the pressure and pressure at sea level. Change-Id: I3f6f14fee6190388f95afa36a66287e3d59eef9b
-rw-r--r--api/current.xml26
-rw-r--r--core/java/android/hardware/SensorManager.java37
2 files changed, 56 insertions, 7 deletions
diff --git a/api/current.xml b/api/current.xml
index 9de160a..4dd0909 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -77858,6 +77858,21 @@
deprecated="not deprecated"
visibility="public"
>
+<method name="getAltitude"
+ return="float"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="p0" type="float">
+</parameter>
+<parameter name="p" type="float">
+</parameter>
+</method>
<method name="getDefaultSensor"
return="android.hardware.Sensor"
abstract="false"
@@ -78437,6 +78452,17 @@
visibility="public"
>
</field>
+<field name="PRESSURE_STANDARD_ATMOSPHERE"
+ type="float"
+ transient="false"
+ volatile="false"
+ value="1013.25f"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="RAW_DATA_INDEX"
type="int"
transient="false"
diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java
index 5cc8d5d..f6d237a 100644
--- a/core/java/android/hardware/SensorManager.java
+++ b/core/java/android/hardware/SensorManager.java
@@ -268,6 +268,10 @@ public class SensorManager
public static final float MAGNETIC_FIELD_EARTH_MIN = 30.0f;
+ /** Standard atmosphere, or average sea-level pressure in hPa (millibar) */
+ public static final float PRESSURE_STANDARD_ATMOSPHERE = 1013.25f;
+
+
/** Maximum luminance of sunlight in lux */
public static final float LIGHT_SUNLIGHT_MAX = 120000.0f;
/** luminance of sunlight in lux */
@@ -573,11 +577,11 @@ public class SensorManager
// which won't get the rotated values
try {
sRotation = sWindowManager.watchRotation(
- new IRotationWatcher.Stub() {
- public void onRotationChanged(int rotation) {
- SensorManager.this.onRotationChanged(rotation);
+ new IRotationWatcher.Stub() {
+ public void onRotationChanged(int rotation) {
+ SensorManager.this.onRotationChanged(rotation);
+ }
}
- }
);
} catch (RemoteException e) {
}
@@ -638,7 +642,7 @@ public class SensorManager
break;
case Sensor.TYPE_ORIENTATION:
result |= SensorManager.SENSOR_ORIENTATION |
- SensorManager.SENSOR_ORIENTATION_RAW;
+ SensorManager.SENSOR_ORIENTATION_RAW;
break;
}
}
@@ -1488,7 +1492,7 @@ public class SensorManager
* @see #getRotationMatrix(float[], float[], float[], float[])
* @see GeomagneticField
*/
- public static float[] getOrientation(float[] R, float values[]) {
+ public static float[] getOrientation(float[] R, float values[]) {
/*
* 4x4 (length=16) case:
* / R[ 0] R[ 1] R[ 2] 0 \
@@ -1514,8 +1518,27 @@ public class SensorManager
return values;
}
-
/**
+ * Computes the Altitude in meters from the atmospheric pressure and the
+ * pressure at sea level.
+ * <p>
+ * Typically the atmospheric pressure is read from a
+ * {@link Sensor#TYPE_PRESSURE} sensor. The pressure at sea level must be
+ * known, usually it can be retrieved from airport databases in the
+ * vicinity.
+ * </p>
+ *
+ * @param p0 pressure at sea level
+ * @param p atmospheric pressure
+ * @return Altitude in meters
+ */
+ public static float getAltitude(float p0, float p) {
+ final float coef = 1.0f / 5.255f;
+ return 44330.0f * (1.0f - (float)Math.pow(p/p0, coef));
+ }
+
+
+ /**
* {@hide}
*/
public void onRotationChanged(int rotation) {