Photo start and stop#
Camera 1#
When can I start or stop photo capture ?#
Photo capture can be started only when all of the the following conditions are met:
camera is active:
camera.isActive == true
camera mode is photo:
camera.mode().value == Camera.Mode.PHOTO
photo state is stopped:
camera.photoState().get() == CameraPhoto.State.FunctionState.STOPPED
Photo capture can be stopped when the following condition is true:
photo state is started:
camera.photoState().get() == CameraPhoto.State.FunctionState.STARTED
The Camera API provides helper methods telling whether photo capture can be started are stopped:
camera.canStartPhotoCapture()
: tells whether photo capture can be startedcamera.canStopPhotoCapture()
: tells whether photo capture can be stopped
Sample code to monitor whether photo capture can be started or stopped :
/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null
/** Monitors and prints whether photo capture can be started or stopped. */
fun monitorCanStartStopPhotoCapture(drone: Drone) {
cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
// called on main thread when the camera peripheral changes
camera?.run {
when {
canStartPhotoCapture() ->
println("Photo capture can be started")
canStopPhotoCapture() ->
println("Photo capture can be stopped")
else ->
println("Photo capture can't be started or stopped")
}
}
}
}
How to start or stop photo capture ?#
Sample code to start and stop photo capture:
/** Starts or stops photo capture. */
fun toggleStartStopPhotoCapture(drone: Drone) {
drone.getPeripheral(MainCamera::class.java)?.run {
when {
// photo capture can be started
canStartPhotoCapture() -> startPhotoCapture()
// photo capture can be stopped
canStopPhotoCapture() -> stopPhotoCapture()
// photo capture can't be started or stopped
else -> println("Photo capture can't be started or stopped")
}
}
}
Camera 2#
When can I start or stop photo capture ?#
Photo capture can be started only when all of the following conditions are met:
camera is active:
camera.active == true
camera mode is photo:
camera.config[Camera.Config.MODE].value == Camera.Mode.PHOTO
photo capture state is stopped:
camera.component<Camera.PhotoCapture>()?.state is Camera.PhotoCapture.State.Stopped
Photo capture can be stopped when the following condition is true:
photo capture state is started or starting:
camera.component<Camera.PhotoCapture>()?.state is Camera.PhotoCapture.State.Starting
OR
camera.component<Camera.PhotoCapture>()?.state is Camera.PhotoCapture.State.Started
Sample code to monitor whether photo capture can be started or stopped :
/** 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 whether photo capture can be started or stopped. */
fun monitorCanStartStopPhotoCapture(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 ->
when (photoCapture?.state) {
Camera.PhotoCapture.State.Starting,
is Camera.PhotoCapture.State.Started ->
println("Photo capture can be stopped")
is Camera.PhotoCapture.State.Stopped ->
println("Photo capture can be started")
else ->
println("Photo capture can't be started or stopped")
}
}
}
}
mainCamera = camera
}
}
How to start or stop photo capture ?#
Sample code to start and stop photo capture:
/** Starts or stops photo capture. */
fun toggleStartStopPhotoCapture(drone: Drone) {
drone.getPeripheral(MainCamera::class.java)?.run {
component<Camera.PhotoCapture>()?.apply {
when (state) {
// photo capture can be stopped
Camera.PhotoCapture.State.Starting,
is Camera.PhotoCapture.State.Started -> start()
// photo capture can be started
is Camera.PhotoCapture.State.Stopped -> stop()
// photo capture state don't allow to start or stop
else -> println("Photo capture can't be started or stopped")
}
} ?: run {
// photo capture component not available at present
println("Photo capture not available")
}
}
}