int getWidget(CameraWidget ** widget, CameraWidget ** child, const char * setting) { CameraWidgetType type; int 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, setting, child); if (ret < GP_OK || child == NULL) { fprintf (stderr, "l lookup widget %s failed: %d\n", setting, ret); gp_widget_free (*widget); return ret; } /* This type check is optional, if you know what type the label * has already. If you are not sure, better check. */ ret = gp_widget_get_type (*child, &type); if (ret < GP_OK) { fprintf (stderr, "l widget get type failed: %d\n", ret); gp_widget_free (*widget); return ret; } return GP_OK; }
int set_config_value_string (Camera *camera, const char *key, char *val, GPContext *context) { CameraWidget *widget = NULL, *child = NULL; CameraWidgetType type; int ret; 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, key, &child); if (ret < GP_OK) { fprintf (stderr, "lookup widget failed: %d\n", ret); goto out; } /* This type check is optional, if you know what type the label * has already. If you are not sure, better check. */ 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_MENU: case GP_WIDGET_RADIO: case GP_WIDGET_TEXT: break; default: fprintf (stderr, "widget has bad type %d\n", type); ret = GP_ERROR_BAD_PARAMETERS; goto out; } /* This is the actual set call. Note that we keep * ownership of the string and have to free it if necessary. */ ret = gp_widget_set_value (child, val); if (ret < GP_OK) { fprintf (stderr, "could not set widget value: %d\n", ret); goto out; } /* This stores it on the camera again */ ret = gp_camera_set_config (camera, widget, context); if (ret < GP_OK) { fprintf (stderr, "camera_set_config failed: %d\n", ret); return ret; } 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; 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, "autofocusdrive", &child); if (ret < GP_OK) { fprintf (stderr, "lookup 'autofocusdrive' 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 autofocus: %d\n", ret); goto out; } out: gp_widget_free (widget); return ret; }
int set_config_value_float (Camera *camera, const char *key, float *value, GPContext *context) { CameraWidget *widget = NULL, *child = NULL; CameraWidgetType type; int ret; printf("Hai sa vedem ce e busit dintre camera si context %p %p\n",camera,context); 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, key, &child); if (ret < GP_OK) { printf("name: %s",key); fprintf (stderr, "lookup widget failed: %d\n", ret); goto out; } /* This type check is optional, if you know what type the label * has already. If you are not sure, better check. */ 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_RANGE: break; default: fprintf (stderr, "widget has bad type %d\n", type); ret = GP_ERROR_BAD_PARAMETERS; goto out; } ret = gp_widget_set_value (child, value); if (ret < GP_OK) { fprintf (stderr, "could not set widget value: %d\n", ret); goto out; } /* This stores it on the camera again */ ret = gp_camera_set_config (camera, widget, context); if (ret < GP_OK) { fprintf (stderr, "camera_set_config failed: %d\n", ret); return ret; } out: gp_widget_free (widget); return ret; }
int get_config_value_string (Camera *camera, const char *key, char **str, GPContext *context) { CameraWidget *widget = NULL, *child = NULL; CameraWidgetType type; int ret; char *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, key, &child); if (ret < GP_OK) { fprintf (stderr, "lookup widget failed: %d\n", ret); goto out; } /* This type check is optional, if you know what type the label * has already. If you are not sure, better check. */ 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_MENU: case GP_WIDGET_RADIO: case GP_WIDGET_TEXT: break; default: fprintf (stderr, "widget has bad type %d\n", type); ret = GP_ERROR_BAD_PARAMETERS; goto out; } /* This is the actual query call. Note that we just * a pointer reference to the string, not a copy... */ ret = gp_widget_get_value (child, &val); if (ret < GP_OK) { fprintf (stderr, "could not query widget value: %d\n", ret); goto out; } /* Create a new copy for our caller. */ *str = strdup (val); out: gp_widget_free (widget); return ret; }
int canon_enable_capture(Camera *camera, int onoff, GPContext *context) { CameraWidget *widget = NULL, *child = NULL; CameraWidgetType type; int ret; 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, "capture", &child); if (ret < GP_OK) { /*fprintf (stderr, "lookup widget failed: %d\n", ret);*/ goto out; } 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; } /* Now set the toggle to the wanted value */ ret = gp_widget_set_value(child, &onoff); if (ret < GP_OK) { fprintf(stderr, "toggling Canon capture to %d failed with %d\n", onoff, ret); goto out; } /* OK */ ret = gp_camera_set_config(camera, widget, context); if (ret < GP_OK) { fprintf(stderr, "camera_set_config failed: %d\n", ret); return ret; } out: gp_widget_free(widget); return ret; }
/* Manual focusing a camera... * xx is -3 / -2 / -1 / 0 / 1 / 2 / 3 */ int camera_manual_focus (Camera *camera, int xx, GPContext *context) { CameraWidget *widget = NULL, *child = NULL; CameraWidgetType type; int ret; float rval; char *mval; 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, "manualfocusdrive", &child); if (ret < GP_OK) { fprintf (stderr, "lookup 'manualfocusdrive' 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_RADIO: { int choices = gp_widget_count_choices (child); ret = gp_widget_get_value (child, &mval); if (ret < GP_OK) { fprintf (stderr, "could not get widget value: %d\n", ret); goto out; } if (choices == 7) { /* see what Canon has in EOS_MFDrive */ ret = gp_widget_get_choice (child, xx+4, (const char**)&mval); if (ret < GP_OK) { fprintf (stderr, "could not get widget choice %d: %d\n", xx+2, ret); goto out; } fprintf(stderr,"manual focus %d -> %s\n", xx, mval); } ret = gp_widget_set_value (child, mval); if (ret < GP_OK) { fprintf (stderr, "could not set widget value to 1: %d\n", ret); goto out; } break; } case GP_WIDGET_RANGE: ret = gp_widget_get_value (child, &rval); if (ret < GP_OK) { fprintf (stderr, "could not get widget value: %d\n", ret); goto out; } switch (xx) { /* Range is on Nikon from -32768 <-> 32768 */ case -3: rval = -1024;break; case -2: rval = -512;break; case -1: rval = -128;break; case 0: rval = 0;break; case 1: rval = 128;break; case 2: rval = 512;break; case 3: rval = 1024;break; default: rval = xx; break; /* hack */ } fprintf(stderr,"manual focus %d -> %f\n", xx, rval); ret = gp_widget_set_value (child, &rval); if (ret < GP_OK) { fprintf (stderr, "could not set widget value to 1: %d\n", ret); goto out; } break; default: fprintf (stderr, "widget has bad type %d\n", type); ret = GP_ERROR_BAD_PARAMETERS; goto out; } ret = gp_camera_set_config (camera, widget, context); if (ret < GP_OK) { fprintf (stderr, "could not set config tree to autofocus: %d\n", ret); goto out; } out: gp_widget_free (widget); return ret; }