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 photo_camera::photo_camera_find_widget_by_name( std::string name, CameraWidget **child, CameraWidget **root) { int error_code; // Get camera configuration error_code = gp_camera_get_config( camera_, root, context_ ); if (error_code != GP_OK) { photo_reporter::error( "gp_camera_get_config()"); return error_code; } // Find child of configuration by name if( gp_widget_get_child_by_name( *root, name.c_str(), child ) == GP_OK ) { return GP_OK; } // Find child of configuration by label if( gp_widget_get_child_by_label( *root, name.c_str(), child ) == GP_OK ) { return GP_OK; } // If full name is not found, search for last subname. // name delimeter is '/' size_t found_index = name.length(); while( found_index == name.length() ) { found_index = name.rfind( '/' ); if( found_index == std::string::npos ) // No subname, we already failed this search above { gp_context_error( context_,"%s not found in configuration tree.", name.c_str() ); gp_widget_free( *root ); return GP_ERROR; } if( found_index == name.length() - 1 ) // end of string, cut it off { name = name.substr( 0, found_index ); } } name = name.substr( found_index, name.length() - 1 ); // Find child using if( gp_widget_get_child_by_name( *root, name.c_str(), child ) == GP_OK ) { return GP_OK; } if( gp_widget_get_child_by_label( *root, name.c_str(), child ) == GP_OK ) { return GP_OK; } // all matches have failed gp_context_error( context_, "%s not found in configuration tree.", name.c_str() ); gp_widget_free( *root ); return GP_ERROR; }
/** * @brief CameraHandler::findWidgetByName * @param p * @param name * @param child * @param rootConfig * @return */ int QTLCamera::findWidgetByName(const char *name, CameraWidget **child, CameraWidget **rootConfig) { int rc; rc = gp_camera_get_config(params->camera, rootConfig, params->context); if (rc != GP_OK) { return rc; } rc = gp_widget_get_child_by_name(*rootConfig, name, child); if (rc != GP_OK) { rc = gp_widget_get_child_by_label(*rootConfig, name, child); } if (rc != GP_OK) { char *part, *s, *newname; newname = strdup(name); if (!newname) { return GP_ERROR_NO_MEMORY; } *child = *rootConfig; part = newname; while (part[0] == '/') { part++; } while (1) { CameraWidget *tmp; s = strchr(part,'/'); if (s) { *s = '\0'; } rc = gp_widget_get_child_by_name(*child, part, &tmp); if (rc != GP_OK) { rc = gp_widget_get_child_by_label(*child, part, &tmp); } if (rc != GP_OK) { break; } *child = tmp; if (!s) { // end of path break; } part = s + 1; while (part[0] == '/') { part++; } } if (s) { // If we have stuff left over, we failed. qDebug() << newname << "not found in configuration tree."; free(newname); gp_widget_free(*rootConfig); return GP_ERROR; } free (newname); } return GP_OK; }
//Set the camera's quality to a certain choice //Current Choices are: // 0: Large Fine JPEG // 2: Medium Fine JPEG int QualityControl(int quality){ char qualString[20]; if(quality == currentQuality){ //We don't want to take up cycles changing nothing return -1; //Could define set error codes, but we don't look at them anyway } strncpy(qualString, "", sizeof qualString); //Debatably necessary if(quality == 0){ strncpy(qualString, "Large Fine JPEG", sizeof qualString); } else if(quality == 2){ strncpy(qualString, "Medium Fine JPEG", sizeof qualString); } else{ return -1; } CameraWidget* widget,* child; if(gp_camera_get_config(getMyCamera(), &widget, getMyContext()) != 0){ //Get our current config free(widget); free(child); return -1; //If it fails, we have failed. } //Widgets in libgphoto act sort of as trees of settings/data //We need to find the right child of the top level, and the right child of that, etc. //until we get down to the appropriate quality setting widget //I already parsed through the tree and found the right child, and so //have hard-coded the values to get to this child here //Check out gphoto2-widget.c for more info gp_widget_get_child(widget, 3, &child); widget = child; gp_widget_get_child(widget, 0, &child); widget = child; //Here we change the quality value to whatever we want //For some reason, it is saved as a string, not a choice //Don't ask me why. gp_widget_set_value(widget, qualString); gp_widget_get_root(widget, &child); if(gp_camera_set_config(getMyCamera(), child, getMyContext()) != 0){ //Set the camera's config to our new, modified config free(widget); free(child); return -1; } free(widget); free(child); currentQuality = quality; //Remember what quality we currently have return 0; }
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; }
CAMLprim value caml_gp_camera_get_config(value camera_val, value context_val) { CAMLparam2(camera_val, context_val); Camera *camera = Camera_val(camera_val); GPContext *context = Context_val(context_val); CameraWidget *widget; int ret = gp_camera_get_config(camera, &widget, context); CHECK_RESULT(ret); CAMLreturn(encapsulate_pointer(widget)); }
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; }
Widget Camera::config() { std::lock_guard<std::mutex> cg(configmutex); std::lock_guard<std::mutex> g(mutex); CameraWidget *w; int ret; if ((ret = gp_camera_get_config(camera, &w, ctx->context)) < GP_OK) throw Exception("gp_camera_get_config", ret); return Widget(w, *this); }
void _camera_configuration_update(const dt_camctl_t *c,const dt_camera_t *camera) { // dt_camctl_t *camctl=(dt_camctl_t *)c; dt_camera_t *cam=(dt_camera_t *)camera; dt_pthread_mutex_lock(&cam->config_lock); CameraWidget *remote; // Copy of remote configuration gp_camera_get_config( camera->gpcam, &remote, c->gpcontext ); // merge remote copy with cache and notify on changed properties to host application _camera_configuration_merge(c, camera, remote, camera->configuration, FALSE ); dt_pthread_mutex_unlock(&cam->config_lock); }
const Widget Camera::config() const { std::lock_guard<std::mutex> cg(configmutex); std::lock_guard<std::mutex> g(mutex); CameraWidget *w; int ret; if ((ret = gp_camera_get_config(camera, &w, ctx->context)) < GP_OK) throw Exception("gp_camera_get_config", ret); // FIXME: dirty cast, make const Widget do magic return Widget(w, const_cast<gp::Camera&>(*this)); }
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; }
gboolean _camera_initialize(const dt_camctl_t *c, dt_camera_t *cam) { dt_camctl_t *camctl=(dt_camctl_t *)c; CameraAbilities a; GPPortInfo pi; if( cam->gpcam==NULL ) { gp_camera_new(&cam->gpcam); int m = gp_abilities_list_lookup_model( c->gpcams, cam->model ); gp_abilities_list_get_abilities (c->gpcams, m, &a); gp_camera_set_abilities (cam->gpcam, a); int p = gp_port_info_list_lookup_path (c->gpports, cam->port); gp_port_info_list_get_info (c->gpports, p, &pi); gp_camera_set_port_info (cam->gpcam , pi); // Check for abilities if( (a.operations&GP_OPERATION_CAPTURE_IMAGE) ) cam->can_tether=TRUE; if( (a.operations&GP_OPERATION_CAPTURE_PREVIEW) ) cam->can_live_view=TRUE; if( cam->can_tether && (a.operations&GP_OPERATION_CONFIG) ) cam->can_config=TRUE; if( !(a.file_operations&GP_FILE_OPERATION_NONE) ) cam->can_import=TRUE; if( gp_camera_init( cam->gpcam , camctl->gpcontext) != GP_OK ) { dt_print(DT_DEBUG_CAMCTL,"[camera_control] failed to initialize camera %s on port %s\n", cam->model,cam->port); return FALSE; } // read a full copy of config to configuration cache gp_camera_get_config( cam->gpcam, &cam->configuration, c->gpcontext ); // TODO: find a more robust way for this, once we find out how to do it with non-EOS cameras if(cam->can_live_view && dt_camctl_camera_property_exists(camctl, cam, "eoszoomposition")) cam->can_live_view_advanced = TRUE; // initialize timeout callbacks eg. keep alive, some cameras needs it. cam->gpcontext = camctl->gpcontext; gp_camera_set_timeout_funcs(cam->gpcam, (CameraTimeoutStartFunc)_camera_start_timeout_func, (CameraTimeoutStopFunc)_camera_stop_timeout_func, cam); dt_pthread_mutex_init(&cam->jobqueue_lock, NULL); dt_print(DT_DEBUG_CAMCTL,"[camera_control] device %s on port %s initialized\n", cam->model,cam->port); } else dt_print(DT_DEBUG_CAMCTL,"[camera_control] device %s on port %s already initialized\n", cam->model,cam->port); return TRUE; }
int main(int argc, char **argv) { Camera *camera = NULL; int ret; GPContext *context; CameraWidget *rootwidget; char buf[200]; CameraText summary; gp_log_add_func(GP_LOG_DEBUG, errordumper, NULL); context = sample_create_context (); /* see context.c */ strcpy(buf,"usb:"); if (argc > 1) strcat (buf, argv[1]); fprintf(stderr,"setting path %s.\n", buf); ret = sample_open_camera (&camera, "USB PTP Class Camera", buf, context); if (ret < GP_OK) { fprintf(stderr,"camera %s not found.\n", buf); goto out; } ret = gp_camera_init (camera, context); if (ret < GP_OK) { fprintf(stderr,"No camera auto detected.\n"); goto out; } /* AFL PART STARTS HERE */ ret = gp_camera_get_summary (camera, &summary, context); if (ret < GP_OK) { printf ("Could not get summary.\n"); goto out; } #if 1 ret = gp_camera_get_config (camera, &rootwidget, context); if (ret < GP_OK) { fprintf (stderr,"Could not get config.\n"); goto out; } #endif printf ("OK, %s\n", summary.text); /* AFL PART ENDS HERE */ out: gp_camera_exit (camera, context); gp_camera_free (camera); return 0; }
QVariant GPhotoCameraWorker::parameter(const QString &name) { CameraWidget *root; int ret = gp_camera_get_config(m_camera, &root, m_context); if (ret < GP_OK) { qWarning() << "Unable to get root option from gphoto"; return QVariant(); } CameraWidget *option; ret = gp_widget_get_child_by_name(root, qPrintable(name), &option); if (ret < GP_OK) { qWarning() << "Unable to get config widget from gphoto"; return QVariant(); } CameraWidgetType type; ret = gp_widget_get_type(option, &type); if (ret < GP_OK) { qWarning() << "Unable to get config widget type from gphoto"; return QVariant(); } if (type == GP_WIDGET_RADIO) { char *value; ret = gp_widget_get_value(option, &value); if (ret < GP_OK) { qWarning() << "Unable to get value for option" << qPrintable(name) << "from gphoto"; return QVariant(); } else { return QString::fromLocal8Bit(value); } } else if (type == GP_WIDGET_TOGGLE) { int value; ret = gp_widget_get_value(option, &value); if (ret < GP_OK) { qWarning() << "Unable to get value for option" << qPrintable(name) << "from gphoto"; return QVariant(); } else { return value == 0 ? false : true; } } else { qWarning() << "Options of type" << type << "are currently not supported"; } return QVariant(); }
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; }
int camera_set(char* name, void* value) { int res; CameraWidget* config_root; CameraWidget* widget; res = gp_camera_get_config(camera, &config_root, context); CAMERA_CHECK_GP(res, "gp_camera_get_config"); res = gp_widget_get_child_by_name(config_root, name, &widget); CAMERA_CHECK_GP(res, "gp_widget_get_child_by_name"); res = gp_widget_set_value(widget, value); CAMERA_CHECK_GP(res, "gp_widget_set_value"); res = gp_camera_set_config(camera, config_root, context); CAMERA_CHECK_GP(res, "gp_camera_set_config"); gp_widget_unref(config_root); return 1; }
bool Image_GPhoto::initCamera(GPhotoCamera& camera) { lock_guard<recursive_mutex> lock(_gpMutex); if (camera.cam == nullptr) { gp_camera_new(&camera.cam); int m = gp_abilities_list_lookup_model(_gpCams, camera.model.c_str()); CameraAbilities abilities{}; gp_abilities_list_get_abilities(_gpCams, m, &abilities); gp_camera_set_abilities(camera.cam, abilities); int p = gp_port_info_list_lookup_path(_gpPorts, camera.port.c_str()); GPPortInfo portInfo; gp_port_info_list_get_info(_gpPorts, p, &portInfo); gp_camera_set_port_info(camera.cam, portInfo); if (abilities.operations & GP_OPERATION_CAPTURE_IMAGE) { camera.canTether = true; if (abilities.operations & GP_OPERATION_CONFIG) camera.canConfig = true; } if (!(abilities.file_operations & GP_FILE_OPERATION_NONE)) camera.canImport = true; if (gp_camera_init(camera.cam, _gpContext) != GP_OK) return false; gp_camera_get_config(camera.cam, &camera.configuration, _gpContext); // Get the available shutterspeeds initCameraProperty(camera, "shutterspeed", camera.shutterspeeds); initCameraProperty(camera, "aperture", camera.apertures); initCameraProperty(camera, "iso", camera.isos); return true; } else { Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Camera " << camera.model << " already initialized" << Log::endl; return false; } }
/** * @brief QTLCamera::initCamera * @return */ QTLError QTLCamera::initCamera() { QTLError result; result.rc = GP_OK; result.errorText = "Camera initialized."; // Set aside memory for camera result.rc = gp_camera_new(¶ms->camera); if (result.rc != GP_OK) { result.errorText = gp_result_as_string(result.rc); return result; } // Initialise camera qDebug() << "Detecting Camera."; result.rc = gp_camera_init(params->camera, params->context); if (result.rc != GP_OK) { result.errorText = gp_result_as_string(result.rc); if (result.rc == -105) { result.errorText = "Failed to initialise camera. Please check the camera " \ "is turned on, then re-initialise or restart the program to enable" \ " camera paramaters."; } else if (result.rc == -60 || result.rc == -53) { result.errorText = "Failed to initialise camera. Please check the camera " \ "is unmounted and that no other applications are using it, then " \ "re-initialise or restart the program to enable camera paramaters."; } } else { qDebug() << "Camera detected"; qDebug() << "Detecting widgets" << endl; CameraWidget *rootConfig; result.rc = gp_camera_get_config(params->camera, &rootConfig, params->context); if (result.rc == GP_OK) { char prefix[] = ""; _getWidgets(params->widgetList, rootConfig, prefix); gp_widget_free(rootConfig); } qDebug() << "Widgets detected"; } return result; }
/** * Load device settings. */ void DigitalCameraCapture::reloadConfig() { std::ostringstream widgetInfoListStream; if (rootWidget != NULL) { widgetInfo.clear(); CR(gp_widget_unref(rootWidget)); rootWidget = NULL; widgets.clear(); } // Make sure, that all configs (getting setting) will use the same locale setting. char * localeTmp = setlocale(LC_ALL, "C"); CR(gp_camera_get_config(camera, &rootWidget, context)); setlocale(LC_ALL, localeTmp); widgetInfoListStream << "id,label,name,info,readonly,type,value," << lineDelimiter; noOfWidgets = collectWidgets(widgetInfoListStream, rootWidget) + 1; widgetInfo = widgetInfoListStream.str(); }
void dt_camctl_camera_stop_live_view(const dt_camctl_t *c) { dt_camctl_t *camctl = (dt_camctl_t*)c; dt_camera_t *cam = (dt_camera_t*)camctl->active_camera; dt_print(DT_DEBUG_CAMCTL,"[camera_control] Stopping live view\n"); cam->is_live_viewing = FALSE; pthread_join(cam->live_view_thread, NULL); //tell camera to get back to normal state (close mirror) // this should work like this: // dt_camctl_camera_set_property(darktable.camctl, NULL, "eosviewfinder", "0"); // but it doesn't, passing a string isn't ok in this case. I guess that's a TODO. // for the time being I'll do it manually (not nice, I know). CameraWidget *config; CameraWidget *widget; gp_camera_get_config( cam->gpcam, &config, camctl->gpcontext ); if( gp_widget_get_child_by_name ( config, "eosviewfinder", &widget) == GP_OK) { int zero=0; gp_widget_set_value ( widget , &zero); gp_camera_set_config( cam->gpcam, config, camctl->gpcontext ); } }
int gp_cmd_config (Camera *camera, GPContext *context) { CmdConfig cmd_config; CameraWidget *config; int result; CDKSCREEN *screen = NULL; WINDOW *window = NULL; if (!camera) return (GP_ERROR_BAD_PARAMETERS); result = gp_camera_get_config (camera, &config, context); if (result < 0) return (result); /* Set up CDK. */ window = initscr (); screen = initCDKScreen (window); /* Set up CDK Colors. */ initCDKColor (); /* Go! */ cmd_config.camera = camera; cmd_config.screen = screen; cmd_config.window = config; cmd_config.context = context; result = show_widget (&cmd_config, config); /* Clean up */ destroyCDKScreen (screen); delwin (window); endCDK (); return (result); }
void GPhotoCameraWorker::logOption(const char *name) { CameraWidget *root; int ret = gp_camera_get_config(m_camera, &root, m_context); if (ret < GP_OK) { qWarning() << "Unable to get root option from gphoto"; return; } CameraWidget *option; ret = gp_widget_get_child_by_name(root, name, &option); if (ret < GP_OK) qWarning() << "Unable to get config widget from gphoto"; CameraWidgetType type; ret = gp_widget_get_type(option, &type); if (ret < GP_OK) qWarning() << "Unable to get config widget type from gphoto"; char *value; ret = gp_widget_get_value(option, &value); qDebug() << "Option" << type << name << value; if (type == GP_WIDGET_RADIO) { int count = gp_widget_count_choices(option); qDebug() << "Choices count:" << count; for (int i = 0; i < count; ++i) { const char* choice; gp_widget_get_choice(option, i, &choice); qDebug() << " value:" << choice; } } gp_widget_free(option); }
int main(int argc, char **argv) { Camera *camera = NULL; int ret; GPContext *context; CameraWidget *rootwidget; char buf[200]; CameraText summary; gp_log_add_func(GP_LOG_DEBUG, errordumper, NULL); context = sample_create_context (); /* see context.c */ strcpy(buf,"usb:"); if (argc > 1) strcat (buf, argv[1]); fprintf(stderr,"setting path %s.\n", buf); ret = sample_open_camera (&camera, "USB PTP Class Camera", buf, context); if (ret < GP_OK) { fprintf(stderr,"camera %s not found.\n", buf); goto out; } ret = gp_camera_init (camera, context); if (ret < GP_OK) { fprintf(stderr,"No camera auto detected.\n"); goto out; } /* AFL PART STARTS HERE */ ret = recursive_directory(camera, "/", context, NULL); if (ret < GP_OK) { printf ("Could not recursive list files.\n"); goto out; } ret = gp_camera_get_summary (camera, &summary, context); if (ret < GP_OK) { printf ("Could not get summary.\n"); goto out; } #if 1 ret = gp_camera_get_config (camera, &rootwidget, context); if (ret < GP_OK) { fprintf (stderr,"Could not get config.\n"); goto out; } #endif printf ("OK, %s\n", summary.text); while (1) { CameraEventType evttype; void *data = NULL; ret = gp_camera_wait_for_event(camera, 1, &evttype, &data, context); if (ret < GP_OK) break; if (data) free (data); if (evttype == GP_EVENT_TIMEOUT) break; } /* AFL PART ENDS HERE */ out: gp_camera_exit (camera, context); gp_camera_free (camera); return 0; }
bool GPhotoCameraWorker::setParameter(const QString &name, const QVariant &value) { CameraWidget *root; int ret = gp_camera_get_config(m_camera, &root, m_context); if (ret < GP_OK) { qWarning() << "Unable to get root option from gphoto"; return false; } // Get widget pointer CameraWidget *option; ret = gp_widget_get_child_by_name(root, qPrintable(name), &option); if (ret < GP_OK) { qWarning() << "Unable to get option" << qPrintable(name) << "from gphoto"; return false; } // Get option type CameraWidgetType type; ret = gp_widget_get_type(option, &type); if (ret < GP_OK) { qWarning() << "Unable to get option type from gphoto"; gp_widget_free(option); return false; } if (type == GP_WIDGET_RADIO) { if (value.type() == QVariant::String) { // String, need no conversion ret = gp_widget_set_value(option, qPrintable(value.toString())); if (ret < GP_OK) { qWarning() << "Failed to set value" << value << "to" << name << "option:" << ret; return false; } ret = gp_camera_set_config(m_camera, root, m_context); if (ret < GP_OK) { qWarning() << "Failed to set config to camera"; return false; } waitForOperationCompleted(); return true; } else if (value.type() == QVariant::Double) { // Trying to find nearest possible value (with the distance of 0.1) and set it to property double v = value.toDouble(); int count = gp_widget_count_choices(option); for (int i = 0; i < count; ++i) { const char* choice; gp_widget_get_choice(option, i, &choice); // We use a workaround for flawed russian i18n of gphoto2 strings bool ok; double choiceValue = QString::fromLocal8Bit(choice).replace(',', '.').toDouble(&ok); if (!ok) { qDebug() << "Failed to convert value" << choice << "to double"; continue; } if (qAbs(choiceValue - v) < 0.1) { ret = gp_widget_set_value(option, choice); if (ret < GP_OK) { qWarning() << "Failed to set value" << choice << "to" << name << "option:" << ret; return false; } ret = gp_camera_set_config(m_camera, root, m_context); if (ret < GP_OK) { qWarning() << "Failed to set config to camera"; return false; } waitForOperationCompleted(); return true; } } qWarning() << "Can't find value matching to" << v << "for option" << name; return false; } else if (value.type() == QVariant::Int) { // Little hacks for 'ISO' option: if the value is -1, we pick the first non-integer value // we found and set it as a parameter int v = value.toInt(); int count = gp_widget_count_choices(option); for (int i = 0; i < count; ++i) { const char* choice; gp_widget_get_choice(option, i, &choice); bool ok; int choiceValue = QString::fromLocal8Bit(choice).toInt(&ok); if ((ok && choiceValue == v) || (!ok && v == -1)) { ret = gp_widget_set_value(option, choice); if (ret < GP_OK) { qWarning() << "Failed to set value" << choice << "to" << name << "option:" << ret; return false; } ret = gp_camera_set_config(m_camera, root, m_context); if (ret < GP_OK) { qWarning() << "Failed to set config to camera"; return false; } waitForOperationCompleted(); return true; } } qWarning() << "Can't find value matching to" << v << "for option" << name; return false; } else { qWarning() << "Failed to set value" << value << "to" << name << "option. Type" << value.type() << "is not supported"; gp_widget_free(option); return false; } } else if (type == GP_WIDGET_TOGGLE) { int v = 0; if (value.canConvert<int>()) { v = value.toInt(); } else { qWarning() << "Failed to set value" << value << "to" << name << "option. Type" << value.type() << "is not supported"; gp_widget_free(option); return false; } ret = gp_widget_set_value(option, &v); if (ret < GP_OK) { qWarning() << "Failed to set value" << v << "to" << name << "option:" << ret; return false; } ret = gp_camera_set_config(m_camera, root, m_context); if (ret < GP_OK) { qWarning() << "Failed to set config to camera"; return false; } waitForOperationCompleted(); return true; } else { qWarning() << "Options of type" << type << "are currently not supported"; } gp_widget_free(option); return false; }
bool photoController::setPhotoQuality() { bool result = true; int ret; CameraWidget *rootconfig; CameraWidget *child; DEBUG_PRINTF(V_MESSAGE, "Checking camera detection.\n"); if(!camera_detected) { DEBUG_PRINTF(V_MESSAGE, "Camera not detected.\n"); return false; } DEBUG_PRINTF(V_MESSAGE, "Getting camera config.\n"); ret = gp_camera_get_config(camera, &rootconfig, context); if (ret != GP_OK) { DEBUG_PRINTF(V_MESSAGE, "Getting camera config error.\n"); result = false; } DEBUG_PRINTF(V_MESSAGE, "Getting imageformat config.\n"); ret = gp_widget_get_child_by_name(rootconfig, "imageformat", &child); if (ret != GP_OK) { DEBUG_PRINTF(V_MESSAGE, "Getting imageformat config error.\n"); result = false; } // Choice: 0 Large Fine JPEG // Choice: 1 Large Normal JPEG // Choice: 2 Medium Fine JPEG // Choice: 3 Medium Normal JPEG // Choice: 4 Small Fine JPEG // Choice: 5 Small Normal JPEG // Choice: 6 Smaller JPEG // Choice: 7 Tiny JPEG // Choice: 8 RAW + Large Fine JPEG // Choice: 9 RAW DEBUG_PRINTF(V_MESSAGE, "Setting image format config.\n"); const char* smallerJPEG = NULL; ret = gp_widget_get_choice (child, 6, &smallerJPEG); //6 = Smaller JPEG if (ret != GP_OK) { DEBUG_PRINTF(V_MESSAGE, "Getting image format choice error %d.\n", ret); result = false; } ret = gp_widget_set_value(child, smallerJPEG); if (ret != GP_OK) { DEBUG_PRINTF(V_MESSAGE, "Setting image format config error %d.\n", ret); result = false; } DEBUG_PRINTF(V_MESSAGE, "Setting camera config.\n"); ret = gp_camera_set_config(camera, rootconfig, context); if (ret != GP_OK) { DEBUG_PRINTF(V_MESSAGE, "Setting camera config error %d.\n", ret); result = false; } DEBUG_PRINTF(V_MESSAGE, "Freeing camera config object.\n"); gp_widget_free(rootconfig); return result; }
int main (int argc, char** argv) { std::cout<<"GP_OK = "<<GP_OK<<std::endl; GPContext *currentContext = NULL; gp_context_new(); Camera *camera=NULL; gp_camera_new (&camera); gp_camera_init (camera, currentContext); CameraAbilitiesList * abilitiesList; CameraAbilities abilities; CameraAbilities * ptr_abilities; ptr_abilities = &abilities; int haveListAbilities = gp_abilities_list_get_abilities (abilitiesList, 0, ptr_abilities); std::cout<<"haveListAbilities : "<< haveListAbilities<<std::endl; /* int haveAbilities = gp_camera_set_abilities(camera, abilities); std::cout<<"haveAbilities : "<< haveAbilities<<std::endl;*/ /* //in case camera driver can't figure out the current camera's speed //gp_camera_set_port_path or name => pas TROUVE int speed; //AURA BESOIN D4UNE VALEUR (???) int hasSpeed = gp_camera_set_port_speed (camera, speed); */ //to know port's camera GPPortInfo info; GPPortInfo * ptr_info; ptr_info = &info; /* int infoSetted = gp_camera_set_port_info (camera, info); std::cout<<"infoSetted : "<< infoSetted<<std::endl;*/ /// int infoGetted = gp_camera_get_port_info(camera, ptr_info); std::cout<<"infoGetted : "<< infoGetted<<std::endl; //To have a window with camera's config CameraWidget ** widget; CameraWidgetType type; const char *label; int widgetCreated = gp_widget_new (type, label, widget); std::cout<<"widgetCreated : "<< widgetCreated<<std::endl; //get config int configGetted = gp_camera_get_config (camera, widget, currentContext); std::cout<<"configGetted : "<< configGetted<<std::endl; //set the configuration's camera // int cameraSetted = gp_camera_set_config (camera, *widget, currentContext); // std::cout<<"cameraSetted : "<< cameraSetted<<std::endl; //HAVE TO FIND FUNCTION WHICH GET/SET THE PÄTH CameraFilePath * path; //IDEM CameraCaptureType typeCapture; CameraFileType typeFile; //mm type à priori //capture int captured = gp_camera_capture (camera, typeCapture, path, currentContext); std::cout<<"captured : "<< captured<<std::endl; //To get capture from camera to computer //folder on computer //TO COMPLETE const char *folder = "../pictures"; //TO COMPLETE //(devra être renseigné en fonction du numéro de la photoprécédente par ex) const char *file = "picture001"; //?? CameraFile * camera_file; int captureGetted = gp_camera_file_get(camera, folder, file, typeFile,camera_file, currentContext); std::cout<<"captureGetted : "<< captureGetted<<std::endl; int indiceCountCamera = gp_camera_unref (camera); //Before the end of using camera => better! int cameraExited = gp_camera_exit (camera, currentContext); return EXIT_SUCCESS; }
static void _camera_process_job(const dt_camctl_t *c,const dt_camera_t *camera, gpointer job) { dt_camera_t *cam=(dt_camera_t *)camera; _camctl_camera_job_t *j = (_camctl_camera_job_t *)job; switch( j->type ) { case _JOB_TYPE_EXECUTE_CAPTURE: { dt_print (DT_DEBUG_CAMCTL,"[camera_control] executing remote camera capture job\n"); CameraFilePath fp; int res=GP_OK; if( (res = gp_camera_capture (camera->gpcam, GP_CAPTURE_IMAGE,&fp, c->gpcontext)) == GP_OK ) { CameraFile *destination; const char *output_path = _dispatch_request_image_path(c,camera); if( !output_path ) output_path="/tmp"; const char *fname = _dispatch_request_image_filename(c,fp.name,cam); if( !fname ) fname=fp.name; char *output = g_build_filename (output_path,fname,(char *)NULL); int handle = open (output, O_CREAT | O_WRONLY,0666); gp_file_new_from_fd (&destination , handle); gp_camera_file_get (camera->gpcam, fp.folder , fp.name, GP_FILE_TYPE_NORMAL, destination, c->gpcontext); close (handle); // Notify listerners of captured image _dispatch_camera_image_downloaded (c,camera,output); g_free (output); } else dt_print (DT_DEBUG_CAMCTL,"[camera_control] capture job failed to capture image: %s\n",gp_result_as_string(res)); } break; case _JOB_TYPE_EXECUTE_LIVE_VIEW: { CameraFile *fp = NULL; int res = GP_OK; const gchar* data = NULL; unsigned long int data_size = 0; gp_file_new(&fp); if( (res = gp_camera_capture_preview (cam->gpcam, fp, c->gpcontext)) != GP_OK ) { dt_print (DT_DEBUG_CAMCTL,"[camera_control] live view failed to capture preview: %s\n", gp_result_as_string(res)); } else if( (res = gp_file_get_data_and_size(fp, &data, &data_size)) != GP_OK ) { dt_print (DT_DEBUG_CAMCTL,"[camera_control] live view failed to get preview data: %s\n", gp_result_as_string(res)); } else { // everything worked GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); if(gdk_pixbuf_loader_write(loader, (guchar*)data, data_size, NULL) == TRUE) { dt_pthread_mutex_lock(&cam->live_view_pixbuf_mutex); if(cam->live_view_pixbuf != NULL) g_object_unref(cam->live_view_pixbuf); cam->live_view_pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); dt_pthread_mutex_unlock(&cam->live_view_pixbuf_mutex); } gdk_pixbuf_loader_close(loader, NULL); } if(fp) gp_file_free(fp); dt_pthread_mutex_unlock(&cam->live_view_synch); dt_control_queue_redraw_center(); } break; case _JOB_TYPE_SET_PROPERTY: { _camctl_camera_set_property_job_t *spj=(_camctl_camera_set_property_job_t *)job; dt_print(DT_DEBUG_CAMCTL,"[camera_control] executing set camera config job %s=%s\n",spj->name,spj->value); CameraWidget *config; // Copy of camera configuration CameraWidget *widget; gp_camera_get_config( cam->gpcam, &config, c->gpcontext ); if( gp_widget_get_child_by_name ( config, spj->name, &widget) == GP_OK) { gp_widget_set_value ( widget , spj->value); gp_camera_set_config( cam->gpcam, config, c->gpcontext ); } /* dt_pthread_mutex_lock( &cam->config_lock ); CameraWidget *widget; if( gp_widget_get_child_by_name ( camera->configuration, spj->name, &widget) == GP_OK) { gp_widget_set_value ( widget , spj->value); //gp_widget_set_changed( widget, 1 ); cam->config_changed=TRUE; } dt_pthread_mutex_unlock( &cam->config_lock);*/ } break; default: dt_print(DT_DEBUG_CAMCTL,"[camera_control] process of unknown job type %lx\n",(unsigned long int)j->type); break; } g_free(j); }
/* 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; }