@Override protected boolean initImpl() { if (GlassUtils.instance$.isGlassDevice()) return false; magnetoEnabled = mSettings.isAbsoluteControlEnabled(); if (magnetoEnabled) { if (mDroneControl.getDroneVersion() == EDroneVersion.DRONE_1 || !mOrientationManager.isMagnetoAvailable()) { // Drone 1 doesn't have compass, so we need to switch magneto // off. magnetoEnabled = false; mSettings.setAbsoluteControlEnabled(false); } } mDroneControl.setMagntoEnabled(magnetoEnabled); applyJoypadConfig(mSettings.getControlMode(), mSettings.isLeftHanded()); return true; }
@Override public void onDeviceOrientationChanged( float[] orientation, float magneticHeading, int magnetoAccuracy) { if (magnetoEnabled && mOrientationManager.isMagnetoAvailable()) { float heading = magneticHeading * 57.2957795f; if (screenRotationIndex == 1) { heading += 90.f; } mDroneControl.setDeviceOrientation((int) heading, 0); } else { mDroneControl.setDeviceOrientation(0, 0); } final boolean isInTouchMode = !GlassUtils.instance$.isGlassDevice(); if (!running) { pitchGazBase = orientation[PITCH]; rollYawBase = orientation[ROLL]; if (isInTouchMode) { mDroneControl.setDronePitch(0); mDroneControl.setDroneRoll(0); } else { mDroneControl.setDroneGaz(0); mDroneControl.setDroneYaw(0); } } else { float x = orientation[PITCH] - pitchGazBase; float y = (orientation[ROLL] - rollYawBase); // if ( timeCounter > -1 && (System.currentTimeMillis() - timeCounter >= 500l) ) { // Log.d(TAG, "Diffs: [x: " + x + ", y: " + y + "]"); // timeCounter = System.currentTimeMillis(); // } if (!isInTouchMode) { if (acceleroEnabled && ( /* Math.abs(x) > ACCELERO_TRESHOLD || */ Math.abs(y) > ACCELERO_TRESHOLD)) { mDroneControl.setDroneYaw(y); // mDroneControl.setDroneGaz(x); } } else { if (screenRotationIndex == 0) { // Xoom if (acceleroEnabled && (Math.abs(x) > ACCELERO_TRESHOLD || Math.abs(y) > ACCELERO_TRESHOLD)) { x *= -1; mDroneControl.setDronePitch(x); mDroneControl.setDroneRoll(y); } } else if (screenRotationIndex == 1) { if (acceleroEnabled && (Math.abs(x) > ACCELERO_TRESHOLD || Math.abs(y) > ACCELERO_TRESHOLD)) { x *= -1; y *= -1; mDroneControl.setDronePitch(y); mDroneControl.setDroneRoll(x); } } else if (screenRotationIndex == 3) { // google tv if (acceleroEnabled && (Math.abs(x) > ACCELERO_TRESHOLD || Math.abs(y) > ACCELERO_TRESHOLD)) { mDroneControl.setDronePitch(y); mDroneControl.setDroneRoll(x); } } } } }