@Override protected void onPause() { super.onPause(); ServiceManager.getInstance().pauseService(true); Log.e(TAG, "stopUpdateTimer"); DJIDrone.getDjiMC().stopUpdateTimer(); // Stop the update timer for MC to update info }
@Override protected void onResume() { super.onResume(); ServiceManager.getInstance().pauseService(false); Log.e(TAG, "startUpdateTimer"); DJIDrone.getDjiMC().startUpdateTimer(1000); // Start the update timer for MC to update info }
@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 onPause() { // TODO Auto-generated method stub if (mTimer != null) { mTimer.cancel(); mTimer.purge(); mTimer = null; } DJIDrone.getDjiMC().stopUpdateTimer(); DJIDrone.getDjiGroundStation().stopUpdateTimer(); super.onPause(); }
private void updateDroneLocation() { // Set the McuUpdateSateCallBack mMcuUpdateStateCallBack = new DJIMcuUpdateStateCallBack() { @Override public void onResult(DJIMainControllerSystemState state) { droneLocationLat = state.droneLocationLatitude; droneLocationLng = state.droneLocationLongitude; Log.e(TAG, "drone lat " + state.droneLocationLatitude); Log.e(TAG, "drone lat " + state.homeLocationLatitude); Log.e(TAG, "drone lat " + state.droneLocationLongitude); Log.e(TAG, "drone lat " + state.homeLocationLongitude); } }; Log.e(TAG, "setMcuUpdateState"); DJIDrone.getDjiMC().setMcuUpdateStateCallBack(mMcuUpdateStateCallBack); LatLng pos = new LatLng(droneLocationLat, droneLocationLng); // Create MarkerOptions object final MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(pos); markerOptions.icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_launcher)); runOnUiThread( new Runnable() { @Override public void run() { if (droneMarker != null) { droneMarker.remove(); } droneMarker = aMap.addMarker(markerOptions); } }); }
@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); }