diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/GyroControl.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/GyroControl.java index 4ead091c13..3c3d09a8b2 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/GyroControl.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/GyroControl.java @@ -6,6 +6,7 @@ import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; +import android.util.Log; import android.view.OrientationEventListener; import android.view.Surface; import android.view.WindowManager; @@ -21,6 +22,9 @@ public class GyroControl implements SensorEventListener, GrabListener { /* How much distance has to be moved before taking into account the gyro */ private static final float SINGLE_AXIS_LOW_PASS_THRESHOLD = 1.13F; private static final float MULTI_AXIS_LOW_PASS_THRESHOLD = 1.3F; + // Warmup period of 2 since the first read from the sensor seems to produce a bogus value, + // which creates a far too large of a difference on the Y axis once actual sensor data comes in + private static final int ROTATION_VECTOR_WARMUP_PERIOD = 2; private final WindowManager mWindowManager; private int mSurfaceRotation; @@ -28,7 +32,7 @@ public class GyroControl implements SensorEventListener, GrabListener { private final Sensor mSensor; private final OrientationCorrectionListener mCorrectionListener; private boolean mShouldHandleEvents; - private boolean mFirstPass; + private int mWarmup; private float xFactor; // -1 or 1 depending on device orientation private float yFactor; private boolean mSwapXY; @@ -64,7 +68,7 @@ public GyroControl(Activity activity) { public void enable() { if(mSensor == null) return; - mFirstPass = true; + mWarmup = ROTATION_VECTOR_WARMUP_PERIOD; mSensorManager.registerListener(this, mSensor, 1000 * LauncherPreferences.PREF_GYRO_SAMPLE_RATE); mCorrectionListener.enable(); mShouldHandleEvents = CallbackBridge.isGrabbing(); @@ -75,7 +79,9 @@ public void disable() { if(mSensor == null) return; mSensorManager.unregisterListener(this); mCorrectionListener.disable(); + mStoredX = mStoredY = 0; resetDamper(); + Log.i("GyroControl", "STOP"); CallbackBridge.removeGrabListener(this); } @@ -87,8 +93,8 @@ public void onSensorChanged(SensorEvent sensorEvent) { SensorManager.getRotationMatrixFromVector(mCurrentRotation, sensorEvent.values); - if(mFirstPass){ // Setup initial position - mFirstPass = false; + if(mWarmup > 0){ // Setup initial position + mWarmup--; return; } SensorManager.getAngleChange(mAngleDifference, mCurrentRotation, mPreviousRotation); @@ -161,7 +167,7 @@ public void onAccuracyChanged(Sensor sensor, int i) {} @Override public void onGrabState(boolean isGrabbing) { - mFirstPass = true; + mWarmup = ROTATION_VECTOR_WARMUP_PERIOD; mShouldHandleEvents = isGrabbing; }