White balance temperature#

In white balance mode custom, the custom temperature is defined with a specific setting.

Camera 1#

Sample code to monitor white balance temperature:

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

/** Monitors and prints white balance temperature. */
fun monitorWhiteBalanceTemperature(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        // called on main thread when the camera peripheral changes
        camera?.whiteBalance()?.run {
            if (supportedCustomTemperatures().isEmpty()) {
                // setting value is not relevant if there is no supported value
                println("No supported value")
            } else {
                // get setting value
                val temperature = customTemperature()
                println("Current value: $temperature")
                // updating flag
                println("Updating: $isUpdating")
            }
        }
    }
}

Example of output:

Current value is: K_1500
Updating: false

Sample code to modify white balance temperature:

/** Sets white balance temperature. */
fun setWhiteBalanceTemperature(drone: Drone, temperature: CameraWhiteBalance.Temperature) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // set setting value
        whiteBalance().setCustomTemperature(temperature)
    }
}

Trying to change the setting value to an unsupported value has no effect. Values supported by the camera are provided by CameraWhiteBalance.Setting.supporteCustomTemperature().

Camera 2#

White balance temperature is configured with parameter Camera.Config.WHITE_BALANCE_TEMPERATURE.

Sample code to monitor white balance temperature:

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

/** Monitors and prints white balance temperature. */
fun monitorWhiteBalanceTemperature(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        camera?.run {
            // get configuration parameter
            config[Camera.Config.WHITE_BALANCE_TEMPERATURE].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 value is: K_1500

Sample code to modify white balance temperature:

/** Sets white balance temperature. */
fun setWhiteBalanceTemperature(drone: Drone, temperature: Camera.WhiteBalanceTemperature) {
    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.WHITE_BALANCE_TEMPERATURE].let { configParam ->
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = temperature
            // 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).