예제 #1
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.v2andlib_single_fragment);
   if (savedInstanceState == null) {
     Fragment fragment = DemoUDPDiscoveryList.newInstance();
     FragmentTransaction trans = getFragmentManager().beginTransaction();
     trans.replace(R.id.v2andLibFragment, fragment);
     trans.commit();
   }
 }
  @Override
  protected void onResume() {
    // TODO Auto-generated method stub

    mTimer = new Timer();
    Task task = new Task();
    mTimer.schedule(task, 0, 500);

    DJIDrone.getDjiMC().startUpdateTimer(1000);
    DJIDrone.getDjiGroundStation().startUpdateTimer(1000);

    super.onResume();
  }
  @Override
  protected void onDestroy() {
    // TODO Auto-generated method stub

    if (DJIDrone.getDjiCamera() != null) DJIDrone.getDjiCamera().setReceivedVideoDataCallBack(null);
    mDjiGLSurfaceView.destroy();
    if (mCheckModeForPauseTimer != null) {
      mCheckModeForPauseTimer.cancel();
      mCheckModeForPauseTimer.purge();
      mCheckModeForPauseTimer = null;
    }

    super.onDestroy();
  }
  @Override
  protected void onPause() {
    // TODO Auto-generated method stub
    if (mTimer != null) {
      mTimer.cancel();
      mTimer.purge();
      mTimer = null;
    }

    DJIDrone.getDjiMC().stopUpdateTimer();
    DJIDrone.getDjiGroundStation().stopUpdateTimer();

    super.onPause();
  }
 @Override
 protected void onStop() {
   // TODO Auto-generated method stub
   super.onStop();
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_gs_protocol_joystick_demo);

    mDjiGLSurfaceView = (DjiGLSurfaceView) findViewById(R.id.DjiSurfaceView_gs);
    mOpenGsButton = (Button) findViewById(R.id.OpenGsButton);
    mAddOneWaypointButton = (Button) findViewById(R.id.AddWaypointButton);
    mUploadWaypointButton = (Button) findViewById(R.id.UploadWaypointButton);
    mTakeOffButton = (Button) findViewById(R.id.TakeOffButton);
    mGohomeButton = (Button) findViewById(R.id.GohomeButton);
    mCloseGsButton = (Button) findViewById(R.id.CloseGsButton);
    mPauseButton = (Button) findViewById(R.id.PauseButton);
    mResumeButton = (Button) findViewById(R.id.ResumeButton);
    mConnectStateTextView = (TextView) findViewById(R.id.ConnectStateGsTextView);
    mScreenJoystickRight = (OnScreenJoystick) findViewById(R.id.directionJoystickRight);
    mScreenJoystickLeft = (OnScreenJoystick) findViewById(R.id.directionJoystickLeft);
    mOneKeyFlyButton = (Button) findViewById(R.id.OneKeyFlyButton);

    mOpenGsButton.setOnClickListener(this);
    mAddOneWaypointButton.setOnClickListener(this);
    mUploadWaypointButton.setOnClickListener(this);
    mTakeOffButton.setOnClickListener(this);
    mGohomeButton.setOnClickListener(this);
    mCloseGsButton.setOnClickListener(this);
    mPauseButton.setOnClickListener(this);
    mResumeButton.setOnClickListener(this);
    mOneKeyFlyButton.setOnClickListener(this);

    mScreenJoystickLeft.setJoystickListener(
        new OnScreenJoystickListener() {

          @Override
          public void onTouch(OnScreenJoystick joystick, float pX, float pY) {
            // TODO Auto-generated method stub
            // Log.d(TAG ,"mScreenJoystickLeft "+pX+" "+pY);
            int YawJoyControlMaxSpeed = 500;

            yaw = (int) (YawJoyControlMaxSpeed * pX);

            throttle = 0;

            if (pY > 0) {
              throttle = 1;
            } else if (pY <= -0.9) {
              // if(pY == -1){
              //	throttle = 2;
              // }
              throttle = 2;
            }

            //                new Thread()
            //                {
            //                    public void run()
            //                    {

            DJIDrone.getDjiGroundStation()
                .setAircraftJoystick(
                    yaw,
                    pitch,
                    roll,
                    throttle,
                    new DJIGroundStationExecuteCallBack() {

                      @Override
                      public void onResult(GroundStationResult result) {
                        // TODO Auto-generated method stub

                      }
                    });
            //                    }
            //                }.start();

          }
        });

    mScreenJoystickRight.setJoystickListener(
        new OnScreenJoystickListener() {

          @Override
          public void onTouch(OnScreenJoystick joystick, float pX, float pY) {
            // TODO Auto-generated method stub
            // Log.d(TAG ,"mScreenJoystickRight "+pX+" "+pY);
            int PitchJoyControlMaxSpeed = 1000;
            int RollJoyControlMaxSpeed = 1000;

            pitch = (int) (PitchJoyControlMaxSpeed * pY);

            roll = (int) (RollJoyControlMaxSpeed * pX);

            // Log.d(TAG ,"mScreenJoystickRight pitch="+pitch);
            // Log.d(TAG ,"mScreenJoystickRight roll="+roll);

            //                new Thread()
            //                {
            //                    public void run()
            //                    {

            DJIDrone.getDjiGroundStation()
                .setAircraftJoystick(
                    yaw,
                    pitch,
                    roll,
                    throttle,
                    new DJIGroundStationExecuteCallBack() {

                      @Override
                      public void onResult(GroundStationResult result) {
                        // TODO Auto-generated method stub

                      }
                    });
            //                    }
            //                }.start();
          }
        });

    mDjiGLSurfaceView.start();

    mReceivedVideoDataCallBack =
        new DJIReceivedVideoDataCallBack() {

          @Override
          public void onResult(byte[] videoBuffer, int size) {
            // TODO Auto-generated method stub
            mDjiGLSurfaceView.setDataToDecoder(videoBuffer, size);
          }
        };

    DJIDrone.getDjiCamera().setReceivedVideoDataCallBack(mReceivedVideoDataCallBack);

    mMcuUpdateStateCallBack =
        new DJIMcuUpdateStateCallBack() {

          @Override
          public void onResult(DJIMainControllerSystemState state) {
            // TODO Auto-generated method stub
            // Log.e(TAG, "DJIMainControllerSystemState homeLocationLatitude "
            // +state.homeLocationLatitude);
            // Log.e(TAG, "DJIMainControllerSystemState homeLocationLongitude "
            // +state.homeLocationLongitude);
            homeLocationLatitude = state.homeLocationLatitude;
            homeLocationLongitude = state.homeLocationLongitude;

            aircraftLocationLatitude = state.droneLocationLatitude;
            aircraftLocationLongitude = state.droneLocationLongitude;

            isFlying = state.isFlying;

            if (homeLocationLatitude != -1
                && homeLocationLongitude != -1
                && homeLocationLatitude != 0
                && homeLocationLongitude != 0) {
              getHomePiontFlag = true;
            } else {
              getHomePiontFlag = false;
            }
          }
        };

    DJIDrone.getDjiMC().setMcuUpdateStateCallBack(mMcuUpdateStateCallBack);

    mGroundStationFlyingInfoCallBack =
        new DJIGroundStationFlyingInfoCallBack() {

          @Override
          public void onResult(DJIGroundStationFlyingInfo flyingInfo) {
            // TODO Auto-generated method stub
            // Log.e(TAG, "DJIGroundStationFlyingInfo homeLocationLatitude "
            // +flyingInfo.homeLocationLatitude);
            // Log.e(TAG, "DJIGroundStationFlyingInfo homeLocationLongitude "
            // +flyingInfo.homeLocationLongitude);

            mFlightMode = flyingInfo.flightMode;
          }
        };

    DJIDrone.getDjiGroundStation()
        .setGroundStationFlyingInfoCallBack(mGroundStationFlyingInfoCallBack);

    mTask = new DJIGroundStationTask();

    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
  }