Exposure compensation#

Camera 1#

Sample code to monitor exposure compensation:

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

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

Example of output:

Current value is: evMinus3_00

Sample code to modify exposure compensation:

/// Sets exposure compensation.
func setExposureCompensationValue(drone: Drone, compensation: CameraEvCompensation) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera) {
        // set setting value
        camera.exposureCompensationSetting.value = compensation
    }
}

Trying to change the setting value to an unsupported value has no effect. Values supported by the camera are provided by CameraExposureCompensationSetting.supportedModes.

Camera 2#

Exposure compensation is configured with parameter Camera2Params.exposureCompensation.

Sample code to monitor exposure compensation:

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

/// Monitors and prints exposure compensation.
func monitorExposureCompensation(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.exposureCompensation] {
                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 exposureCompensationValue = configParam.value
                    print("Current value is: \(exposureCompensationValue)")
                }
            }
        }
    }
}

Example of output:

Current value is: evMinus3_00

Sample code to modify exposure compensation:

/// Sets exposure compensation.
func setExposureCompensation(drone: Drone, compensation: Camera2EvCompensation) {
    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.exposureCompensation] {
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = compensation
            // 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.