/* * Only need to reset the generic camera type, AFAICT - * the pocket digital never seems to need it. */ static int ultrapocket_reset(Camera *camera) { GPPortInfo oldpi; GPPort *port = camera->port; CameraAbilities cab; unsigned char cmdbuf[0x10]; gp_camera_get_abilities(camera, &cab); GP_DEBUG ("First connect since camera was used - need to reset cam"); /* * this resets the ultrapocket. Messy, but it's what the windows * software does. We only reset if it's been plugged in since * last reset. */ memset(cmdbuf, 0, 16); cmdbuf[0] = 0x28; cmdbuf[1] = 0x01; CHECK_RESULT(ultrapocket_command(port, 1, cmdbuf, 0x10)); /* -------------- */ sleep(4); /* This should do - _might_ need increasing */ CHECK_RESULT(gp_port_get_info(port, &oldpi)); CHECK_RESULT(gp_port_free(port)); CHECK_RESULT(gp_port_new(&port)); CHECK_RESULT(gp_port_set_info(port, oldpi)); CHECK_RESULT(gp_port_usb_find_device(port, cab.usb_vendor, cab.usb_product)); CHECK_RESULT(gp_port_open(port)); camera->port = port; return GP_OK; }
static GNOME_C_Camera impl_connect (PortableServer_Servant servant, const CORBA_char *manufacturer, const CORBA_char *model, const CORBA_char *port, CORBA_Environment *ev) { KncCMngr *m = KNC_C_MNGR (bonobo_object (servant)); KncCCamera *c; GPPort *p = NULL; GPPortInfo info; unsigned int i; gp_port_new (&p); for (i = 0; i < MAX (gp_port_info_list_count (m->priv->il), 0); i++) { gp_port_info_list_get_info (m->priv->il, i, &info); if (!strcmp (info.name, port)) { gp_port_set_info (p, info); c = knc_c_camera_new (manufacturer, model, p, ev); if (BONOBO_EX (ev)) return CORBA_OBJECT_NIL; return CORBA_Object_duplicate (BONOBO_OBJREF (c), ev); } } gp_port_free (p); CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_C_Error, NULL); return CORBA_OBJECT_NIL; }
int gp_camera_set_port_info (Camera *camera, GPPortInfo info) { CHECK_NULL (camera); /* * If the camera is currently initialized, terminate that connection. * We don't care if we are successful or not. */ if (camera->pc->lh) gp_camera_exit (camera, NULL); gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Setting port info for " "port '%s' at '%s'...", info.name, info.path); CR (camera, gp_port_set_info (camera->port, info), NULL); return (GP_OK); }
int gp_camera_set_port_info (Camera *camera, GPPortInfo info) { char *name, *path; C_PARAMS (camera); /* * If the camera is currently initialized, terminate that connection. * We don't care if we are successful or not. */ if (camera->pc->lh) gp_camera_exit (camera, NULL); gp_port_info_get_name (info, &name); gp_port_info_get_path (info, &path); GP_LOG_D ("Setting port info for port '%s' at '%s'...", name, path); CR (camera, gp_port_set_info (camera->port, info), NULL); return (GP_OK); }
/** * \param list a CameraAbilitiesList * \param info_list the GPPortInfoList of ports to use for detection * \param l a #CameraList that contains the autodetected cameras after the call * \param context a #GPContext * * Tries to detect any camera connected to the computer using the supplied * list of supported cameras and the supplied info_list of ports. * * \return a gphoto2 error code */ int gp_abilities_list_detect (CameraAbilitiesList *list, GPPortInfoList *info_list, CameraList *l, GPContext *context) { GPPortInfo info; GPPort *port; int i, info_count; CHECK_NULL (list && info_list && l); gp_list_reset (l); CHECK_RESULT (info_count = gp_port_info_list_count (info_list)); CHECK_RESULT (gp_port_new (&port)); for (i = 0; i < info_count; i++) { int res; char *xpath; GPPortType type; CHECK_RESULT (gp_port_info_list_get_info (info_list, i, &info)); CHECK_RESULT (gp_port_set_info (port, info)); gp_port_info_get_type (info, &type); res = gp_port_info_get_path (info, &xpath); if (res <GP_OK) continue; switch (type) { case GP_PORT_USB: case GP_PORT_USB_SCSI: case GP_PORT_USB_DISK_DIRECT: { int ability; res = gp_abilities_list_detect_usb (list, &ability, port); if (res == GP_OK) { gp_list_append(l, list->abilities[ability].model, xpath); } else if (res < 0) gp_port_set_error (port, NULL); break; } case GP_PORT_DISK: { char *s, path[1024]; struct stat stbuf; s = strchr (xpath, ':'); if (!s) break; s++; snprintf (path, sizeof(path), "%s/DCIM", s); if (-1 == stat(path, &stbuf)) { snprintf (path, sizeof(path), "%s/dcim", s); if (-1 == stat(path, &stbuf)) continue; } gp_list_append (l, "Mass Storage Camera", xpath); break; } case GP_PORT_PTPIP: { char *s; s = strchr (xpath, ':'); if (!s) break; s++; if (!strlen(s)) break; gp_list_append (l, "PTP/IP Camera", xpath); break; } default: /* * We currently cannot detect any cameras on this * port */ break; } } gp_port_free (port); return (GP_OK); }
bool GPCamera::findConnectedUsbCamera(int vendorId, int productId, QString& model, QString& port) { #ifdef HAVE_GPHOTO2 CameraAbilitiesList* abilList = 0; GPPortInfoList* list = 0; GPContext* context = 0; CameraList* camList = 0; bool success = false; // get name and port of detected camera const char* model_str = 0; const char* port_str = 0; context = gp_context_new(); // get list of all ports gp_port_info_list_new(&list); gp_port_info_list_load(list); gp_abilities_list_new(&abilList); // get list of all supported cameras gp_abilities_list_load(abilList, context); // autodetect all cameras, then match the list to the passed in USB ids gp_list_new (&camList); gp_abilities_list_detect(abilList, list, camList, context); gp_context_unref(context); int count = gp_list_count(camList); int cnt = 0; for (int i = 0 ; i < count ; i++) { const char* xmodel = 0; gp_list_get_name(camList, i, &xmodel); int model = gp_abilities_list_lookup_model (abilList, xmodel); CameraAbilities ab; gp_abilities_list_get_abilities(abilList, model, &ab); if (ab.port != GP_PORT_USB) continue; /* KDE provides us USB Vendor and Product, but we might just * have covered this via a class match. Check class matched * cameras also for matchingo USB vendor/product id */ if (ab.usb_vendor == 0) { int ret; GPPortInfo info; const char* xport = 0; GPPort* gpport = 0; /* get the port path so we only look at this bus position */ gp_list_get_value(camList, i, &xport); ret = gp_port_info_list_lookup_path (list, xport); if (ret < GP_OK) /* should not happen */ continue; /* get the lowlevel port info for the path */ gp_port_info_list_get_info(list, ret, &info); /* open lowlevel driver interface briefly to search */ gp_port_new(&gpport); gp_port_set_info(gpport, info); /* And now call into the lowlevel usb driver to see if the bus position * has that specific vendor/product id */ if (gp_port_usb_find_device(gpport, vendorId, productId) == GP_OK) { ab.usb_vendor = vendorId; ab.usb_product = productId; } gp_port_free (gpport); } if (ab.usb_vendor != vendorId) continue; if (ab.usb_product != productId) continue; /* keep it, and continue iterating, in case we find another one */ gp_list_get_name (camList, i, &model_str); gp_list_get_value(camList, i, &port_str); cnt++; } gp_port_info_list_free(list); gp_abilities_list_free(abilList); if (cnt > 0) { if (cnt > 1) { qCWarning(DIGIKAM_IMPORTUI_LOG) << "More than one camera detected on port " << port << ". Due to restrictions in the GPhoto2 API, " << "only the first camera is used."; } model = QString::fromLatin1(model_str); port = QString::fromLatin1(port_str); success = true; } else { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get information for the listed camera"; } gp_list_free(camList); return success; #else Q_UNUSED(vendorId); Q_UNUSED(productId); Q_UNUSED(model); Q_UNUSED(port); return false; #endif /* HAVE_GPHOTO2 */ }