Пример #1
0
 std::vector<std::shared_ptr<device>> query_devices(std::shared_ptr<context> context)
 {
     std::vector<std::shared_ptr<device>> devices;
     
     uvc_device_t ** list;
     CALL_UVC(uvc_get_device_list, context->ctx, &list);
     for(auto it = list; *it; ++it) try {
         devices.push_back(std::make_shared<device>(context, *it));
     } catch(std::runtime_error &e) {
         LOG_WARNING("usb:" << (int)uvc_get_bus_number(*it) << ':' <<
                 (int)uvc_get_device_address(*it) << ": " << e.what());
     }
     uvc_free_device_list(list, 1);
     return devices;
 }
Пример #2
0
            static void foreach_uvc_device(uvc_context_t *ctx,
                    std::function<void(
                            const uvc_device_info &info,
                                       const std::string&)> action)
            {
                uvc_error_t res;
                uvc_device_t **device_list;
                uvc_device_internal *dev;
                uvc_device_info info;
                uvc_device_descriptor_t *device_desc;

                // get all uvc devices.
                res = uvc_get_device_list(ctx, &device_list);

                if (res < 0) {
                    throw linux_backend_exception("fail to get uvc device list.");
                }

                int i = 0;
                // iterate over all devices.
                while (device_list[i] != NULL) {
                    // get the internal device object so we can use the libusb handle.
                    dev = (uvc_device_internal *) device_list[i];
                    // set up the unique id for the device.
                    info.unique_id = get_usb_port_id(dev->usb_dev);

                    // get device descriptor.
                    res = uvc_get_device_descriptor((uvc_device_t *)dev, &device_desc);
                    if ( res < 0) {
                        uvc_free_device_list(device_list, 0);
                        throw linux_backend_exception("fail to get device descriptor");
                    }

                    // set up device definitions.
                    info.pid = device_desc->idProduct;
                    info.vid = device_desc->idVendor;
                    info.mi = dev->interface-1;

                    uvc_free_device_descriptor(device_desc);

                    // declare this device to the caller.
                    action(info, "Intel Camera");

                    // this code was used for the sr300 version.
/*                    libusb_config_descriptor *config;
                    int status = libusb_get_active_config_descriptor(dev->usb_dev, &config);

                    if (config->bNumInterfaces >= 2)
                    {
                        info.mi = 2;
                        action(info, "depth");
                    }

                    libusb_free_config_descriptor(config);*/

                    i++;

                }
                uvc_free_device_list(device_list, 0);

            }