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);
}
});
}
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));
}
}
}
});
}
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) {
}
};
}
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();
}
}
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");
}
}
Aggregations