Mode photo capture or video record#

The camera can operate in photo captue mode or in video recording mode. A setting is dedicated to the selection of this mode.

Photos can be taken only in photo capture mode. And videos can be recorded only in video recording mode.

Camera 1#

Sample code to monitor camera mode setting:

/// Keep reference on MainCamera peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera>?

/// Monitors and prints camera mode.
func monitorCameraMode(drone: Drone) {
    cameraRef = drone.getPeripheral(Peripherals.mainCamera) { camera in
        // called on main thread when the camera peripheral changes
        if let camera = camera {
            if camera.modeSetting.supportedModes.isEmpty {
                // setting value is not relevant if there is no supported value
                print("No supported value")
            } else {
                // get setting value
                let mode = camera.modeSetting.mode
                print("Current mode is: \(mode)")
            }
        }
    }
}

Example of output:

Current mode is: photo

Sample code to modify camera mode:

/// Sets camera mode.
func setCameraMode(drone: Drone, mode: CameraMode) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera) {
        // set setting value
        camera.modeSetting.mode = mode
    }
}

Camera 2#

Camera mode is configured with parameter Camera2Params.mode.

Sample code to monitor camera mode:

/// Keep reference on MainCamera2 peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera2>?

/// Monitors and prints camera mode.
func monitorCameraMode(drone: Drone) {
    cameraRef = drone.getPeripheral(Peripherals.mainCamera2) { camera in
        // called on main thread when the camera peripheral changes
        if let camera = camera {
            // get configuration parameter
            if let configParam = camera.config[Camera2Params.mode] {
                if configParam.currentSupportedValues.isEmpty {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    print("No supported value in current configuration")
                } else {
                    // get parameter value
                    let mode = configParam.value
                    print("Current mode is: \(mode)")
                }
            }
        }
    }
}

Example of output:

Current mode is: recording

Sample code to modify camera mode:

/// Sets camera mode.
func setCameraMode(drone: Drone, mode: Camera2Mode) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
        // create configuration editor, starting from current configuration
        let editor = camera.config.edit(fromScratch: false)
        // retrieve configuration parameter
        if let configParam = editor[Camera2Params.mode] {
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = mode
            // complete configuration, by setting missing parameters values
            editor.autoComplete()
            // send new configuration to drone
            editor.commit()
        }
    }
}

Trying to change the parameter value to an unsupported value has no effect. Values supported by the camera are provided by the parameter field configParam.overallSupportedValues.