Search in sources :

Example 6 with DJIError

use of dji.common.error.DJIError in project uav_mobile_app by jiushuokj.

the class MyMqttService method gimbalControl.

private void gimbalControl(final MqttMessage message) {
    Log.i(TAG, "gimbalControl: ");
    GimbalControlRequest request = JSON.parseObject(new String(message.getPayload()), GimbalControlRequest.class);
    Rotation rotation = new Rotation.Builder().mode(RotationMode.values()[request.getMode().ordinal()]).pitch(request.getPitch()).roll(request.getRoll()).yaw(request.getYaw()).time(request.getTime()).build();
    for (Gimbal gimbal : aircraft.getGimbals()) {
        Log.i(TAG, "gimbalControl: gimbals--->" + gimbal);
    }
    aircraft.getGimbals().get(0).rotate(rotation, new CommonCallbacks.CompletionCallback() {

        @Override
        public void onResult(DJIError djiError) {
            makeDefaultResponse(djiError, message);
        }
    });
}
Also used : ProtoGimbal(com.jskj.mobile.state.ProtoGimbal) Gimbal(dji.sdk.gimbal.Gimbal) GimbalControlRequest(com.jiushuo.uavRct.entity.mqtt.GimbalControlRequest) CommonCallbacks(dji.common.util.CommonCallbacks) DJIError(dji.common.error.DJIError) Rotation(dji.common.gimbal.Rotation)

Example 7 with DJIError

use of dji.common.error.DJIError in project uav_mobile_app by jiushuokj.

the class MyMqttService method cameraMode.

private void cameraMode(final MqttMessage message) {
    final CameraModeRequest request = JSON.parseObject(new String(message.getPayload()), CameraModeRequest.class);
    aircraft.getCameras().get(0).setMode(SettingsDefinitions.CameraMode.values()[request.getCameraMode()], new CommonCallbacks.CompletionCallback() {

        @Override
        public void onResult(DJIError djiError) {
            String responseTopicName = request.getResTopic();
            if (djiError != null) {
                Log.i(TAG, "onResult: " + responseTopicName + djiError.getDescription());
                if (responseTopicName != null) {
                    CameraModeResponse response = new CameraModeResponse();
                    response.setCode(djiError.getErrorCode());
                    response.setCameraMode(cameraMode.ordinal());
                    response(responseTopicName, JSON.toJSONString(response, SerializerFeature.WriteMapNullValue));
                }
            } else {
                Log.i(TAG, "onResult:" + responseTopicName + " success!");
                if (responseTopicName != null) {
                    CameraModeResponse response = new CameraModeResponse();
                    response.setCode(RequestUtil.CODE_SUCCESS);
                    response.setCameraMode(cameraMode.ordinal());
                    response(responseTopicName, JSON.toJSONString(response, SerializerFeature.WriteMapNullValue));
                }
            }
        }
    });
}
Also used : CameraModeResponse(com.jiushuo.uavRct.entity.mqtt.CameraModeResponse) CommonCallbacks(dji.common.util.CommonCallbacks) DJIError(dji.common.error.DJIError) CameraModeRequest(com.jiushuo.uavRct.entity.mqtt.CameraModeRequest)

Example 8 with DJIError

use of dji.common.error.DJIError in project StickFlight by gly2000.

the class DemoApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mHandler = new Handler(Looper.getMainLooper());
    // Check the permissions before registering the application for android system 6.0 above.
    int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    int permissionCheck2 = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.READ_PHONE_STATE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (permissionCheck == 0 && permissionCheck2 == 0)) {
        // This is used to start SDK services and initiate SDK.
        DJISDKManager.getInstance().registerApp(getApplicationContext(), mDJISDKManagerCallback);
    } else {
        Toast.makeText(getApplicationContext(), "Please check if the permission is granted.", Toast.LENGTH_LONG).show();
    }
    /**
     * When starting SDK services, an instance of interface DJISDKManager.DJISDKManagerCallback will be used to listen to
     * the SDK Registration result and the product changing.
     */
    mDJISDKManagerCallback = new DJISDKManager.SDKManagerCallback() {

        // Listens to the SDK registration result
        @Override
        public void onRegister(DJIError error) {
            if (error == DJISDKError.REGISTRATION_SUCCESS) {
                DJISDKManager.getInstance().startConnectionToProduct();
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Register Success", Toast.LENGTH_LONG).show();
                    }
                });
                loginAccount();
            } else {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Register Failed, check network is available", Toast.LENGTH_LONG).show();
                    }
                });
            }
            Log.e("TAG", error.toString());
        }

        @Override
        public void onProductDisconnect() {
            Log.d("TAG", "onProductDisconnect");
            notifyStatusChange();
        }

        @Override
        public void onProductConnect(BaseProduct baseProduct) {
            Log.d("TAG", String.format("onProductConnect newProduct:%s", baseProduct));
            notifyStatusChange();
        }

        @Override
        public void onProductChanged(BaseProduct baseProduct) {
            Log.d("TAG", String.format("onProductChanged newProduct:%s", baseProduct));
            notifyStatusChange();
        }

        @Override
        public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent, BaseComponent newComponent) {
            if (newComponent != null) {
                newComponent.setComponentListener(new BaseComponent.ComponentListener() {

                    @Override
                    public void onConnectivityChange(boolean isConnected) {
                        Log.d("TAG", "onComponentConnectivityChanged: " + isConnected);
                        notifyStatusChange();
                    }
                });
            }
            Log.d("TAG", String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s", componentKey, oldComponent, newComponent));
        }

        @Override
        public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {
        }

        @Override
        public void onDatabaseDownloadProgress(long l, long l1) {
        }
    };
}
Also used : BaseComponent(dji.sdk.base.BaseComponent) DJISDKManager(dji.sdk.sdkmanager.DJISDKManager) Handler(android.os.Handler) DJIError(dji.common.error.DJIError) DJISDKInitEvent(dji.sdk.sdkmanager.DJISDKInitEvent) BaseProduct(dji.sdk.base.BaseProduct)

Example 9 with DJIError

use of dji.common.error.DJIError in project mavicmini by kadytoast.

the class AircraftObjHandler method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mHandler = new Handler(Looper.getMainLooper());
    /**
     * When starting SDK services, an instance of interface DJISDKManager.DJISDKManagerCallback will be used to listen to
     * the SDK Registration result and the product changing.
     */
    mDJISDKManagerCallback = new DJISDKManager.SDKManagerCallback() {

        // Listens to the SDK registration result
        @Override
        public void onRegister(DJIError error) {
            if (error == DJISDKError.REGISTRATION_SUCCESS) {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Register Success", Toast.LENGTH_LONG).show();
                    }
                });
                DJISDKManager.getInstance().startConnectionToProduct();
            } else {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Register sdk fails, check network is available", Toast.LENGTH_LONG).show();
                    }
                });
            }
            Log.e("TAG", error.toString());
        }

        @Override
        public void onProductDisconnect() {
            Log.d("TAG", "onProductDisconnect");
            notifyStatusChange();
        }

        @Override
        public void onProductConnect(BaseProduct baseProduct) {
            Log.d("TAG", String.format("onProductConnect newProduct:%s", baseProduct));
            notifyStatusChange();
        }

        @Override
        public void onProductChanged(BaseProduct baseProduct) {
        }

        @Override
        public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent, BaseComponent newComponent) {
            if (newComponent != null) {
                newComponent.setComponentListener(new BaseComponent.ComponentListener() {

                    @Override
                    public void onConnectivityChange(boolean isConnected) {
                        Log.d("TAG", "onComponentConnectivityChanged: " + isConnected);
                        notifyStatusChange();
                    }
                });
            }
            Log.d("TAG", String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s", componentKey, oldComponent, newComponent));
        }

        @Override
        public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {
        }

        @Override
        public void onDatabaseDownloadProgress(long l, long l1) {
        }
    };
    // Check the permissions before registering the application for android system 6.0 above.
    int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    int permissionCheck2 = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.READ_PHONE_STATE);
    if (permissionCheck == 0 && permissionCheck2 == 0) {
        // This is used to start SDK services and initiate SDK.
        Toast.makeText(getApplicationContext(), "trying to register:", Toast.LENGTH_LONG).show();
        DJISDKManager.getInstance().registerApp(getApplicationContext(), mDJISDKManagerCallback);
        Toast.makeText(getApplicationContext(), "registering, pls wait...", Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(getApplicationContext(), "Please check if the permission is granted.", Toast.LENGTH_LONG).show();
    }
}
Also used : BaseComponent(dji.sdk.base.BaseComponent) DJISDKManager(dji.sdk.sdkmanager.DJISDKManager) Handler(android.os.Handler) DJIError(dji.common.error.DJIError) DJISDKInitEvent(dji.sdk.sdkmanager.DJISDKInitEvent) BaseProduct(dji.sdk.base.BaseProduct)

Example 10 with DJIError

use of dji.common.error.DJIError in project StickFlight by gly2000.

the class EditorActivity method setControlMode.

public void setControlMode() {
    aircraft.getFlightController().setVirtualStickModeEnabled(true, djiError -> {
        if (null == djiError) {
            isEnableStick = true;
            Log.e("virtual", "enable success");
            aircraft.getFlightController().setRollPitchCoordinateSystem(FlightCoordinateSystem.GROUND);
            aircraft.getFlightController().setVerticalControlMode(VerticalControlMode.POSITION);
            aircraft.getFlightController().setYawControlMode(YawControlMode.ANGLE);
            aircraft.getFlightController().setRollPitchControlMode(RollPitchControlMode.VELOCITY);
            Toast toast = Toast.makeText(getApplicationContext(), "Stick flight model start!", Toast.LENGTH_LONG);
            toast.show();
        } else {
            Log.e("virtual", "error = " + djiError.getDescription());
            Toast toast = Toast.makeText(getApplicationContext(), "error = " + djiError.getDescription(), Toast.LENGTH_LONG);
            toast.show();
        }
    });
    if (null == sendVirtualStickDataTimer) {
        sendVirtualStickDataTask = new TimerTask() {

            @Override
            public void run() {
                if (isFlightControllerAvailable()) {
                    aircraft.getFlightController().sendVirtualStickFlightControlData(new FlightControlData(pitch, roll, yaw, throttle), new CommonCallbacks.CompletionCallback() {

                        @Override
                        public void onResult(DJIError djiError) {
                        }
                    });
                } else {
                    Log.e("SendVirtualStickData", "isFlightControllerAvailable = false");
                }
            }
        };
        sendVirtualStickDataTimer = new Timer();
        sendVirtualStickDataTimer.schedule(sendVirtualStickDataTask, 100, 200);
    } else {
        Log.e("dispatch", "isEnableStick = false");
    }
}
Also used : FlightControlData(dji.common.flightcontroller.virtualstick.FlightControlData) Toast(android.widget.Toast) TimerTask(java.util.TimerTask) Timer(java.util.Timer) DJIError(dji.common.error.DJIError)

Aggregations

DJIError (dji.common.error.DJIError)17 CommonCallbacks (dji.common.util.CommonCallbacks)9 MediaFile (dji.sdk.media.MediaFile)4 Handler (android.os.Handler)3 WaypointMission (dji.common.mission.waypoint.WaypointMission)3 BaseComponent (dji.sdk.base.BaseComponent)3 BaseProduct (dji.sdk.base.BaseProduct)3 DJISDKInitEvent (dji.sdk.sdkmanager.DJISDKInitEvent)3 DJISDKManager (dji.sdk.sdkmanager.DJISDKManager)3 SuppressLint (android.annotation.SuppressLint)2 ProtoWaypointMission (com.jskj.mobile.request.ProtoWaypointMission)2 Waypoint (dji.common.mission.waypoint.Waypoint)2 ArrayList (java.util.ArrayList)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Bitmap (android.graphics.Bitmap)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1