summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2016-10-11 08:29:11 +0200
committerMarcus Meissner <marcus@jet.franken.de>2016-10-11 08:29:11 +0200
commit45fe36273089b17e3582f9bafd51fe0799d38210 (patch)
tree4219af9fd7d1f35f52e24f992e4e7f5a51daa2e8 /examples
parentb4c961bf1350f252f41afd20cc0f10ee5a412a75 (diff)
downloadlibgphoto2-45fe36273089b17e3582f9bafd51fe0799d38210.tar.gz
add event polling / tethering to sample photobooth
Diffstat (limited to 'examples')
-rw-r--r--examples/sample-photobooth.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/examples/sample-photobooth.c b/examples/sample-photobooth.c
index c96378ab8..76a7cb72b 100644
--- a/examples/sample-photobooth.c
+++ b/examples/sample-photobooth.c
@@ -96,12 +96,18 @@ main(int argc, char **argv) {
CameraFile *file;
char output_file[32];
+ /*
+ * Capture a full picture on demand. Use unique filenames.
+ */
if (capture_now) {
capture_now = 0;
sprintf(output_file, "image-%03d.jpg", capturecnt++);
capture_to_file(camera, context, output_file);
}
+ /*
+ * Capture a preview on every loop. Save as preview.jpg.
+ */
retval = gp_file_new(&file);
if (retval != GP_OK) {
fprintf(stderr,"gp_file_new: %d\n", retval);
@@ -119,6 +125,61 @@ main(int argc, char **argv) {
exit(1);
}
gp_file_unref(file);
+ /*
+ * Check and drain the event queue.
+ * Download newly captured images.
+ * Ignore the rest events.
+ */
+ while (1) {
+ CameraEventType evttype;
+ CameraFilePath *path;
+ void *evtdata;
+ int fd;
+
+ evtdata = NULL;
+ retval = gp_camera_wait_for_event (camera, 1, &evttype, &evtdata, context);
+ if (retval != GP_OK) break;
+ switch (evttype) {
+ case GP_EVENT_FILE_ADDED:
+ path = (CameraFilePath*)evtdata;
+ printf("File added on the camera: %s/%s\n", path->folder, path->name);
+
+ sprintf(output_file, "image-%03d.jpg", capturecnt++);
+
+ fd = open(output_file, O_CREAT | O_WRONLY, 0644);
+ retval = gp_file_new_from_fd(&file, fd);
+ retval = gp_camera_file_get(camera, path->folder, path->name,
+ GP_FILE_TYPE_NORMAL, file, context);
+
+ retval = gp_camera_file_delete(camera, path->folder, path->name, context);
+ gp_file_free(file);
+ free (evtdata);
+ break;
+ case GP_EVENT_FOLDER_ADDED:
+ path = (CameraFilePath*)evtdata;
+ printf("Folder added on camera: %s / %s\n", path->folder, path->name);
+ free (evtdata);
+ break;
+ case GP_EVENT_CAPTURE_COMPLETE:
+ printf("Capture Complete.\n");
+ break;
+ case GP_EVENT_TIMEOUT:
+ break;
+ case GP_EVENT_UNKNOWN:
+ if (evtdata) {
+ printf("Unknown event: %s.\n", (char*)evtdata);
+ free (evtdata);
+ } else {
+ printf("Unknown event.\n");
+ }
+ break;
+ default:
+ printf("Type %d?\n", evttype);
+ break;
+ }
+ if (evttype == GP_EVENT_TIMEOUT)
+ break;
+ }
}
gp_camera_exit(camera, context);
return 0;