Photo state#

The photo state provides information on current state of photo capture function. It also indicates information such as number of photo taken in session (useful for burst and hyperlapse) and saved media identifiers.

Camera 1#

Sample code to monitor photo capture state:

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

/** Monitors and prints photo capture state. */
fun monitorPhotoCaptureState(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        // called on main thread when the camera peripheral changes
        camera?.photoState()?.run {
            when (get()) {
                CameraPhoto.State.FunctionState.UNAVAILABLE ->
                    println("Photo capture not available at present")

                CameraPhoto.State.FunctionState.STOPPED ->
                    println("Photo capture stopped")

                CameraPhoto.State.FunctionState.STARTED ->
                    println("Photo capture started, photoCount: ${photoCount()}")

                CameraPhoto.State.FunctionState.STOPPING ->
                    println("Photo capture stopping")

                CameraPhoto.State.FunctionState.ERROR_INTERNAL,
                CameraPhoto.State.FunctionState.ERROR_INSUFFICIENT_STORAGE ->
                    println("Photo capture error")
            }
            latestMediaId()?.let { mediaId ->
                print("Identifier of latest saved media: $mediaId")
            }
        }
    }
}

Example of output during photo capture:

Photo capture stopped
Photo capture started, photoCount: 0
Photo capture started, photoCount: 1
Photo capture stopped
Identifier of latest saved media: 10000559

Camera 2#

Photo capture state is monitored with sub-component Camera.PhotoCapture.

Sample code to monitor photo capture state:

/** 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 photo capture state. */
fun monitorPhotoCaptureState(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 photo capture sub-component changes
                camera.component<Camera.PhotoCapture> { photoCapture ->
                    photoCapture?.apply {
                        when (val state = state) {
                            is Camera.PhotoCapture.State.Starting ->
                                println("Photo capture starting")

                            is Camera.PhotoCapture.State.Started ->
                                println("Photo capture started ${state.photoCount} ${state.mediaStorage} ${state.startTime}")

                            is Camera.PhotoCapture.State.Stopping -> {
                                println("Photo capture stopping ${state.reason}")
                                state.savedMediaId?.let { mediaId ->
                                    println("Identifier of saved media: $mediaId")
                                }
                            }

                            is Camera.PhotoCapture.State.Stopped -> {
                                println("Photo capture stopped")
                                state.latestSavedMediaId?.let { mediaId ->
                                    println("Identifier of latest saved media: $mediaId")
                                }
                            }
                        }
                    } ?: println("Photo capture not available at present")
                }
            }
        }
        mainCamera = camera
    }
}

Example of output during photo capture:

Photo capture stopped
Photo capture starting
Photo capture started 0 INTERNAL 1613658260327
Photo capture stopping CaptureDone
Identifier of saved media: 10000151
Photo capture stopped
Identifier of latest saved media: 10000151