summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/focus.c60
-rw-r--r--examples/preview.c16
-rw-r--r--examples/sample-justfocus.c8
-rw-r--r--examples/samples.h3
4 files changed, 82 insertions, 5 deletions
diff --git a/examples/focus.c b/examples/focus.c
index 077b7deeb..d7ae3f6fa 100644
--- a/examples/focus.c
+++ b/examples/focus.c
@@ -22,7 +22,61 @@ _lookup_widget(CameraWidget*widget, const char *key, CameraWidget **child) {
/* calls the Nikon DSLR or Canon DSLR autofocus method. */
int
-camera_auto_focus(Camera *camera, GPContext *context) {
+camera_eosviewfinder(Camera *camera, GPContext *context, int onoff) {
+ CameraWidget *widget = NULL, *child = NULL;
+ CameraWidgetType type;
+ int ret,val;
+
+ ret = gp_camera_get_config (camera, &widget, context);
+ if (ret < GP_OK) {
+ fprintf (stderr, "camera_get_config failed: %d\n", ret);
+ return ret;
+ }
+ ret = _lookup_widget (widget, "eosviewfinder", &child);
+ if (ret < GP_OK) {
+ fprintf (stderr, "lookup 'eosviewfinder' failed: %d\n", ret);
+ goto out;
+ }
+
+ /* check that this is a toggle */
+ ret = gp_widget_get_type (child, &type);
+ if (ret < GP_OK) {
+ fprintf (stderr, "widget get type failed: %d\n", ret);
+ goto out;
+ }
+ switch (type) {
+ case GP_WIDGET_TOGGLE:
+ break;
+ default:
+ fprintf (stderr, "widget has bad type %d\n", type);
+ ret = GP_ERROR_BAD_PARAMETERS;
+ goto out;
+ }
+
+ ret = gp_widget_get_value (child, &val);
+ if (ret < GP_OK) {
+ fprintf (stderr, "could not get widget value: %d\n", ret);
+ goto out;
+ }
+ val = onoff;
+ ret = gp_widget_set_value (child, &val);
+ if (ret < GP_OK) {
+ fprintf (stderr, "could not set widget value to 1: %d\n", ret);
+ goto out;
+ }
+
+ ret = gp_camera_set_config (camera, widget, context);
+ if (ret < GP_OK) {
+ fprintf (stderr, "could not set config tree to eosviewfinder: %d\n", ret);
+ goto out;
+ }
+out:
+ gp_widget_free (widget);
+ return ret;
+}
+
+int
+camera_auto_focus(Camera *camera, GPContext *context, int onoff) {
CameraWidget *widget = NULL, *child = NULL;
CameraWidgetType type;
int ret,val;
@@ -58,7 +112,9 @@ camera_auto_focus(Camera *camera, GPContext *context) {
fprintf (stderr, "could not get widget value: %d\n", ret);
goto out;
}
- val++;
+
+ val = onoff;
+
ret = gp_widget_set_value (child, &val);
if (ret < GP_OK) {
fprintf (stderr, "could not set widget value to 1: %d\n", ret);
diff --git a/examples/preview.c b/examples/preview.c
index 2af5c6002..094df21f7 100644
--- a/examples/preview.c
+++ b/examples/preview.c
@@ -138,6 +138,11 @@ main(int argc, char **argv) {
exit (1);
}
canon_enable_capture(canon, TRUE, canoncontext);
+ retval = camera_eosviewfinder(canon,canoncontext,1);
+ if (retval != GP_OK) {
+ fprintf(stderr,"camera_eosviewfinder(1): %d\n", retval);
+ exit(1);
+ }
/*set_capturetarget(canon, canoncontext);*/
printf("Taking 100 previews and saving them to snapshot-XXX.jpg ...\n");
for (i=0;i<100;i++) {
@@ -153,7 +158,9 @@ main(int argc, char **argv) {
/* autofocus every 10 shots */
if (i%10 == 9) {
- camera_auto_focus (canon, canoncontext);
+ camera_auto_focus (canon, canoncontext, 1);
+ /* FIXME: wait a bit and/or poll events ? */
+ camera_auto_focus (canon, canoncontext, 0);
} else {
camera_manual_focus (canon, (i/10-5)/2, canoncontext);
}
@@ -183,6 +190,13 @@ main(int argc, char **argv) {
capture_to_file(canon, canoncontext, output_file);
*/
}
+ retval = camera_eosviewfinder(canon,canoncontext,0);
+ if (retval != GP_OK) {
+ fprintf(stderr,"camera_eosviewfinder(0): %d\n", retval);
+ exit(1);
+ }
+
+ sleep(10);
gp_camera_exit(canon, canoncontext);
return 0;
}
diff --git a/examples/sample-justfocus.c b/examples/sample-justfocus.c
index 8ad502235..a3a80c9a9 100644
--- a/examples/sample-justfocus.c
+++ b/examples/sample-justfocus.c
@@ -44,7 +44,7 @@ int main(int argc, char *argv[]){
if(argc == 1)
{
- retval = camera_auto_focus(camera, context);
+ retval = camera_auto_focus(camera, context, 1);
if(retval != GP_OK) {
printf("Error: %s\n", gp_result_as_string(retval));
return 1;
@@ -63,6 +63,12 @@ int main(int argc, char *argv[]){
retval = gp_camera_wait_for_event (camera, 10, &evttype, &evtdata, context);
} while ((retval == GP_OK) && (evttype != GP_EVENT_TIMEOUT));
+ retval = camera_auto_focus(camera, context, 0);
+ if(retval != GP_OK) {
+ printf("Error: %s\n", gp_result_as_string(retval));
+ return 1;
+ }
+
gp_camera_exit(camera, context);
return 0;
}
diff --git a/examples/samples.h b/examples/samples.h
index 69307e525..9132c6cb3 100644
--- a/examples/samples.h
+++ b/examples/samples.h
@@ -10,6 +10,7 @@ extern int get_config_value_string (Camera *, const char *, char **, GPContext *
extern int set_config_value_string (Camera *, const char *, const char *, GPContext *);
int canon_enable_capture (Camera *camera, int onoff, GPContext *context);
-extern int camera_auto_focus (Camera *list, GPContext *context);
+extern int camera_auto_focus (Camera *list, GPContext *context, int onoff);
+extern int camera_eosviewfinder (Camera *list, GPContext *context, int onoff);
extern int camera_manual_focus (Camera *list, int tgt, GPContext *context);
#endif