예제 #1
0
  VirtualJoystick(final ControlDroneActivity droneControl) {
    super(droneControl);

    screenRotationIndex =
        droneControl.getWindow().getWindowManager().getDefaultDisplay().getRotation();

    initJoysticListeners();

    mOrientationManager =
        new DeviceOrientationManager(
            new DeviceSensorManagerWrapper(droneControl.getApplicationContext()), this);
    mOrientationManager.onCreate();

    mSettings = mDroneControl.getSettings();
  }
예제 #2
0
  @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;
  }
예제 #3
0
  @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);
          }
        }
      }
    }
  }
예제 #4
0
 /*
  * (non-Javadoc)
  *
  * @see com.parrot.freeflight.controllers.Controller#destroy()
  */
 @Override
 protected void destroyImpl() {
   mOrientationManager.destroy();
 }
예제 #5
0
 /*
  * (non-Javadoc)
  *
  * @see com.parrot.freeflight.controllers.Controller#pause()
  */
 @Override
 protected void pauseImpl() {
   mOrientationManager.pause();
 }
예제 #6
0
 /*
  * (non-Javadoc)
  *
  * @see com.parrot.freeflight.controllers.Controller#resume()
  */
 @Override
 protected void resumeImpl() {
   mOrientationManager.resume();
 }