Пример #1
0
  public static void enableFollowMe(
      DroneManager droneMgr,
      Handler droneHandler,
      FollowType followType,
      ICommandListener listener) {
    if (droneMgr == null) return;

    final FollowAlgorithm.FollowModes selectedMode =
        CommonApiUtils.followTypeToMode(droneMgr.getDrone(), followType);

    if (selectedMode != null) {
      final Follow followMe = droneMgr.getFollowMe();
      if (followMe == null) return;

      if (!followMe.isEnabled()) followMe.toggleFollowMeState();

      FollowAlgorithm currentAlg = followMe.getFollowAlgorithm();
      if (currentAlg.getType() != selectedMode) {
        if (selectedMode == FollowAlgorithm.FollowModes.SOLO_SHOT
            && !SoloApiUtils.isSoloLinkFeatureAvailable(droneMgr, listener)) return;

        followMe.setAlgorithm(selectedMode.getAlgorithmType(droneMgr, droneHandler));
        postSuccessEvent(listener);
      }
    }
  }
Пример #2
0
  public static FollowState getFollowState(Follow followMe) {
    if (followMe == null) return new FollowState();

    final int state;
    switch (followMe.getState()) {
      default:
      case FOLLOW_INVALID_STATE:
        state = FollowState.STATE_INVALID;
        break;

      case FOLLOW_DRONE_NOT_ARMED:
        state = FollowState.STATE_DRONE_NOT_ARMED;
        break;

      case FOLLOW_DRONE_DISCONNECTED:
        state = FollowState.STATE_DRONE_DISCONNECTED;
        break;

      case FOLLOW_START:
        state = FollowState.STATE_START;
        break;

      case FOLLOW_RUNNING:
        state = FollowState.STATE_RUNNING;
        break;

      case FOLLOW_END:
        state = FollowState.STATE_END;
        break;
    }

    final FollowAlgorithm currentAlg = followMe.getFollowAlgorithm();
    Map<String, Object> modeParams = currentAlg.getParams();
    Bundle params = new Bundle();
    for (Map.Entry<String, Object> entry : modeParams.entrySet()) {
      switch (entry.getKey()) {
        case FollowType.EXTRA_FOLLOW_ROI_TARGET:
          LatLongAlt target = (LatLongAlt) entry.getValue();
          if (target != null) {
            params.putParcelable(entry.getKey(), target);
          }
          break;

        case FollowType.EXTRA_FOLLOW_RADIUS:
          Double radius = (Double) entry.getValue();
          if (radius != null) params.putDouble(entry.getKey(), radius);
          break;
      }
    }
    return new FollowState(state, CommonApiUtils.followModeToType(currentAlg.getType()), params);
  }