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:

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null

/** Monitors and prints camera mode. */
fun monitorCameraMode(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        // called on main thread when the camera peripheral changes
        camera?.mode()?.run {
            if (availableValues.isEmpty()) {
                // setting value is not relevant if there is no available value
                println("No available value")
            } else {
                // setting value
                println("Current mode: $value")
                // updating flag
                println("Updating: $isUpdating")
            }
        }
    }
}

Example of output:

Current mode: PHOTO
Updating: false

Sample code to modify camera mode:

/** Sets photo mode. */
fun setCameraMode(drone: Drone, mode: Camera.Mode) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // set setting value
        mode().value = mode
    }
}

Camera 2#

Sample code to monitor camera mode:

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null

/** Monitors and prints camera mode. */
fun monitorCameraMode(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        // called on main thread when the camera peripheral changes
        camera?.run {
            // get configuration parameter
            config[Camera.Config.MODE].run {
                if (supportedValues(onlyCurrent = true).isEmpty()) {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    println("No supported value in current configuration")
                } else {
                    println("Current value: $value")
                }
            }
        }
    }
}

Example of output:

Current mode is: PHOTO

Sample code to modify camera mode:

/** Sets camera mode. */
fun setCameraMode(drone: Drone, mode: Camera.Mode) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // create configuration editor, starting from current configuration
        val editor = config.edit(fromScratch = false)
        // get configuration parameter
        editor[Camera.Config.MODE].let { configParam ->
            // 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 retrieved by calling configParam.supportedValues(onlyCurrent = false).