Skip to content

Commit 6ab7d45

Browse files
Add listPhotos example
1 parent 6c499b1 commit 6ab7d45

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

examples/java-client/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ configurations {
99
checkstyleClasspath
1010
}
1111

12-
mainClassName = "io.mavsdk.example.TakeoffAndLand"
13-
14-
sourceCompatibility = JavaVersion.VERSION_1_8
15-
targetCompatibility = JavaVersion.VERSION_1_8
16-
1712
task takeoffAndLand(dependsOn: 'classes', type: JavaExec) {
1813
main = "io.mavsdk.example.TakeoffAndLand"
1914
classpath = sourceSets.main.runtimeClasspath
@@ -44,6 +39,11 @@ task runDownloadLastLog(dependsOn: 'classes', type: JavaExec) {
4439
classpath = sourceSets.main.runtimeClasspath
4540
}
4641

42+
task listPhotos(dependsOn: 'classes', type: JavaExec) {
43+
main = "io.mavsdk.example.ListPhotos"
44+
classpath = sourceSets.main.runtimeClasspath
45+
}
46+
4747
task checkstyle(type: Checkstyle) {
4848
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
4949
source 'src'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.mavsdk.example;
2+
3+
import io.mavsdk.System;
4+
import io.mavsdk.camera.Camera;
5+
import io.reactivex.Completable;
6+
import io.reactivex.Single;
7+
8+
import java.util.List;
9+
import java.util.concurrent.CountDownLatch;
10+
import java.util.concurrent.TimeUnit;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
14+
public class ListPhotos {
15+
private static final Logger logger = LoggerFactory.getLogger(ListPhotos.class);
16+
17+
public static void main(String[] args) {
18+
logger.debug("Starting example: taking and listing photos...");
19+
20+
System drone = new System();
21+
CountDownLatch latch = new CountDownLatch(1);
22+
23+
// Completable trying to take 50 pictures (stopping in case of error)
24+
Completable takePhotoCompletable
25+
= drone.getCamera().takePhoto()
26+
.doOnComplete(() -> logger.debug("Picture taken"))
27+
.doOnError(throwable -> logger.error("Error: " + throwable.getMessage()))
28+
.onErrorComplete()
29+
.delay(1, TimeUnit.SECONDS)
30+
.repeat(50);
31+
32+
// Single getting a list of all the pictures available on the camera
33+
Single<List<Camera.CaptureInfo>> photosList
34+
= drone.getCamera().listPhotos(Camera.PhotosRange.ALL)
35+
.doOnSuccess(captureInfos -> logger.debug("Got " + captureInfos.size() + " photos"))
36+
.doOnError(throwable -> logger.error("Error: " + throwable.getMessage()));
37+
38+
// Run them one after the other
39+
takePhotoCompletable.andThen(photosList)
40+
.subscribe((captureInfos, throwable) -> latch.countDown());
41+
42+
try {
43+
latch.await();
44+
} catch (InterruptedException ignored) {
45+
// This is expected
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)