Skip to content

Commit 0da554a

Browse files
pixelflingerAndroid (Google) Code Review
authored andcommitted
Merge "fix an overflow in the orientation sensonr calculations" into jb-mr1-dev
2 parents 61ebf9c + 278a966 commit 0da554a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

core/java/android/hardware/LegacySensorManager.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private static final class LmsFilter {
371371
private static final float PREDICTION_RATIO = 1.0f/3.0f;
372372
private static final float PREDICTION_TIME = (SENSORS_RATE_MS*COUNT/1000.0f)*PREDICTION_RATIO;
373373
private float mV[] = new float[COUNT*2];
374-
private float mT[] = new float[COUNT*2];
374+
private long mT[] = new long[COUNT*2];
375375
private int mIndex;
376376

377377
public LmsFilter() {
@@ -381,7 +381,6 @@ public LmsFilter() {
381381
public float filter(long time, float in) {
382382
float v = in;
383383
final float ns = 1.0f / 1000000000.0f;
384-
final float t = time*ns;
385384
float v1 = mV[mIndex];
386385
if ((v-v1) > 180) {
387386
v -= 360;
@@ -396,9 +395,9 @@ public float filter(long time, float in) {
396395
if (mIndex >= COUNT*2)
397396
mIndex = COUNT;
398397
mV[mIndex] = v;
399-
mT[mIndex] = t;
398+
mT[mIndex] = time;
400399
mV[mIndex-COUNT] = v;
401-
mT[mIndex-COUNT] = t;
400+
mT[mIndex-COUNT] = time;
402401

403402
float A, B, C, D, E;
404403
float a, b;
@@ -408,8 +407,8 @@ public float filter(long time, float in) {
408407
for (i=0 ; i<COUNT-1 ; i++) {
409408
final int j = mIndex - 1 - i;
410409
final float Z = mV[j];
411-
final float T = 0.5f*(mT[j] + mT[j+1]) - t;
412-
float dT = mT[j] - mT[j+1];
410+
final float T = (mT[j]/2 + mT[j+1]/2 - time)*ns;
411+
float dT = (mT[j] - mT[j+1])*ns;
413412
dT *= dT;
414413
A += Z*dT;
415414
B += T*(T*dT);

0 commit comments

Comments
 (0)