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 i2) {
        this.mScreenRotation = i2;
    }

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

    private float getDegrees(float f2, float f3, float f4) {
        float alpha = getAlpha(f4);
        float[] fArr = this.mLastAcceleration;
        float f5 = 1.0f - alpha;
        fArr[0] = (f2 * f5) + (fArr[0] * alpha);
        fArr[1] = (f5 * f3) + (alpha * fArr[1]);
        float degrees = (float) Math.toDegrees(Math.atan(fArr[0] / fArr[1]));
        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 f2, float f3, long j2) {
        return getSuggestDegrees(f2, f3, 0.0f, j2);
    }

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

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

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