am 29c99aaa: Merge "Added check to make orientation calculations more robust" into gingerbread
* commit '29c99aaaaed00c605fb6cd64de169fafad0e40ed': Added check to make orientation calculations more robust
This commit is contained in:
@@ -234,6 +234,14 @@ public abstract class WindowOrientationListener {
|
|||||||
// high time constant.
|
// high time constant.
|
||||||
private static final float MAX_DEVIATION_FROM_GRAVITY = 1.5f;
|
private static final float MAX_DEVIATION_FROM_GRAVITY = 1.5f;
|
||||||
|
|
||||||
|
// Minimum acceleration considered, in m/s^2. Below this threshold sensor noise will have
|
||||||
|
// significant impact on the calculations and in case of the vector (0, 0, 0) there is no
|
||||||
|
// defined rotation or tilt at all. Low or zero readings can happen when space travelling
|
||||||
|
// or free falling, but more commonly when shaking or getting bad readings from the sensor.
|
||||||
|
// The accelerometer is turned off when not used and polling it too soon after it is
|
||||||
|
// turned on may result in (0, 0, 0).
|
||||||
|
private static final float MIN_ABS_ACCELERATION = 1.5f;
|
||||||
|
|
||||||
// Actual sampling period corresponding to SensorManager.SENSOR_DELAY_NORMAL. There's no
|
// Actual sampling period corresponding to SensorManager.SENSOR_DELAY_NORMAL. There's no
|
||||||
// way to get this information from SensorManager.
|
// way to get this information from SensorManager.
|
||||||
// Note the actual period is generally 3-30ms larger than this depending on the device, but
|
// Note the actual period is generally 3-30ms larger than this depending on the device, but
|
||||||
@@ -347,6 +355,9 @@ public abstract class WindowOrientationListener {
|
|||||||
float deviation = Math.abs(magnitude - SensorManager.STANDARD_GRAVITY);
|
float deviation = Math.abs(magnitude - SensorManager.STANDARD_GRAVITY);
|
||||||
|
|
||||||
handleAccelerationDistrust(deviation);
|
handleAccelerationDistrust(deviation);
|
||||||
|
if (magnitude < MIN_ABS_ACCELERATION) {
|
||||||
|
return; // Ignore tilt and orientation when (0, 0, 0) or low reading
|
||||||
|
}
|
||||||
|
|
||||||
// only filter tilt when we're accelerating
|
// only filter tilt when we're accelerating
|
||||||
float alpha = 1;
|
float alpha = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user