Exposure lock#
Camera 1#
Sample code to monitor exposure lock:
/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null
/** Monitors and prints exposure lock. */
fun monitorExposureLock(drone: Drone) {
cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
// called on main thread when the camera peripheral changes
camera?.run {
exposureLock()?.apply {
when(mode()) {
CameraExposureLock.Mode.NONE -> print("Exposure unlocked")
CameraExposureLock.Mode.CURRENT_VALUES -> print("Exposure locked")
CameraExposureLock.Mode.REGION -> {
val x = regionCenterX
val y = regionCenterY
val w = regionWidth
val h = regionHeight
println("Exposure locked on region $x $y $w $h")
}
}
} ?: println("Exposure lock not available")
}
}
}
Example of output:
Exposure unlocked
Exposure lock updating: false
Sample code to lock and unlock exposure:
/** Locks exposure on current values. */
fun lockExposure(drone: Drone) {
drone.getPeripheral(MainCamera::class.java)?.run {
exposureLock()?.lockCurrentValues()
}
}
/** Locks exposure on a region. */
fun lockExposureOnRegion(drone: Drone, centerX: Double, centerY: Double) {
drone.getPeripheral(MainCamera::class.java)?.run {
exposureLock()?.lockOnRegion(centerX, centerY)
}
}
/** Unlocks exposure. */
fun unlockExposure(drone: Drone) {
drone.getPeripheral(MainCamera::class.java)?.run {
exposureLock()?.unlock()
}
}
Camera 2#
Exposure lock is controlled with sub-component Camera.ExposureLock
.
Sample code to monitor exposure lock:
/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null
/** `MainCamera` peripheral. This is used to know when peripheral appears. */
private var mainCamera: Camera? = null
/** Monitors and prints exposure lock. */
fun monitorExposureLock(drone: Drone) {
cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
// called on main thread when the camera peripheral changes
camera?.run {
// register sub-component listener, only when camera peripheral appears
if (mainCamera == null) {
// get notified every time exposure lock sub-component changes
camera.component<Camera.ExposureLock> { exposureLock ->
exposureLock?.run {
println("Exposure lock mode: $mode")
println("Exposure lock applying: $applying")
}
}
}
}
mainCamera = camera
}
}
Example of output:
Exposure lock mode: UNLOCKED
Exposure lock applying: false
Sample code to lock and unlock exposure:
/** Locks exposure on full frame. */
fun lockExposure(drone: Drone) {
drone.getPeripheral(MainCamera::class.java)?.run {
component<Camera.ExposureLock>()?.lockOnFullFrame()
}
}
/** Locks exposure on a region. */
fun lockExposureOnRegion(drone: Drone, centerX: Double, centerY: Double) {
drone.getPeripheral(MainCamera::class.java)?.run {
component<Camera.ExposureLock>()?.lockOnRegion(centerX, centerY)
}
}
/** Unlocks exposure. */
fun unlockExposure(drone: Drone) {
drone.getPeripheral(MainCamera::class.java)?.run {
component<Camera.ExposureLock>()?.unlock()
}
}