//----------------------------------------------------------------------------- bool HIDDeviceManager::GetDescriptorFromPath(const char* dev_path, HIDDeviceDesc* desc) { if (!initializeManager()) { return false; } struct hid_device_info *devs, *cur_dev; devs = hid_enumerate(0x0, 0x0); cur_dev = devs; while (cur_dev) { if(strcmp(cur_dev->path,dev_path)==0) { desc->Path = String(cur_dev->path); getFullDesc(cur_dev, desc); } cur_dev = cur_dev->next; } hid_free_enumeration(devs); return true; }
bool HIDDeviceManager::GetHIDDeviceDesc(const String& path, HIDDeviceDesc* pdevDesc) const { // open device in non-exclusive mode for detection... HANDLE hidDev = CreateHIDFile(path, false); if (hidDev == INVALID_HANDLE_VALUE) return false; pdevDesc->Path = path; getFullDesc(hidDev, pdevDesc); ::CloseHandle(hidDev); return true; }
//----------------------------------------------------------------------------- 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; }