diff options
author | Marcus Meissner <marcus@jet.franken.de> | 2008-09-26 07:24:47 +0000 |
---|---|---|
committer | Marcus Meissner <marcus@jet.franken.de> | 2008-09-26 07:24:47 +0000 |
commit | bec34902c81ae6371c7fdda78baa1da4edcc0f01 (patch) | |
tree | bb230451c9fcd12fb0bad500c1e530c42cd02a2e /examples | |
parent | 254e1d3d48bf2227ebcdc45aeea6253cf3a88555 (diff) | |
download | libgphoto2-bec34902c81ae6371c7fdda78baa1da4edcc0f01.tar.gz |
merged comments
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@11351 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'examples')
-rw-r--r-- | examples/autodetect.c | 18 | ||||
-rw-r--r-- | examples/sample-autodetect.c | 13 |
2 files changed, 25 insertions, 6 deletions
diff --git a/examples/autodetect.c b/examples/autodetect.c index 0cc93c920..4814aabad 100644 --- a/examples/autodetect.c +++ b/examples/autodetect.c @@ -9,7 +9,10 @@ static GPPortInfoList *portinfolist = NULL; static CameraAbilitiesList *abilities = NULL; /* - * This detects all currently attached cameras. + * This detects all currently attached cameras and returns + * them in a list. It avoids the generic usb: entry. + * + * This function does not open nor initialize the cameras yet. */ int sample_autodetect (CameraList *list, GPContext *context) { @@ -19,6 +22,7 @@ sample_autodetect (CameraList *list, GPContext *context) { ret = gp_list_new (&xlist); if (ret < GP_OK) goto out; if (!portinfolist) { + /* Load all the port drivers we have... */ ret = gp_port_info_list_new (&portinfolist); if (ret < GP_OK) goto out; ret = gp_port_info_list_load (portinfolist); @@ -26,13 +30,17 @@ sample_autodetect (CameraList *list, GPContext *context) { ret = gp_port_info_list_count (portinfolist); if (ret < 0) goto out; } + /* Load all the camera drivers we have... */ ret = gp_abilities_list_new (&abilities); if (ret < GP_OK) goto out; ret = gp_abilities_list_load (abilities, context); if (ret < GP_OK) goto out; + + /* ... and autodetect the currently attached cameras. */ ret = gp_abilities_list_detect (abilities, portinfolist, xlist, context); if (ret < GP_OK) goto out; + /* Filter out the "usb:" entry */ ret = gp_list_count (xlist); if (ret < GP_OK) goto out; for (i=0;i<ret;i++) { @@ -48,6 +56,9 @@ out: return gp_list_count(list); } +/* + * This function opens a camera depending on the specified model and port. + */ int sample_open_camera (Camera ** camera, const char *model, const char *port) { int ret, m, p; @@ -57,7 +68,7 @@ sample_open_camera (Camera ** camera, const char *model, const char *port) { ret = gp_camera_new (camera); if (ret < GP_OK) return ret; - /* First the model / driver */ + /* First lookup the model / driver */ m = gp_abilities_list_lookup_model (abilities, model); if (m < GP_OK) return ret; ret = gp_abilities_list_get_abilities (abilities, m, &a); @@ -65,8 +76,7 @@ sample_open_camera (Camera ** camera, const char *model, const char *port) { ret = gp_camera_set_abilities (*camera, a); if (ret < GP_OK) return ret; - /* Then associate with a port */ - + /* Then associate the camera with the specified port */ p = gp_port_info_list_lookup_path (portinfolist, port); if (ret < GP_OK) return ret; switch (p) { diff --git a/examples/sample-autodetect.c b/examples/sample-autodetect.c index 66e57f25d..a2f53abf9 100644 --- a/examples/sample-autodetect.c +++ b/examples/sample-autodetect.c @@ -1,11 +1,16 @@ #include <stdio.h> #include <string.h> - #include <gphoto2/gphoto2-camera.h> #include "samples.h" +/* Sample autodetection program. + * + * This program can autodetect multiple cameras and then calls a + * simple function in each of them (summary). + */ + int main(int argc, char **argv) { CameraList *list; Camera **cams; @@ -13,11 +18,14 @@ int main(int argc, char **argv) { const char *name, *value; GPContext *context; - context = sample_create_context (); + context = sample_create_context (); /* see context.c */ + /* Detect all the cameras that can be autodetected... */ ret = gp_list_new (&list); if (ret < GP_OK) return 1; count = sample_autodetect (list, context); + + /* Now open all cameras we autodected for usage */ printf("Number of cameras: %d\n", count); cams = calloc (sizeof (Camera*),count); for (i = 0; i < count; i++) { @@ -26,6 +34,7 @@ int main(int argc, char **argv) { ret = sample_open_camera (&cams[i], name, value); if (ret < GP_OK) fprintf(stderr,"Camera %s on port %s failed to open\n", name, value); } + /* Now call a simple function in each of those cameras. */ for (i = 0; i < count; i++) { CameraText text; ret = gp_camera_get_summary (cams[i], &text, context); |