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:
/// Keep reference on MainCamera peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera>?
/// Monitors and prints white balance temperature.
func monitorWhiteBalanceTemperature(drone: Drone) {
cameraRef = drone.getPeripheral(Peripherals.mainCamera) { camera in
// called on main thread when the camera peripheral changes
if let camera = camera {
if camera.whiteBalanceSettings.supporteCustomTemperature.isEmpty {
// setting value is not relevant if there is no supported value
print("No supported value")
} else {
// get setting value
let whiteBalanceTemperature = camera.whiteBalanceSettings.customTemperature
print("Current value is: \(whiteBalanceTemperature)")
}
}
}
}
Example of output:
Current value is: k1500
Sample code to modify white balance temperature:
/// Sets white balance temperature.
func setWhiteBalanceTemperature(drone: Drone, temperature: CameraWhiteBalanceTemerature) {
if let camera = drone.getPeripheral(Peripherals.mainCamera) {
// set setting value
camera.whiteBalance.temperature = temperature
}
}
Trying to change the setting value to an unsupported value has no effect.
Values supported by the camera are provided by CameraWhiteBalanceSettings.supporteCustomTemperature
.
Camera 2#
Sample code to monitor white balance temperature:
/// Keep reference on MainCamera2 peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera2>?
/// Monitors and prints white balance temperature.
func monitorWhiteBalanceTemperature(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.whiteBalanceTemperature] {
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 whiteBalanceTemperature = configParam.value
print("Current value is: \(whiteBalanceTemperature)")
}
}
}
}
}
Example of output:
Current value is: k1500
Sample code to modify white balance temperature:
/// Sets white balance temperature.
func setWhiteBalanceTemperature(camera: MainCamera2, temperature: Camera2WhiteBalanceTemperature) {
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.whiteBalanceTemperature] {
// 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 provided by the parameter field configParam.overallSupportedValues
.