int internal_set_setting(const char * setting, const char * value) { CameraWidget * widget = NULL; // will hold the root config entry CameraWidget * child = NULL; // will hold the actual config entry from the tree int ret = getWidget(&widget, &child, setting); if (ret < GP_OK) { fprintf (stderr, "camera_get_config failed: %d\n", ret); return ret; } ret = gp_widget_set_value(child, value); if (ret < GP_OK) { fprintf (stderr, "could not set widget value: %d\n", ret); gp_widget_free (widget); return ret; } /* 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); gp_widget_free (widget); return ret; } gp_widget_free (widget); return 0; }
void Camera::set_config(CameraWidget* rootwindow) { std::lock_guard<std::mutex> g(mutex); int ret; if ((ret = gp_camera_set_config(camera, rootwindow, ctx->context)) < GP_OK) throw Exception("gp_camera_set_config", ret); }
//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; }
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 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; }
CAMLprim value caml_gp_camera_set_config(value camera_val, value context_val, value widget_val) { CAMLparam3(camera_val, context_val, widget_val); Camera *camera = Camera_val(camera_val); GPContext *context = Context_val(context_val); CameraWidget *widget = Widget_val(widget_val); int ret = gp_camera_set_config(camera, widget, context); CHECK_RESULT(ret); CAMLreturn(Val_unit); }
void _camera_configuration_commit(const dt_camctl_t *c,const dt_camera_t *camera) { g_assert( camera != NULL ); dt_camera_t *cam=(dt_camera_t *)camera; dt_pthread_mutex_lock(&cam->config_lock); if( gp_camera_set_config( camera->gpcam, camera->configuration, c->gpcontext) != GP_OK ) dt_print(DT_DEBUG_CAMCTL,"[camera_control] Failed to commit configuration changes to camera\n"); cam->config_changed=FALSE; dt_pthread_mutex_unlock(&cam->config_lock); }
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; }
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; }
static int set_config (CmdConfig *cmd_config) { int result, selection; char *msg[10]; char *buttons[] = {N_("</B/24>Continue"), N_("</B16>Cancel")}; CDKDIALOG *question = NULL; result = gp_camera_set_config (cmd_config->camera, cmd_config->window, cmd_config->context); if (result < 0) { msg[0] = N_("<C></5>Error"); msg[1] = ""; msg[2] = N_("Could not set configuration:"); msg[3] = (char*) gp_result_as_string (result); question = newCDKDialog (cmd_config->screen, CENTER, CENTER, msg, 4, buttons, 2, COLOR_PAIR (2) | A_REVERSE, TRUE, TRUE, FALSE); if (!question) return (GP_ERROR); selection = activateCDKDialog (question, 0); if (question->exitType == vNORMAL) { switch (selection) { case 0: /* Continue */ destroyCDKDialog (question); return (GP_OK); default: destroyCDKDialog (question); return (result); } } else { destroyCDKDialog (question); return (result); } } return (GP_OK); }
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 ); } }
bool Image_GPhoto::doSetProperty(const string& name, const string& value) { lock_guard<recursive_mutex> lock(_gpMutex); if (_selectedCameraIndex == -1) { Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - A camera must be selected before trying to capture" << Log::endl; return false; } GPhotoCamera* camera = &(_cameras[_selectedCameraIndex]); CameraWidget* widget; if (gp_widget_get_child_by_name(camera->configuration, name.c_str(), &widget) == GP_OK) { if (gp_widget_set_value(widget, value.c_str()) != GP_OK) { Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Unable to set parameter " << name << " to value " << value << Log::endl; return false; } if (gp_camera_set_config(camera->cam, camera->configuration, _gpContext) != GP_OK) { Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Setting parameter " << name << " is not supported for this camera" << Log::endl; return false; } return true; } else { Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Parameter " << name << " does not seem to be available" << Log::endl; } return false; }
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 photo_camera::photo_camera_set_config( std::string param, std::string value ) { CameraWidget *root, *child; int error_code; const char *label; CameraWidgetType type; // Locate the widget that corresponds to this parameter if( photo_camera_find_widget_by_name( param, &child, &root ) != GP_OK ) { photo_reporter::error( "photo_camera_find_widget_by_name()"); return false; } // Get the widget label if( gp_widget_get_label(child, &label) != GP_OK ) { photo_reporter::error( "gp_widget_get_label()"); gp_widget_free( root ); return false; } // Get the widget type if( gp_widget_get_type( child, &type ) != GP_OK ) { photo_reporter::error( "gp_widget_get_type()"); gp_widget_free( root ); return false; } switch( type ) { case GP_WIDGET_TEXT: // char* if( gp_widget_set_value(child, value.c_str()) != GP_OK ) { photo_reporter::error( "gp_widget_set_value()"); gp_context_error( context_, "Failed to set the value of text widget %s to %s.", param.c_str(), value.c_str() ); gp_widget_free( root ); return false; } break; case GP_WIDGET_RANGE: // float float f, t, b, s; if( gp_widget_get_range( child, &b, &t, &s) != GP_OK ) { photo_reporter::error( "gp_widget_get_range()" ); gp_widget_free( root ); return false; } if( !sscanf( value.c_str(), "%f", &f ) ) { gp_context_error( context_, "The passed value %s is not a floating point value.", value.c_str() ); gp_widget_free( root ); return false; } if( (f < b) || (f > t) ) { gp_context_error( context_ , "The passed value %f is not within the expected range of %f -- %f.", f, b, t ); gp_widget_free( root ); return false; } if( gp_widget_set_value( child, &f ) != GP_OK ) { photo_reporter::error( "gp_widget_set_value()" ); gp_context_error( context_, "Failed to set the value of range widget %s to %f.", param.c_str(), f ); gp_widget_free( root ); return false; } break; case GP_WIDGET_TOGGLE: // int bool tog; if( photo_camera_check_toggle_value( value, &tog ) == false ) { gp_context_error(context_, "The passed value %s is not a valid toggle value.", value.c_str() ); gp_widget_free( root ); return false; } if( gp_widget_set_value( child, &tog ) != GP_OK ) { photo_reporter::error( "gp_widget_set_value()" ); gp_context_error( context_, "Failed to set values %s of toggle widget %s.", value.c_str(), param.c_str() ); gp_widget_free( root ); return false; } break; case GP_WIDGET_DATE: // int { int time = -1; #ifdef HAVE_STRPTIME struct tm xtm; if( strptime( value.c_str(), "%c", &xtm ) || strptime( value.c_str(), "%Ec", &xtm ) ) { time = mktime( &xtm ); } #endif if( time == -1 ) { if( !sscanf( value.c_str(), "%d", &time ) ) { gp_context_error( context_, "The passed value %s is neither a valid time nor an integer.", value.c_str() ); gp_widget_free( root ); return false; } } if( gp_widget_set_value(child, &time) != GP_OK ) { photo_reporter::error( "gp_widget_set_value()" ); gp_context_error( context_, "Failed to set new time of date/time widget %s to %s.", param.c_str(), value.c_str() ); gp_widget_free( root ); return false; } break; } case GP_WIDGET_MENU: case GP_WIDGET_RADIO: // char* int count, i; count = gp_widget_count_choices( child ); if( count < GP_OK ) { photo_reporter::error( "gp_widget_count_choices()" ); gp_widget_free( root ); return false; } error_code = GP_ERROR_BAD_PARAMETERS; for( i = 0; i < count; i++ ) { const char *choice; if( gp_widget_get_choice( child, i, &choice ) == GP_OK ) { if( value.compare( choice ) == 0 ) { if( gp_widget_set_value( child, value.c_str() ) == GP_OK ) { break; } } } } // attemt a different method for setting a radio button if( sscanf( value.c_str(), "%d", &i ) ) { if( (i >= 0) && (i < count) ) { const char *choice; if( gp_widget_get_choice( child, i, &choice ) == GP_OK ) { if( gp_widget_set_value( child, choice ) == GP_OK ) { break; } } } } gp_context_error( context_, "Choice %s not found within list of choices.", value.c_str() ); gp_widget_free( root ); return false; case GP_WIDGET_WINDOW: case GP_WIDGET_SECTION: case GP_WIDGET_BUTTON: default: gp_context_error( context_,"The %s widget is not configurable.", param.c_str() ); gp_widget_free( root ); return false; } // Configuration parameters are correct, so set the camera if( gp_camera_set_config( camera_, root, context_ ) != GP_OK ) { photo_reporter::error( "gp_camera_set_config()" ); gp_context_error( context_, "Failed to set new configuration value %s for configuration entry %s.", value.c_str(), param.c_str() ); gp_widget_free( root ); return false; } gp_widget_free( root ); return true; }
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); }
/** * Set property. * @see DigitalCameraCapture for more information about value, double typed, argument. */ bool DigitalCameraCapture::setProperty(int propertyId, double value) { CameraWidget * widget = NULL; bool output = false; if (propertyId < 0) { widget = getWidget(-propertyId); } else { switch (propertyId) { // gphoto2 cap featured case CV_CAP_PROP_GPHOTO2_PREVIEW: preview = value != 0; return true; case CV_CAP_PROP_GPHOTO2_WIDGET_ENUMERATE: return false; case CV_CAP_PROP_GPHOTO2_RELOAD_CONFIG: reloadConfig(); return true; case CV_CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE: reloadOnChange = value != 0; return true; case CV_CAP_PROP_GPHOTO2_COLLECT_MSGS: collectMsgs = value != 0; return true; case CV_CAP_PROP_GPHOTO2_FLUSH_MSGS: return false; default: widget = setGenericProperty(propertyId, value, output); /* no break */ } } if (widget == NULL) return output; try { CameraWidgetType type; CR(gp_widget_get_type(widget, &type)); switch (type) { case GP_WIDGET_RADIO: case GP_WIDGET_MENU: { int i = static_cast<int>(value); char *choice; CR(gp_widget_get_choice(widget, i, (const char**)&choice)); CR(gp_widget_set_value(widget, choice)); break; } case GP_WIDGET_TOGGLE: { int i = static_cast<int>(value); CR(gp_widget_set_value(widget, &i)); break; } case GP_WIDGET_RANGE: { float v = static_cast<float>(value); CR(gp_widget_set_value(widget, &v)); break; } default: { CR(gp_widget_set_value(widget, (void* )(intptr_t )&value)); break; } } if (!reloadOnChange) { // force widget change CR(gp_widget_set_changed(widget, 1)); } // Use the same locale setting as while getting rootWidget. char * localeTmp = setlocale(LC_ALL, "C"); CR(gp_camera_set_config(camera, rootWidget, context)); setlocale(LC_ALL, localeTmp); if (reloadOnChange) { reloadConfig(); } else { CR(gp_widget_set_changed(widget, 0)); } } catch (GPhoto2Exception & e) { char buf[128] = ""; sprintf(buf, "cannot set property: %d to %f", propertyId, value); message(WARNING, (const char *) buf, e); return false; } return true; }
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; }
/* 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; }
/** * @brief CameraHandler::setConfigAction * @param p * @param name * @param value * @return */ int QTLCamera::setConfigAction(const char *name, const char *value) { CameraWidget *rootConfig,*child; int rc; const char *label; CameraWidgetType type; rc = findWidgetByName(name, &child, &rootConfig); if (rc != GP_OK) { return rc; } rc = gp_widget_get_type (child, &type); if (rc != GP_OK) { gp_widget_free(rootConfig); return rc; } rc = gp_widget_get_label(child, &label); if (rc != GP_OK) { gp_widget_free(rootConfig); return rc; } switch (type) { case GP_WIDGET_TOGGLE: { } case GP_WIDGET_TEXT: { /* char * */ rc = gp_widget_set_value(child, value); if (rc != GP_OK) { qDebug() << "Failed to set the value of text widget" << name << value; } break; } case GP_WIDGET_RANGE: { /* float */ float floatValue, top, bottom, s; rc = gp_widget_get_range(child, &bottom, &top, &s); if (rc != GP_OK) break; if (!sscanf(value, "%f", &floatValue)) { qDebug() << "The passed value" << value << "is not a floating point value."; rc = GP_ERROR_BAD_PARAMETERS; break; } if ((floatValue < bottom) || (floatValue > top)) { qDebug () << "The passed value" << floatValue << "is not within the expected range" << bottom << "-" << top << "."; rc = GP_ERROR_BAD_PARAMETERS; break; } rc = gp_widget_set_value(child, &floatValue); if (rc != GP_OK) { qDebug() << "Failed to set the value of range widget" << name << "to" << floatValue << "."; } break; } case GP_WIDGET_DATE: { /* int */ int t = -1; if (t == -1) { if (!sscanf(value, "%d", &t)) { qDebug() << "The passed value" << value << "is neither a valid time nor an integer."; rc = GP_ERROR_BAD_PARAMETERS; break; } } rc = gp_widget_set_value(child, &t); if (rc != GP_OK) { qDebug() << "Failed to set new time of date/time widget " << name << " to " << value << "."; } break; } case GP_WIDGET_MENU: case GP_WIDGET_RADIO: { /* char * */ int cnt, i; cnt = gp_widget_count_choices(child); if (cnt < GP_OK) { rc = cnt; break; } rc = GP_ERROR_BAD_PARAMETERS; for (i=0; i<cnt; i++) { const char *choice; rc = gp_widget_get_choice(child, i, &choice); if (rc != GP_OK) { continue; } if (!strcmp(choice, value)) { rc = gp_widget_set_value(child, value); break; } } if (i != cnt) { break; } if (sscanf(value, "%d", &i)) { if ((i >= 0) && (i < cnt)) { const char *choice; rc = gp_widget_get_choice(child, i, &choice); if (rc == GP_OK) { rc = gp_widget_set_value(child, choice); } break; } } qDebug() << "Choice " << value << " not found within list of choices."; break; } /* ignore: */ case GP_WIDGET_WINDOW: case GP_WIDGET_SECTION: case GP_WIDGET_BUTTON: //gp_context_error(p->context, _("The %s widget is not configurable."), name); rc = GP_ERROR_BAD_PARAMETERS; break; } if (rc == GP_OK) { rc = gp_camera_set_config(params->camera, rootConfig, params->context); if (rc != GP_OK) { qDebug() << "Failed to set new configuration value " << value << " for configuration entry " << name << "."; } } gp_widget_free(rootConfig); return rc; }