// Path: Android/FPVR/app/src/main/java/com/solersoft/fpvr/util/DJI.java
// public class DJI
// {
//     /**
//      * Returns true if the result is considered a success.
//      * @param errorCode the result.
//      * @return true if result is a success; otherwise false.
//      */
//     public static boolean Success(int errorCode)
//     {
//         return errorCode == 0;
//     }
// }


import android.util.Log;
import com.solersoft.fpvr.fpvrlib.*;
import com.solersoft.fpvr.util.DJI;
import java.security.InvalidParameterException;
import java.util.Timer;
import java.util.TimerTask;
import dji.sdk.api.DJIDrone;
import dji.sdk.api.DJIError;
import dji.sdk.api.Gimbal.DJIGimbal;
import dji.sdk.api.Gimbal.DJIGimbalAttitude;
import dji.sdk.api.Gimbal.DJIGimbalCapacity;
import dji.sdk.api.Gimbal.DJIGimbalRotation;
import dji.sdk.interfaces.DJIExecuteResultCallback;
import dji.sdk.interfaces.DJIGimbalUpdateAttitudeCallBack;
        yaw = clampYaw(yaw);

        // Scale
        int ps = (int)Math.round(pitch);
        int rs = (int)Math.round(roll);
        int ys = (int)Math.round(yaw);

        boolean enabled = true;
        boolean directionBackward = false;
        DJIGimbalRotation pr = new DJIGimbalRotation(enabled, directionBackward, relative, ps);
        DJIGimbalRotation rr = new DJIGimbalRotation(enabled, directionBackward, relative, rs);
        DJIGimbalRotation yr = new DJIGimbalRotation(enabled, directionBackward, relative, ys);

        // Move the gimbal
        Log.i(TAG, "Native Move: PS: " + ps + " RS: " + rs + " YS: " + ys);
        DJIDrone.getDjiGimbal().updateGimbalAttitude(pr, rr, yr);
    }

    private void setGimbalSpeed(int pitchSpeed, int rollSpeed, int yawSpeed)
    {
        // Make sure enabled
        if (!isEnabled()) { return; }

        // Set Gimbal Move Speed
        Log.i(TAG, "Updating gimbal speed: P: " + pitchSpeed + " R: " + rollSpeed + " Y: " + yawSpeed);
        DJIDrone.getDjiRemoteController().setGimbalControlSpeed(pitchSpeed, rollSpeed, yawSpeed, new DJIExecuteResultCallback()
        {
            @Override
            public void onResult(DJIError djiError)
            {
// Path: Android/FPVR/app/src/main/java/com/solersoft/fpvr/util/DJI.java
// public class DJI
// {
//     /**
//      * Returns true if the result is considered a success.
//      * @param errorCode the result.
//      * @return true if result is a success; otherwise false.
//      */
//     public static boolean Success(int errorCode)
//     {
//         return errorCode == 0;
//     }
// }


// Path: Android/FPVR/app/src/main/java/com/solersoft/fpvr/fpvrdji/DJIGimbalService.java
import android.util.Log;
import com.solersoft.fpvr.fpvrlib.*;
import com.solersoft.fpvr.util.DJI;
import java.security.InvalidParameterException;
import java.util.Timer;
import java.util.TimerTask;
import dji.sdk.api.DJIDrone;
import dji.sdk.api.DJIError;
import dji.sdk.api.Gimbal.DJIGimbal;
import dji.sdk.api.Gimbal.DJIGimbalAttitude;
import dji.sdk.api.Gimbal.DJIGimbalCapacity;
import dji.sdk.api.Gimbal.DJIGimbalRotation;
import dji.sdk.interfaces.DJIExecuteResultCallback;
import dji.sdk.interfaces.DJIGimbalUpdateAttitudeCallBack;

        yaw = clampYaw(yaw);

        // Scale
        int ps = (int)Math.round(pitch);
        int rs = (int)Math.round(roll);
        int ys = (int)Math.round(yaw);

        boolean enabled = true;
        boolean directionBackward = false;
        DJIGimbalRotation pr = new DJIGimbalRotation(enabled, directionBackward, relative, ps);
        DJIGimbalRotation rr = new DJIGimbalRotation(enabled, directionBackward, relative, rs);
        DJIGimbalRotation yr = new DJIGimbalRotation(enabled, directionBackward, relative, ys);

        // Move the gimbal
        Log.i(TAG, "Native Move: PS: " + ps + " RS: " + rs + " YS: " + ys);
        DJIDrone.getDjiGimbal().updateGimbalAttitude(pr, rr, yr);
    }

    private void setGimbalSpeed(int pitchSpeed, int rollSpeed, int yawSpeed)
    {
        // Make sure enabled
        if (!isEnabled()) { return; }

        // Set Gimbal Move Speed
        Log.i(TAG, "Updating gimbal speed: P: " + pitchSpeed + " R: " + rollSpeed + " Y: " + yawSpeed);
        DJIDrone.getDjiRemoteController().setGimbalControlSpeed(pitchSpeed, rollSpeed, yawSpeed, new DJIExecuteResultCallback()
        {
            @Override
            public void onResult(DJIError djiError)
            {
                if (!DJI.Success(djiError.errorCode))