/*---------------------------------------------------------------------------*/ 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; }
hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, const 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; }
static void freeDevice(LPCUSBSIO_I2C_Ctrl_t *dev) { LPCUSBSIO_I2C_Ctrl_t *curDev = g_Ctrl.devList; if (curDev == dev) { g_Ctrl.devList = dev->next; } else { while (curDev) { if (curDev->next == dev) { /* update linked list */ curDev->next = dev->next; break; } } } framework_FreeMem(dev); /* unload HID library if all devices are closed. */ if (g_Ctrl.devList == NULL) { hid_free_enumeration(g_Ctrl.devInfoList); hid_exit(); } }
/* * 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; }
//------------------------------------------------------------------------------------- LapTrainer::~LapTrainer(void) { num_res= simball.DisconnectFromSimBall(0); hid_free_enumeration(simball.device); //we free enumeration Sleep (50); hid_exit(); }
//----------------------------------------------------------------------------- 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; }
/********************************************************** * 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; }
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); } }
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; }
void Comm::PollUSB() { hid_device_info *dev; dev = hid_enumerate(VID, PID); connected = (dev != NULL); hid_free_enumeration(dev); }
// 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; }
void touchmouse_free_enumeration(touchmouse_device_info *devs) { TM_FLOOD("touchmouse_free_enumeration: Freeing touchmouse device list\n"); touchmouse_device_info* prev; if (devs) { hid_free_enumeration(((struct hid_device_info**)devs->opaque)[1]); } while (devs) { prev = devs; devs = devs->next; free(prev->opaque); free(prev); } }
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); }
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); }
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); } }
//----------------------------------------------------------------------------- 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; }
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; }
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; }
/*! 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); }
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; }
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 }
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; }
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 }
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; }
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; }
LPCUSBSIO_API int32_t I2C_GetNumPorts(void) { struct hid_device_info *cur_dev; int32_t count = 0; /* free any HID device structures if we were called previously */ if (g_Ctrl.devInfoList != NULL) { hid_free_enumeration(g_Ctrl.devInfoList); g_Ctrl.devInfoList = NULL; } g_Ctrl.devInfoList = hid_enumerate(LPCUSBSIO_VID, LPCUSBSIO_PID); cur_dev = g_Ctrl.devInfoList; while (cur_dev) { count++; cur_dev = cur_dev->next; } return count; }
void UT612ByteSource::printAllHidDevices() { printf("\n--- List of all HID devices: ---\n"); hid_device_info* devs = hid_enumerate(0x0, 0x0); hid_device_info* cur_dev = devs; while (cur_dev) { 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"); cur_dev = cur_dev->next; } hid_free_enumeration(devs); std::cout << "--------------------------------" << std::endl; }
REALTOUCH_DECLSPEC int realtouch_get_count(struct realtouch* s) { int count = 0; struct hid_device_info* devices_old; struct hid_device_info* devices_new; struct hid_device_info* device_cur; if (!s->_is_inited) { return E_REALTOUCH_NOT_INITED; } devices_new = hid_enumerate(REALTOUCH_VID, REALTOUCH_PID); device_cur = devices_new; while(device_cur) { ++count; device_cur = device_cur->next; } hid_free_enumeration(devices_new); return count; }
bool ControllerDeviceEnumerator::next() { bool foundValid = false; while (!foundValid && m_deviceType < CommonDeviceState::SUPPORTED_CONTROLLER_TYPE_COUNT) { if (cur_dev != nullptr) { cur_dev = cur_dev->next; foundValid = is_valid(); } // If there are more device types to scan // move on to the next vid/pid device enumeration if (!foundValid && cur_dev == nullptr) { m_deviceType = static_cast<CommonDeviceState::eDeviceType>(m_deviceType + 1); // Free any previous enumeration if (devs != nullptr) { hid_free_enumeration(devs); cur_dev= nullptr; devs= nullptr; } if (GET_DEVICE_TYPE_INDEX(m_deviceType) < MAX_CONTROLLER_TYPE_INDEX) { USBDeviceInfo &dev_info = g_supported_controller_infos[GET_DEVICE_TYPE_INDEX(m_deviceType)]; // Create a new HID enumeration devs = hid_enumerate(dev_info.vendor_id, dev_info.product_id); cur_dev = devs; foundValid = is_valid(); } } } return foundValid; }
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); if (devs == NULL) { printf("%s:%d:%x:%x not found\n", __FILE__, __LINE__, 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 */ printf("%s:%d: %s\n", __FILE__, __LINE__, path_to_open); handle = hid_open_path(path_to_open); } hid_free_enumeration(devs); return handle; }