Last active
February 29, 2016 06:13
-
-
Save tresf/c0d596a4891b430eb29a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Set specified configuration as active for given device using low-level api | |
*/ | |
public static void setActiveConfiguration(UsbDevice device, UsbConfiguration cfg) throws LibUsbException { | |
DeviceList list = new DeviceList(); | |
LibUsb.getDeviceList(null, list); | |
try { | |
for (Device d : list) { | |
DeviceDescriptor descriptor = new DeviceDescriptor(); | |
LibUsb.getDeviceDescriptor(d, descriptor); | |
if (descriptor.idVendor() == device.getUsbDeviceDescriptor().idVendor() && | |
descriptor.idProduct() == device.getUsbDeviceDescriptor().idProduct()) { | |
Context context = new Context(); | |
LibUsb.init(context); | |
DeviceHandle handle = new DeviceHandle(); | |
LibUsb.open(d, handle); | |
LibUsb.setConfiguration(handle, cfg.getUsbConfigurationDescriptor().bConfigurationValue()); | |
LibUsb.close(handle); | |
LibUsb.exit(context); | |
return; | |
} | |
} | |
} finally { LibUsb.freeDeviceList(list, true); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment