org.bidib.jbidibc.usbhid.UsbConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbidibc-usb Show documentation
Show all versions of jbidibc-usb Show documentation
jBiDiB jbidibc USB POM
Install the libusb drivers for using the libusb access. Under Windows OS you must install the Zadig driver as described here: https://github.com/libusb/libusb/wiki/Windows.
Zadic can be downloaded from: http://zadig.akeo.ie/
In the Zadig UI you must check Options > List all devices and the select the 'USB-EPP /I2C... CH341A' device. Then select the target driver with the spinners (I used libusb-win32 (v1.2.6.0))
and click the 'Install driver' button.
package org.bidib.jbidibc.usbhid;
public class UsbConfiguration {
private final int mId;
private final String mName;
private final int mAttributes;
private final int mMaxPower;
/** All interfaces for this config, only null during creation */
private UsbInterface[] mInterfaces;
/**
* Mask for "self-powered" bit in the configuration's attributes.
*/
private static final int ATTR_SELF_POWERED = 1 << 6;
/**
* Mask for "remote wakeup" bit in the configuration's attributes.
*/
private static final int ATTR_REMOTE_WAKEUP = 1 << 5;
/**
* UsbConfiguration should only be instantiated by UsbService implementation
*
* @hide
*/
public UsbConfiguration(int id, String name, int attributes, int maxPower) {
mId = id;
mName = name;
mAttributes = attributes;
mMaxPower = maxPower;
}
/**
* Returns the configuration's ID field. This is an integer that uniquely identifies the configuration on the
* device.
*
* @return the configuration's ID
*/
public int getId() {
return mId;
}
/**
* Returns the configuration's name.
*
* @return the configuration's name, or {@code null} if the property could not be read
*/
public String getName() {
return mName;
}
/**
* Returns the self-powered attribute value configuration's attributes field. This attribute indicates that the
* device has a power source other than the USB connection.
*
* @return the configuration's self-powered attribute
*/
public boolean isSelfPowered() {
return (mAttributes & ATTR_SELF_POWERED) != 0;
}
/**
* Returns the remote-wakeup attribute value configuration's attributes field. This attributes that the device may
* signal the host to wake from suspend.
*
* @return the configuration's remote-wakeup attribute
*/
public boolean isRemoteWakeup() {
return (mAttributes & ATTR_REMOTE_WAKEUP) != 0;
}
/**
* Returns the attributes of this configuration
*
* @return the configuration's attributes
*
* @hide
*/
public int getAttributes() {
return mAttributes;
}
/**
* Returns the configuration's max power consumption, in milliamps.
*
* @return the configuration's max power
*/
public int getMaxPower() {
return mMaxPower * 2;
}
/**
* Returns the number of {@link UsbInterface}s this configuration contains.
*
* @return the number of endpoints
*/
public int getInterfaceCount() {
return mInterfaces.length;
}
/**
* Returns the {@link UsbInterface} at the given index.
*
* @return the interface
*/
public UsbInterface getInterface(int index) {
return mInterfaces[index];
}
/**
* Only used by UsbService implementation
*
* @hide
*/
public void setInterfaces(UsbInterface[] interfaces) {
mInterfaces = interfaces;
}
@Override
public String toString() {
StringBuilder builder =
new StringBuilder("UsbConfiguration[mId=" + mId + ",mName=" + mName + ",mAttributes=" + mAttributes
+ ",mMaxPower=" + mMaxPower + ",mInterfaces=[");
for (int i = 0; i < mInterfaces.length; i++) {
builder.append("\n");
builder.append(mInterfaces[i].toString());
}
builder.append("]");
return builder.toString();
}
}