package com.seewo.sdk.sensor;

import com.seewo.sdk.util.RLog;

/* JADX INFO: loaded from: classes.dex */
public class DegreesHelper {
    private static final float ALPHA = 0.8f;
    private static final int ANTI_JITTER_DEGREES = 3;
    private static final float MAX_GYROSCOPE = 30.517578f;
    private static final int POSITION_DEGREES = 5;
    private boolean isClockwise;
    private float[] mLastAcceleration = new float[2];
    private float mLastDegrees;
    private long mLastTimestamp;
    private int mScreenRotation;

    public DegreesHelper(int i) {
        this.mScreenRotation = i;
    }

    public void setScreenRotation(int i) {
        this.mScreenRotation = i;
    }

    private float getAlpha(float f) {
        return Math.max(0.0f, ALPHA - (Math.min(Math.abs(f), MAX_GYROSCOPE) / 38.146973f));
    }

    private float getDegrees(float f, float f2, float f3) {
        float alpha = getAlpha(f3);
        float[] fArr = this.mLastAcceleration;
        float f4 = 1.0f - alpha;
        fArr[0] = (fArr[0] * alpha) + (f * f4);
        fArr[1] = (alpha * fArr[1]) + (f4 * f2);
        float degrees = (float) Math.toDegrees(Math.atan(r2 / r7));
        if (degrees < 0.0f) {
            degrees = Math.abs(degrees) > 45.0f ? 90.0f : 0.0f;
        }
        return 3 == this.mScreenRotation ? 90.0f - Math.abs(degrees) : degrees;
    }

    @Deprecated
    public float getSuggestDegrees(float f, float f2, long j) {
        return getSuggestDegrees(f, f2, 0.0f, j);
    }

    public float getSuggestDegrees(float f, float f2, float f3, long j) {
        float degrees = getDegrees(f, f2, f3);
        if (Math.abs(degrees - this.mLastDegrees) >= 3.0f && j - this.mLastTimestamp < 120000000) {
            return getDegrees(this.mLastDegrees);
        }
        if (this.isClockwise) {
            float f4 = this.mLastDegrees;
            if (degrees - f4 > 0.0f && degrees - f4 < 3.0f) {
                return getDegrees(f4);
            }
        } else {
            float f5 = this.mLastDegrees;
            if (degrees - f5 < 0.0f && degrees - f5 > -3.0f) {
                return getDegrees(f5);
            }
        }
        float f6 = this.mLastDegrees;
        if (degrees - f6 >= 3.0f) {
            this.isClockwise = false;
        } else if (degrees - f6 <= -3.0f) {
            this.isClockwise = true;
        }
        this.mLastDegrees = degrees;
        this.mLastTimestamp = j;
        return getDegrees(degrees);
    }

    private float getDegrees(float f) {
        RLog.d("DegreesHelper", "degress: " + f);
        if (f <= 5.0f) {
            return 0.0f;
        }
        if (f >= 85.0f) {
            return 90.0f;
        }
        return f;
    }
}
