Exposure compensation#

Camera 1#

Sample code to monitor exposure compensation:

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

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

Example of output:

Current value: EV_MINUS_3

Sample code to modify exposure compensation:

/** Sets exposure compensation. */
fun setExposureCompensationValue(drone: Drone, compensation: CameraEvCompensation) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // set setting value
        exposureCompensation().value = compensation
    }
}

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

Camera 2#

Audio recording mode is configured with parameter Camera.Config.EXPOSURE_COMPENSATION.

Sample code to monitor exposure compensation:

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

/** Monitors and prints exposure compensation. */
fun monitorExposureCompensation(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.EXPOSURE_COMPENSATION].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 {
                    // print parameter value
                    println("Current value: $value")
                }
            }
        }
    }
}

Example of output:

Current value: EV_MINUS_3

Sample code to modify exposure compensation:

/** Sets exposure compensation. */
fun setExposureCompensation(drone: Drone, mode: Camera.ExposureValue) {
    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.EXPOSURE_COMPENSATION].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).