Пример #1
0
bool SSAG::Connect(bool bootload) {
  if ((this->handle = libusb_open_device_with_vid_pid(ctx, SSAG_VENDOR_ID, SSAG_PRODUCT_ID)) == NULL) {
    if (bootload) {
      Loader *loader = new Loader();
      if (loader->Connect()) {
        if (!loader->LoadFirmware()) {
          DBG("Failed to upload firmware to the device");
          return false;
        }
        loader->Disconnect();
        for (int i = 0; i < RENUMERATE_TIMEOUT; i++) {
          if (this->Connect(false))
            return true;
          sleep(1);
        }
        DBG("Device did not renumerate. Timed out.");
        return false;
      } else {
        DBG("Failed to connect loader");
        return false;
      }
    } else {
      return false;
    }
  }
  
  int rc;
  if (libusb_kernel_driver_active(this->handle, 0) == 1) {
    rc = libusb_detach_kernel_driver(this->handle, 0);
    if (rc < 0) {
      DBG("Can't detach kernel driver (%d)", rc);
    }
  }
  
  rc = libusb_set_configuration(this->handle, 1);
  if (rc < 0) {
    DBG("Can't set configuration (%d)", rc);
  }

  rc = libusb_claim_interface(this->handle, 0);
  if (rc < 0) {
    DBG("Can't claim interface (%d)", rc);
  }
  
  this->SetBufferMode();
  this->SetGain(1);
  this->InitSequence();
  
  return true;
}
Пример #2
0
bool SSAG::Connect(bool bootload)
{
    if (!usb_open_device(&this->handle, SSAG_VENDOR_ID, SSAG_PRODUCT_ID, NULL)) {
        if (bootload) {
            Loader *loader = new Loader();
            if (loader->Connect()) {
                if (!loader->LoadFirmware()) {
                    fprintf(stderr, "ERROR:  Failed to upload firmware to the device\n");
                    return false;
                }
                loader->Disconnect();
                for (time_t t = time(NULL) + RENUMERATE_TIMEOUT; time(NULL) < t;) {
                    DBG("Checking if camera has renumerated...");
                    if (EnumerateDevices()) {
                        DBG("Yes\n");
                        return this->Connect(false);
                    }
                    DBG("No\n");
                    sleep(1);
                }
                DBG("ERROR:  Device did not renumerate. Timed out.\n");
                /* Timed out */
                return false;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    this->SetBufferMode();
    this->SetGain(1);
    this->InitSequence();

    return true;
}