コード例 #1
0
void HMDDeviceEnumerator::build_interface_list()
{
    USBDeviceInfo &dev_info = g_supported_hmd_infos[GET_DEVICE_TYPE_INDEX(m_deviceType)];
    hid_device_info * devs = hid_enumerate(dev_info.vendor_id, dev_info.product_id);

    current_device_identifier = "";
    current_device_interfaces.clear();

    if (devs != nullptr)
    {
        std::stringstream device_id_builder;
        device_id_builder <<
                          "USB\\VID_" << std::hex << std::setfill('0') << std::setw(4) << dev_info.vendor_id <<
                          "&PID_" << std::hex << std::setfill('0') << std::setw(4) << dev_info.product_id;

        current_device_identifier = device_id_builder.str();

        for (hid_device_info *cur_dev = devs; cur_dev != nullptr; cur_dev = cur_dev->next)
        {
            HMDDeviceInterface hmd_interface;

            hmd_interface.device_path = cur_dev->path;
            hmd_interface.interface_number = cur_dev->interface_number;

            current_device_interfaces.push_back(hmd_interface);
        }

        hid_free_enumeration(devs);
    }
}
コード例 #2
0
ファイル: hid-libusb.c プロジェクト: Tsgzj/new-keyboard
hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, wchar_t *serial_number)
{
	struct hid_device_info *devs, *cur_dev;
	const char *path_to_open = NULL;
	hid_device *handle = NULL;
	
	devs = hid_enumerate(vendor_id, product_id);
	cur_dev = devs;
	while (cur_dev) {
		if (cur_dev->vendor_id == vendor_id &&
		    cur_dev->product_id == product_id) {
			if (serial_number) {
				if (wcscmp(serial_number, cur_dev->serial_number) == 0) {
					path_to_open = cur_dev->path;
					break;
				}
			}
			else {
				path_to_open = cur_dev->path;
				break;
			}
		}
		cur_dev = cur_dev->next;
	}

	if (path_to_open) {
		/* Open the device */
		handle = hid_open_path(path_to_open);
	}

	hid_free_enumeration(devs);
	
	return handle;
}
コード例 #3
0
ファイル: device.c プロジェクト: niranjandighe/linux-mfg-tool
int check_target_device(unsigned int vid, unsigned int pid)
{

	assert((0xffff0000 & vid) == 0);
	assert((0xffff0000 & pid) == 0);

	dev = hid_enumerate((unsigned short)vid, (unsigned short)pid);
	if (dev) {

		target = hid_open_path(dev->path);
		DBG_INFO("%s", dev->path);
		if (target == NULL) {
			perror("Error");
			return -1;
		}

		printf("Device Info -\n");
		printf("\tManufacturer: %ls\n", dev->manufacturer_string);
		printf("\tProduct: %ls\n", dev->product_string);
		printf("\tVendor ID: %x, Product ID: %x\n", dev->vendor_id, dev->product_id);
		printf("\tSerial Number: %ls\n", dev->serial_number);

		return 0;
	}

	return -1;
}
コード例 #4
0
ファイル: hidapi.cpp プロジェクト: PML369/qlcplus
hid_device * HID_API_EXPORT hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
{
    /* This function is identical to the Linux version. Platform independent. */
    struct hid_device_info *devs, *cur_dev;
    const char *path_to_open = NULL;
    hid_device * handle = NULL;

    devs = hid_enumerate(vendor_id, product_id);
    cur_dev = devs;
    while (cur_dev) {
        if (cur_dev->vendor_id == vendor_id &&
            cur_dev->product_id == product_id) {
            if (serial_number) {
                if (wcscmp(serial_number, cur_dev->serial_number) == 0) {
                    path_to_open = cur_dev->path;
                    break;
                }
            }
            else {
                path_to_open = cur_dev->path;
                break;
            }
        }
        cur_dev = cur_dev->next;
    }

    if (path_to_open) {
        /* Open the device */
        handle = hid_open_path(path_to_open);
    }

    hid_free_enumeration(devs);

    return handle;
}
コード例 #5
0
/**********************************************************
 * Function detect_relay_card_hidapi()
 * 
 * Description: Detect the HID API compatible relay card
 * 
 * Parameters: portname (out) - pointer to a string where
 *                              the detected com port will
 *                              be stored
 *             num_relays(out)- pointer to number of relays
 * 
 * Return:  0 - success
 *         -1 - fail, no relay card found
 *********************************************************/
int detect_relay_card_hidapi(char* portname, uint8* num_relays)
{
   struct hid_device_info *devs;
   uint8 num;
   
   if ((devs = hid_enumerate(VENDOR_ID, DEVICE_ID)) == NULL)
   {
      return -1;  
   }

   if (devs->product_string == NULL ||
       devs->path == NULL)
   {
      return -1;
   }
   
   //printf("DBG: card %ls found\n", devs->product_string);
   
   /* Get number of relays from product description */
   num = atoi((const char *)(devs->product_string+strlen(PRODUCT_STR_BASE)));
   if (num>0)
   {
      g_num_relays = num;
   }

   /* Return parameters */
   if (num_relays!=NULL) *num_relays = g_num_relays;
   sprintf(portname, "%s", devs->path);
  
   hid_free_enumeration(devs);   
   return 0;
}
コード例 #6
0
ファイル: libambit.c プロジェクト: natanojl/openambit
/*
 * Public functions
 */
ambit_device_info_t * libambit_enumerate(void)
{
    ambit_device_info_t *devices = NULL;

    struct hid_device_info *devs = hid_enumerate(0, 0);
    struct hid_device_info *current;

    if (!devs) {
      LOG_WARNING("HID: no USB HID devices found");
      return NULL;
    }

    current = devs;
    while (current) {
        ambit_device_info_t *tmp = ambit_device_info_new(current);

        if (tmp) {
            if (devices) {
                tmp->next = devices;
            }
            else {
                devices = tmp;
            }
        }
        current = current->next;
    }
    hid_free_enumeration(devs);

    return devices;
}
コード例 #7
0
ファイル: dbg_mac.c プロジェクト: arv3/edbg
//-----------------------------------------------------------------------------
int dbg_enumerate(debugger_t *debuggers, int size) 
{
  struct hid_device_info *devs, *cur_dev;
  int rsize = 0;

  if (hid_init())
    return 0;

  devs = hid_enumerate(0, 0);
  cur_dev = devs;	

  for (cur_dev = devs; cur_dev && rsize < size; cur_dev = cur_dev->next)
  {
    debuggers[rsize].path = strdup(cur_dev->path);
    debuggers[rsize].serial = cur_dev->serial_number ? wcstombsdup(cur_dev->serial_number) : "<unknown>";
    debuggers[rsize].wserial = cur_dev->serial_number ? wcsdup(cur_dev->serial_number) : NULL;
    debuggers[rsize].manufacturer = cur_dev->manufacturer_string ? wcstombsdup(cur_dev->manufacturer_string) : "<unknown>";
    debuggers[rsize].product = cur_dev->product_string ? wcstombsdup(cur_dev->product_string) : "<unknown>";
    debuggers[rsize].vid = cur_dev->vendor_id;
    debuggers[rsize].pid = cur_dev->product_id;

    if (strstr(debuggers[rsize].product, "CMSIS-DAP"))
      rsize++;
  }

  hid_free_enumeration(devs);

  return rsize;
}
コード例 #8
0
/*---------------------------------------------------------------------------*/
int t100::searchDevices()
{ 
  // Enumerate and print the HID devices on the system
  struct hid_device_info *devs, *cur_dev;

  t100_totalDevices = 0;
  
  devs = hid_enumerate(0x0, 0x0);
  cur_dev = devs; 
  while (cur_dev) 
  { 
    if((cur_dev->vendor_id == VID) && (cur_dev->product_id == PID))
    {     
      #if WIN
      t100_deviceSerials[t100_totalDevices] = _wcstoui64(cur_dev->serial_number,NULL,0);
      #else
      t100_deviceSerials[t100_totalDevices] = wcstoul(cur_dev->serial_number,NULL,0);
      #endif
      t100_totalDevices++;
    }   
    cur_dev = cur_dev->next;
  }
  hid_free_enumeration(devs);

  return t100_totalDevices;
}
コード例 #9
0
ファイル: gui-dialog-print.c プロジェクト: bert/pcb-update
void
ghid_dialog_export (void)
{
  GtkWidget *vbox, *button;
  GHidPort *out = &ghid_port;
  int i;
  HID **hids;
  GtkTooltips *tips;
  gboolean no_exporter = TRUE;

  tips = gtk_tooltips_new ();

  export_dialog = gtk_dialog_new_with_buttons (_("PCB Export Layout"),
					       GTK_WINDOW (out->top_window),
					       GTK_DIALOG_MODAL
					       |
					       GTK_DIALOG_DESTROY_WITH_PARENT,
					       GTK_STOCK_CANCEL,
					       GTK_RESPONSE_CANCEL, NULL);
  gtk_window_set_wmclass (GTK_WINDOW (export_dialog), "PCB_Export", "PCB");

  vbox = gtk_vbox_new (FALSE, 6);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (export_dialog)->vbox), vbox);

  /* 
   * Iterate over all the export HID's and build up a dialog box that
   * lets us choose which one we want to use.
   * This way, any additions to the exporter HID's automatically are
   * reflected in this dialog box.
   */

  hids = hid_enumerate ();
  for (i = 0; hids[i]; i++)
    {
      if (hids[i]->exporter)
	{
	  no_exporter = FALSE;
	  button = gtk_button_new_with_label (hids[i]->name);
	  gtk_tooltips_set_tip (tips, button, hids[i]->description, NULL);
	  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
	  g_signal_connect (G_OBJECT (button), "clicked",
			    G_CALLBACK (exporter_clicked_cb), hids[i]);
	}
    }

  if (no_exporter)
    {
      gui->log (_("Can't find a suitable exporter HID"));
    }

  gtk_widget_show_all (export_dialog);
  gtk_dialog_run (GTK_DIALOG (export_dialog));

  if (export_dialog != NULL)
    gtk_widget_destroy (export_dialog);
  export_dialog = NULL;
}
コード例 #10
0
void Comm::PollUSB()
{
    hid_device_info *dev;

    dev = hid_enumerate(VID, PID);

    connected = (dev != NULL);
    hid_free_enumeration(dev);
}
コード例 #11
0
ファイル: touchmouse.c プロジェクト: zarvox/libtouchmouse
// Enumeration.
touchmouse_device_info* touchmouse_enumerate_devices(void)
{
	TM_SPEW("touchmouse_enumerate_devices: Enumerating HIDAPI devices\n");
	touchmouse_device_info* retval = NULL;
	touchmouse_device_info** prev_next_pointer = &retval;
	struct hid_device_info *devs, *cur_dev;
	// Get list of HID devices that match VendorID/ProductID
	devs = hid_enumerate(0x045e, 0x0773); // 0x045e = Microsoft, 0x0773 = TouchMouse
	cur_dev = devs;
	while(cur_dev) {
		TM_DEBUG("Examining device: %s\n", cur_dev->path);
		TM_SPEW("\tVendor  ID: %04x\n", cur_dev->vendor_id);
		TM_SPEW("\tProduct ID: %04x\n", cur_dev->product_id);
		TM_SPEW("\tSerial num: %ls\n", cur_dev->serial_number);
		TM_SPEW("\tRelease #:  %d\n", cur_dev->release_number);
		TM_SPEW("\tManuf. Str: %ls\n", cur_dev->manufacturer_string);
		TM_SPEW("\tProd.  Str: %ls\n", cur_dev->product_string);
		TM_SPEW("\tUsage Page: %02x\n", cur_dev->usage_page);
		TM_SPEW("\tUsage     : %02x\n", cur_dev->usage);
		TM_SPEW("\tInterface:  %d\n", cur_dev->interface_number);
#ifdef __APPLE__
		// This method of detection should work on both OSX and Windows.
		if (cur_dev->usage_page == 0x0c && cur_dev->usage == 0x01)
#else
		// This method of detection should work on Linux and Windows.
		// Pity there's no single way to uniquely ID the device.
		if (cur_dev->interface_number == 2)
#endif
		{
			TM_DEBUG("Found TouchMouse: %s\n", cur_dev->path);
			*prev_next_pointer = (touchmouse_device_info*)malloc(sizeof(touchmouse_device_info));
			memset(*prev_next_pointer, 0, sizeof(**prev_next_pointer));
			TM_FLOOD("Allocated a touchmouse_device_info at address %p\n", *prev_next_pointer);
			// We need to save both the pointer to this particular hid_device_info
			// as well as the one from which it was initially allocated, so we can
			// free it.
			// Perhaps this would be better placed in a statically allocated list...
			struct hid_device_info** pair = (struct hid_device_info**)malloc(2*sizeof(struct hid_device_info*));
			TM_FLOOD("Allocated two hid_device_info* at address %p\n", pair);
			(*prev_next_pointer)->opaque = (void*)pair;
			pair[0] = cur_dev;
			pair[1] = devs;
			prev_next_pointer = &((*prev_next_pointer)->next);
		}
		cur_dev = cur_dev->next;
	}
	// If we're about to return NULL, then we'd better free the HID enumeration
	// handles now, since we'll get no data from the user when they call
	// touchmouse_free_enumeration(NULL)
	if (!retval) {
		TM_FLOOD("Found no devices, so calling hid_free_enumeration()\n");
		hid_free_enumeration(devs);
	}
	return retval;
}
コード例 #12
0
ファイル: SC_HID_api.cpp プロジェクト: ASauer/supercollider
int SC_HID_APIManager::build_devicelist(){
	struct hid_device_info *cur_dev;
	devinfos = hid_enumerate(0x0, 0x0);

	cur_dev = devinfos;
	int count = 0;
	while (cur_dev) {
		count++;
		cur_dev = cur_dev->next;
	}
	return count;
}
コード例 #13
0
ファイル: HIDDeviceList.cpp プロジェクト: elafarge/HmIdiD
HIDDeviceList::HIDDeviceList() : mDevices(){
    struct hid_device_info *cDev;
        
    mApiDevices = hid_enumerate(0x0, 0x0);

    for(cDev = mApiDevices; cDev; cDev = cDev->next){
        if(cDev->serial_number && !cDev->product_string){
            std::cout << "One device hasn't been opened because the current user doesn't have permission to access it." << std::endl;
        } else {
            mDevices.push_back(HIDDevice(cDev));
        }
    }

}
コード例 #14
0
ファイル: hidplugin.cpp プロジェクト: PML369/qlcplus
void HIDPlugin::rescanDevices()
{
    /* Treat all devices as dead first, until we find them again. Those
       that aren't found, get destroyed at the end of this function. */
    QList <HIDDevice*> destroyList(m_devices);
    int devCount = m_devices.count();

    struct hid_device_info *devs, *cur_dev;
    quint32 line = 0;

    devs = hid_enumerate(0x0, 0x0);

    cur_dev = devs;

    while (cur_dev)
    {
        //qDebug() << "[HID Device found] path:" << QString(cur_dev->path) << ", name:" << QString::fromWCharArray(cur_dev->product_string);

        HIDDevice* dev = device(QString(cur_dev->path));
        if (dev != NULL)
        {
            /** Device already exists, delete from remove list */
            destroyList.removeAll(dev);
        }
        else if((cur_dev->vendor_id == HID_DMX_INTERFACE_VENDOR_ID
                && cur_dev->product_id == HID_DMX_INTERFACE_PRODUCT_ID) ||
                (cur_dev->vendor_id == HID_DMX_INTERFACE_VENDOR_ID_2
                && cur_dev->product_id == HID_DMX_INTERFACE_PRODUCT_ID_2) ||
                (cur_dev->vendor_id == HID_DMX_INTERFACE_VENDOR_ID_3
                && cur_dev->product_id == HID_DMX_INTERFACE_PRODUCT_ID_3))
        {
            /* Device is a USB DMX Interface, add it */
            dev = new HIDDMXDevice(this, line++,
                                   QString::fromWCharArray(cur_dev->manufacturer_string) + " " +
                                   QString::fromWCharArray(cur_dev->product_string),
                                   QString(cur_dev->path));
            addDevice(dev);
        }
#if defined(Q_WS_X11) || defined(Q_OS_LINUX)
        else if (QString(cur_dev->path).contains("js"))
        {
            dev = new HIDLinuxJoystick(this, line++, cur_dev);
#elif defined(WIN32) || defined (Q_OS_WIN)
        else if(HIDWindowsJoystick::isJoystick(cur_dev->vendor_id, cur_dev->product_id) == true)
        {
            dev = new HIDWindowsJoystick(this, line++, cur_dev);
#elif defined (__APPLE__) || defined(Q_OS_MACX)
        else if(HIDOSXJoystick::isJoystick(cur_dev->usage) == true)
コード例 #15
0
ファイル: main.cpp プロジェクト: STwilight/Smart-Control
void __fastcall TForm1::deviceConnect(TObject *Sender)
{
	/* Метод поиска и подключения необходимого HID-устройства */

	// Структура для поиска HID-устройств
	struct hid_device_info *devs, *cur_dev;

	// Установка отметки "Searching"
	Button3->ImageIndex = 0;
	// Вывод статуса
	Label2->Text = "Поиск устройства...";

	// Запуск поиска HID-устройства
	devs = hid_enumerate(VID, PID);

	// Помещение найденных устройств с указанными VID и PID в динамический массив
	cur_dev = devs;

	/* Поиск устройства по строке описания продукта 'Product Name' */
	while (cur_dev) {
		if ((cur_dev->product_string) == productString)
			break;
		cur_dev = cur_dev->next;
	}

	/* Если устройство найдено и успешно открыто... */
	if (cur_dev && (handle_device = hid_open_path(cur_dev->path)))
	{
		// Остановка таймера, который вызывает данный метод
		Timer1->Enabled = false;
		// Установка отметки "Connected"
		Button3->ImageIndex = 1;
		// Вывод статуса
		Label2->Text = "Устройство подключено";
	}
	else
	{
		// Установка отметки "Disconnected"
		Button3->ImageIndex = 0;
		//Button3->ImageIndex = 2;
		// Вывод статуса
		Label2->Text = "Поиск устройства...";
		//Label2->Text = "Устройство не найдено";
	}

	// Удаление списка
	hid_free_enumeration(devs);
}
コード例 #16
0
void USBInterface::EnumerateHIDs()
{
    Devs = hid_enumerate(0x0, 0x0);
	CurDev = Devs;	
	while (CurDev) {
		printf("Device Found\n  type: %04hx %04hx\n  path: %s\n  serial_number: %ls",
			CurDev->vendor_id, CurDev->product_id, CurDev->path, CurDev->serial_number);
		printf("\n");
		printf("  Manufacturer: %ls\n", CurDev->manufacturer_string);
		printf("  Product:      %ls\n", CurDev->product_string);
		printf("\n");
		CurDev = CurDev->next;
	}
	hid_free_enumeration(Devs);     
     
}
コード例 #17
0
ControllerDeviceEnumerator::ControllerDeviceEnumerator(CommonDeviceState::eDeviceType deviceType)
    : DeviceEnumerator(deviceType)
    , devs(nullptr)
    , cur_dev(nullptr)
{
    assert(m_deviceType >= 0 && GET_DEVICE_TYPE_INDEX(m_deviceType) < MAX_CONTROLLER_TYPE_INDEX);

    USBDeviceInfo &dev_info = g_supported_controller_infos[GET_DEVICE_TYPE_INDEX(m_deviceType)];
    devs = hid_enumerate(dev_info.vendor_id, dev_info.product_id);
    cur_dev = devs;

    if (!is_valid())
    {
        next();
    }
}
コード例 #18
0
//-----------------------------------------------------------------------------
bool HIDDeviceManager::Enumerate(HIDEnumerateVisitor* enumVisitor)
{
    if (!initializeManager())
    {
        return false;
    }
    // Enumerate and print the HID devices on the system
	struct hid_device_info *devs, *cur_dev;

	devs = hid_enumerate(0x0, 0x0);
	cur_dev = devs;
	while (cur_dev) {

		// Check the VID/PID for a match
		if(enumVisitor->MatchVendorProduct(cur_dev->vendor_id, cur_dev->product_id))
		{
			HIDDeviceDesc devDesc;
			devDesc.Path = String(cur_dev->path);
			getFullDesc(cur_dev, &devDesc);

			// Look for the device to check if it is already opened.
			Ptr<DeviceCreateDesc> existingDevice = DevManager->FindHIDDevice(devDesc, true);
			// if device exists and it is opened then most likely the device open()
			// will fail; therefore, we just set Enumerated to 'true' and continue.
			if (existingDevice && existingDevice->pDevice)
			{
				existingDevice->Enumerated = true;
			}
			else
			{
				//libusb does not support 'minimal'

				Linux::HIDDevice device(this);
				device.openDevice(devDesc.Path.ToCStr());
				enumVisitor->Visit(device, devDesc);
				device.closeDevice(false);
			}
		}

		cur_dev = cur_dev->next;
	}

	hid_free_enumeration(devs);

    return true;
}
コード例 #19
0
int main()
{
    hid_init();

    struct hid_device_info *hid_dev = hid_enumerate(0, 0);
    while (hid_dev) {
        std::printf("HID device: VID=%x PID=%x Path=%s Product string: \"%S\"\n",
                    hid_dev->vendor_id,
                    hid_dev->product_id,
                    hid_dev->path,
                    hid_dev->product_string);
        hid_dev = hid_dev->next;
    }

    hid_exit();
    return 0;
}
コード例 #20
0
/*
    PSYCHHIDCheckInit() 
    
    Check to see if we need to create the USB-HID device list. If it has not been created then create it.   
*/
void PsychHIDVerifyInit(void)
{
    int busId, devId, intId;
    pRecDevice currentDevice = NULL;
    struct hid_device_info* hid_dev = NULL;
    
    // If hid_devices list of all HID devices not yet initialized,
    // perform device enumeration:
    if (!hidlib_devices) {        
        // Low-Level enumeration by HIDLIB:
        hidlib_devices = hid_enumerate(0x0, 0x0);
        
        // Build our own higher-level device list filled with info
        // from the low-level list:
        for (hid_dev = hidlib_devices; hid_dev != NULL; hid_dev = hid_dev->next) {
            // Allocate and zero-init high level struct currentDevice:
            currentDevice = calloc(1, sizeof(recDevice));
            
            // Copy low-level props to corresponding high-level props:
            currentDevice->usagePage = hid_dev->usage_page;
            currentDevice->usage = hid_dev->usage;
            // Abuse the "transport" string for the device path. On OS/X this just contains "USB":
            sprintf(&currentDevice->transport[0], "%s", hid_dev->path);
            currentDevice->vendorID = hid_dev->vendor_id;
            currentDevice->productID = hid_dev->product_id;
            currentDevice->version = hid_dev->release_number;
            if (hid_dev->manufacturer_string) wcstombs(&currentDevice->manufacturer[0], hid_dev->manufacturer_string, 256);
            if (hid_dev->product_string) wcstombs(&currentDevice->product[0], hid_dev->product_string, 256);
            if (hid_dev->serial_number) wcstombs(&currentDevice->serial[0], hid_dev->serial_number, 256);

            // Convert unique device path into unique numeric location id:
            sscanf(hid_dev->path, "%x:%x:%x", &busId, &devId, &intId);
            currentDevice->locID = (double) ((busId << 24) + (devId << 8) + intId);

            // Interface number is great for identifying DAQ devices, but not available
            // on OS/X, so this will be a Linux/Windows only thing.
            currentDevice->interfaceId = hid_dev->interface_number;

            // Enqueue record into linked list:
            currentDevice->pNext = hid_devices;
            hid_devices = currentDevice;
        }
    }
    
    return;
}
コード例 #21
0
ファイル: PSMoveManager.cpp プロジェクト: Hadron/psmovesender
void PSMoveManager::ConnectAll ()
{
  struct hid_device_info *devs, *cur;
  devs = hid_enumerate (PSMOVE_VID, PSMOVE_PID);

  for (auto w : m_wands) {
    w.second.flag = false;
  }

  uint64_t addr;

  for (cur = devs; cur != NULL; cur = cur->next) {
    /* Only consider Bluetooth devices. */
    
    if ((cur->serial_number == NULL) || (wcslen (cur->serial_number) == 0)) {
      continue;
    }

    uint64_t addr = parse_btaddr (cur->serial_number);
    if (addr == INVALID_BTADDR) { continue; }

    MoveRecord &record = FindOrCreateRecord (addr);
    record.flag = true;

    if (record.controller != NULL) { continue; }

    record.id = AvailableID ();
    PSMove *move = psmove_connect_internal (cur->serial_number, cur->path, record.id);
    if (move == NULL) { abort (); }
    record.controller = CreateController (move, record.id);
    record.controller->Bind (this);
    record.flag = true;

    SetupController (record.controller);
  }

  hid_free_enumeration (devs);

  auto w = m_wands.begin ();
  while (w != m_wands.end ()) {
    auto cur = w++;
    if (cur->second.flag) { continue; }
    delete cur->second.controller;
    m_wands.erase (cur);
  }
}
コード例 #22
0
ファイル: hidenumerator.cpp プロジェクト: Alppasa/mixxx
QList<Controller*> HidEnumerator::queryDevices() {
    qDebug() << "Scanning HID devices:";

    struct hid_device_info *devs, *cur_dev;
    devs = hid_enumerate(0x0, 0x0);

    for (cur_dev = devs; cur_dev; cur_dev = cur_dev->next) {
        if (isDeviceBlacklisted(cur_dev)) {
            // OS/X and windows use usage_page/usage not interface_number
            qDebug() << "Blacklisting"
                     << HidController::safeDecodeWideString(cur_dev->manufacturer_string, 512)
                     << HidController::safeDecodeWideString(cur_dev->product_string, 512)
                     << QString("r%1").arg(cur_dev->release_number)
                     << "S/N" << HidController::safeDecodeWideString(cur_dev->serial_number, 512)
                     << (cur_dev->interface_number == -1 ? QString("Usage Page %1 Usage %2").arg(
                         QString::number(cur_dev->usage_page),
                         QString::number(cur_dev->usage)) :
                         QString("Interface %1").arg(cur_dev->interface_number));
            continue;
        }

        // OS/X and windows use usage_page/usage not interface_number
        qDebug() << "Found"
                 << HidController::safeDecodeWideString(cur_dev->manufacturer_string, 512)
                 << HidController::safeDecodeWideString(cur_dev->product_string, 512)
                 << QString("r%1").arg(cur_dev->release_number)
                 << "S/N" << HidController::safeDecodeWideString(cur_dev->serial_number, 512)
                 << (cur_dev->interface_number == -1 ? QString("Usage Page %1 Usage %2").arg(
                     QString::number(cur_dev->usage_page),
                     QString::number(cur_dev->usage)) :
                     QString("Interface %1").arg(cur_dev->interface_number));

        if (!cur_dev->serial_number && !cur_dev->product_string) {
            qWarning() << "USB permissions problem (or device error.) Your account needs write access to USB HID controllers.";
            continue;
        }

        HidController* currentDevice = new HidController(*cur_dev);
        m_devices.push_back(currentDevice);
    }
    hid_free_enumeration(devs);

    return m_devices;
}
コード例 #23
0
ファイル: usb.cpp プロジェクト: dgrover/LightCrafter
int USB_Open(int id)
{
    // Open the device using the VID, PID,
    // and optionally the Serial number.
	struct hid_device_info *devs, *cur_dev;

	devs = hid_enumerate(MY_VID, MY_PID);
	cur_dev = devs;
	
	int i = 0;

	while (cur_dev) {

		if (wcscmp(cur_dev->product_string, L"DDP442X") == 0)
		{
			if (i == id)
				DeviceHandle = hid_open_path(cur_dev->path);

			printf("Device Found\n  type: %04hx %04hx\n  path: %s\n  serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
			printf("\n");
			printf("  Manufacturer: %ls\n", cur_dev->manufacturer_string);
			printf("  Product:      %ls\n", cur_dev->product_string);
			printf("  Release:      %hx\n", cur_dev->release_number);
			printf("  Interface:    %d\n", cur_dev->interface_number);
			printf("\n");

			i++;
		}

		cur_dev = cur_dev->next;
	}

	hid_free_enumeration(devs);
		
	//DeviceHandle = hid_open(MY_VID, MY_PID, NULL);
	
    if(DeviceHandle == NULL)
    {
        USBConnected = false;
        return -1;
    }
    USBConnected = true;
    return 0;
}
コード例 #24
0
int LedDeviceLightpackHidapi::open(const std::string & serialNumber)
{
	// initialize the usb context
	int error = hid_init();
	if (error != 0)
	{
		Error(_log, "Error while initializing the hidapi context");
		return -1;
	}
	Info("Hidapi initialized");

	// retrieve the list of usb devices
	hid_device_info * deviceList = hid_enumerate(0x0, 0x0);

	// iterate the list of devices
	for (hid_device_info * deviceInfo = deviceList; deviceInfo != nullptr; deviceInfo = deviceInfo->next)
	{
		// try to open and initialize the device
		error = testAndOpen(deviceInfo, serialNumber);

		if (error == 0)
		{
			// a device was sucessfully opened. break from list
			break;
		}
	}

	// free the device list
	hid_free_enumeration(deviceList);

	if (_deviceHandle == nullptr)
	{
		if (_serialNumber.empty())
		{
			Error(_log, "No Lightpack device has been found");
		}
		else
		{
			Error(_log, "No Lightpack device has been found with serial %s", _serialNumber);
		}
	}

	return _deviceHandle == nullptr ? -1 : 0;
}
コード例 #25
0
/*!
	Workaround for some usb interfaces (e.g. 310 or rf)
	which has not impl. a usb serial number but returns a very short string (0x0409):
	We ignore very short strings

	NOTE: We check the string ptr before because UnicodeConverter::convert not worked
	with "null ptr" / string with length 0!
*/
void UsbDriverEnumerator::enumerate()
{
	UsbHidRAII::instance();

	deviceInfos_.clear();

	struct hid_device_info* devs = hid_enumerate(0x0, 0x0);
	struct hid_device_info* iter = devs;

	while (iter)
	{
		const unsigned int vendor = iter->vendor_id;
		const unsigned int product = iter->product_id;

		if (match(vendor, product))
		{
			UsbDeviceInfo device(iter->path, vendor, product);
			if (iter->manufacturer_string)
			{
				std::string manufacturer;
				UnicodeConverter::convert(iter->manufacturer_string, manufacturer);
				device.setManufacturer(manufacturer);
			}
			if (iter->product_string)
			{
				std::string product;
				UnicodeConverter::convert(iter->product_string, product);
				device.setProduct(product);
			}
			if (iter->serial_number)
			{
				std::string serialNumber;
				UnicodeConverter::convert(iter->serial_number, serialNumber);
				if (serialNumber.size() > 3)
				{
					device.setSerialNumber(serialNumber);
				}
			}
			deviceInfos_.push_back(device);
		}
		iter = iter->next;
	}
	hid_free_enumeration(devs);
}
コード例 #26
0
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
{
	// TODO: Merge this functions with the Linux version. This function should be platform independent.
	struct hid_device_info *devs, *cur_dev;
	const char *path_to_open = NULL;
    hid_device *handle = NULL;

#ifdef STICK20_DEBUG
{ // For debugging
    char text[1000];
    sprintf(text,"hid_open: VID %04x PID %04x\n", vendor_id,product_id);
    DebugAppendText (text);
}
#endif

	devs = hid_enumerate(vendor_id, product_id);
	cur_dev = devs;
	while (cur_dev) {
		if (cur_dev->vendor_id == vendor_id &&
		    cur_dev->product_id == product_id) {
			if (serial_number) {
				if (wcscmp(serial_number, cur_dev->serial_number) == 0) {
					path_to_open = cur_dev->path;
					break;
				}
			}
			else {
				path_to_open = cur_dev->path;
				break;
			}
		}
		cur_dev = cur_dev->next;
	}

	if (path_to_open) {
		/* Open the device */
		handle = hid_open_path(path_to_open);
	}

	hid_free_enumeration(devs);
	
	return handle;
}
コード例 #27
0
ファイル: footswitch.c プロジェクト: a-b/footswitch
void init_pid(unsigned short vid, unsigned short pid) {
#ifdef OSX
    hid_init();
    dev = hid_open(vid, pid, NULL);
#else
    struct hid_device_info *info = NULL, *ptr = NULL;
    hid_init();
    info = hid_enumerate(vid, pid);
    ptr = info;
    while (ptr != NULL) {
        if (ptr->interface_number == 1) {
            dev = hid_open_path(ptr->path);
            break;
        }
        ptr = ptr->next;
    }
    hid_free_enumeration(info);
#endif
}
コード例 #28
0
ファイル: DaplugDongle.c プロジェクト: Bouikiouch/daplug-c
int DAPLUGCALL Daplug_getDongleList(Dongle_info *dil){

    struct hid_device_info *lh;

    int i=0;

    //Enumerate & initialize hid devices
    if(!(lh=hid_enumerate(HID_VID,HID_PID))){
        //fprintf(stderr,"\ngetDongleList(): No hid Dongle_info inserted !\n");
    }
    else{
        while(lh && (i<CON_DNG_MAX_NB)){

            //if Linux OS, pass to dongle second interface
            #ifdef __linux__
            lh=lh->next;
            #endif

            dil[i].type = HID_DEVICE;
            dil[i].path = (char*)lh->path;

            lh=lh->next;
            i++;
        }

        hid_free_enumeration(lh);
    }

    //Enumerate and initialize winusb devices
    winusb_device *wdl[CON_DNG_MAX_NB];
    int nb_wd = listWinusbDevices(wdl);
    int j = 0;
    if(nb_wd <= 0) return i;
    while(j < nb_wd && i < CON_DNG_MAX_NB){
        dil[i].type = WINUSB_DEVICE;
        dil[i].handle = (winusb_device *) wdl[j];
        j++;
        i++;
    }

    return i; //number of connected plug-ups
}
コード例 #29
0
HidDeviceInfos HidDevice::findDevices(
    uint16_t vendorId, uint16_t productId, const char* serialNumber,
    uint16_t usagePage, uint16_t usage)
{
    HidDeviceInfos results;
    struct hid_device_info* devs, * dev;
    devs = hid_enumerate(vendorId, productId);
    for(dev=devs; dev; dev=dev->next)
    {
//TODO: See if we can find out which HIDAPI implementation is in use, rather than just checking the platform
#ifdef _WIN32
        if(usagePage && usage)
            if((dev->usage_page != usagePage) || (dev->usage != usage))
                continue;
#endif
        std::string devSerialNumber;
        utf16BufferToUtf8String(devSerialNumber, dev->serial_number);
        std::string mfrString;
        utf16BufferToUtf8String(mfrString, dev->manufacturer_string);
        std::string productString;
        utf16BufferToUtf8String(productString, dev->product_string);
	uint8_t releaseHi = (dev->release_number & 0xFF00) >> 8;
	uint8_t releaseLo = dev->release_number & 0x00FF;
	std::string releaseNumber = (boost::format("%02d.%02d") % (int)releaseHi % (int)releaseLo).str();
        results.push_back(
            HidDeviceInfo(dev->vendor_id, dev->product_id, dev->usage_page,
                          dev->usage, mfrString, productString, devSerialNumber,
                          releaseNumber, dev->path));
    }
    hid_free_enumeration(devs);
    if(!serialNumber)
        return results;
    //TODO: Instead of copying into a new list, just delete from the original
    HidDeviceInfos matches;
    auto filterFn = [serialNumber](const HidDeviceInfo& devInfo)
    {
        return (!devInfo.serialNumber.compare(serialNumber));
    };
    std::copy_if(results.begin(), results.end(), std::back_inserter(matches),
                 filterFn);
    return matches;
}
コード例 #30
0
ファイル: ba6x.c プロジェクト: Ousret/BA6X-SAPI
int initializeDevice() {

  struct hid_device_info *devs, *cur_dev;
  const wchar_t targetManufacturer[] = L"Wincor Nixdorf";

  hid_init();
  /* Auto-detection du périphérique */
  //Wincor Nixdorf

	devs = hid_enumerate(0x0, 0x0);
	cur_dev = devs;

	while (cur_dev) {
    if (DEBUG) fprintf(stdout, "<Debug> Périphérique trouvé: %04hx %04hx - %ls - %s\n", cur_dev->vendor_id, cur_dev->product_id, cur_dev->manufacturer_string ,cur_dev->path);

    #if defined(__APPLE__)
      if (!wcscmp(targetManufacturer, cur_dev->manufacturer_string) ) {
        fprintf(stdout, "<Pilote> Afficheur USB %04hx %04hx en cours d\'ouverture sur %s..\n", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path);
        display = hid_open(cur_dev->vendor_id, cur_dev->product_id, NULL);
        break;
      }
    #elif defined(linux)
      if (!wcscmp(targetManufacturer, cur_dev->manufacturer_string) &&  !strcmp(cur_dev->path+(strlen(cur_dev->path)-2), "01")) {
        fprintf(stdout, "<Pilote> Afficheur USB %04hx %04hx en cours d\'ouverture sur %s..\n", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path);
        display = hid_open_path(cur_dev->path);
        break;
      }
    #else
      fprintf(stderr, "<Fatal> Ce système n'est pas (encore) supporté pour l'instant!\n");
      exit(-1);
    #endif

		cur_dev = cur_dev->next;
	}

	hid_free_enumeration(devs);
  if (!display) return 0;

  hid_get_product_string(display, moduleName, MAX_STR);
  if (DEBUG) fprintf(stdout, "<Info> Connected to \"%ls\" display.\n", moduleName);
  return display!=NULL;
}