FlightMode { public static int getMode(@NonNull MLocation loc) { final double groundSpeed = loc.groundSpeed(); final double climb = loc.climb; if (-0.3 * groundSpeed + 7 < climb && 33 < groundSpeed) { return MODE_PLANE; } else if (climb < -13 && climb < -groundSpeed - 10 && groundSpeed < 19) { return MODE_FREEFALL; } else if (climb < groundSpeed - 32 && climb < -0.3 * groundSpeed + 5.5) { return MODE_WINGSUIT; } else if (climb < -17) { return MODE_WINGSUIT; } else if (-11.5 < climb && climb < -1.1 && groundSpeed - 31 < climb && climb < groundSpeed - 4 && 1.1 < groundSpeed && groundSpeed < 23.5 && climb < -groundSpeed + 20) { return MODE_CANOPY; } else if (groundSpeed + Math.abs(climb - 1) < 5) { return MODE_GROUND; } else if (-1 < climb && climb < 2 && !(groundSpeed > 10)) { return MODE_GROUND; } else { return MODE_UNKNOWN; } }  static int getMode(@NonNull MLocation loc); static final int MODE_GROUND; static final int MODE_PLANE; static final int MODE_WINGSUIT; static final int MODE_FREEFALL; static final int MODE_CANOPY; }
@Test public void detectFlightMode() { assertEquals("Ground", getMode(getLoc(0, 0))); assertEquals("Ground", getMode(getLoc(1, 10))); assertEquals("Plane", getMode(getLoc(0, 100))); assertEquals("Wingsuit", getMode(getLoc(-20, 50))); assertEquals("Wingsuit", getMode(getLoc(-18, 14))); assertEquals("Freefall", getMode(getLoc(-40, 0))); assertEquals("Canopy", getMode(getLoc(-5, 20))); assertEquals("", getMode(getLoc(15, 20))); }