public AdbDevice(AdbTestActivity activity, UsbDeviceConnection connection,
UsbInterface intf) {
mActivity = activity;
mDeviceConnection = connection;
mSerial = connection.getSerial();
UsbEndpoint epOut = null;
UsbEndpoint epIn = null;
// look for our bulk endpoints
for (int i = 0; i < intf.getEndpointCount(); i++) {
UsbEndpoint ep = intf.getEndpoint(i);
if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
epOut = ep;
} else {
epIn = ep;
}
}
}
if (epOut == null || epIn == null) {
throw new IllegalArgumentException("not all endpoints found");
}
mEndpointOut = epOut;
mEndpointIn = epIn;
}
java类android.hardware.usb.UsbInterface的实例源码
AdbDevice.java 文件源码
项目:buildAPKsSamples
阅读 27
收藏 0
点赞 0
评论 0
UsbHidDevice.java 文件源码
项目:UsbHid
阅读 26
收藏 0
点赞 0
评论 0
public static UsbHidDevice[] enumerate(Context context, int vid, int pid) throws Exception {
UsbManager usbManager = (UsbManager) context.getApplicationContext().getSystemService(Context.USB_SERVICE);
if (usbManager == null) {
throw new Exception("no usb service");
}
Map<String, UsbDevice> devices = usbManager.getDeviceList();
List<UsbHidDevice> usbHidDevices = new ArrayList<>();
for (UsbDevice device : devices.values()) {
if ((vid == 0 || device.getVendorId() == vid) && (pid == 0 || device.getProductId() == pid)) {
for (int i = 0; i < device.getInterfaceCount(); i++) {
UsbInterface usbInterface = device.getInterface(i);
if (usbInterface.getInterfaceClass() == INTERFACE_CLASS_HID) {
UsbHidDevice hidDevice = new UsbHidDevice(device, usbInterface, usbManager);
usbHidDevices.add(hidDevice);
}
}
}
}
return usbHidDevices.toArray(new UsbHidDevice[usbHidDevices.size()]);
}
UsbHidDevice.java 文件源码
项目:UsbHid
阅读 23
收藏 0
点赞 0
评论 0
private UsbHidDevice(UsbDevice usbDevice, UsbInterface usbInterface, UsbManager usbManager) {
mUsbDevice = usbDevice;
mUsbInterface = usbInterface;
mUsbManager= usbManager;
for (int i = 0; i < mUsbInterface.getEndpointCount(); i++) {
UsbEndpoint endpoint = mUsbInterface.getEndpoint(i);
int dir = endpoint.getDirection();
int type = endpoint.getType();
if (mInUsbEndpoint == null && dir == UsbConstants.USB_DIR_IN && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
mInUsbEndpoint = endpoint;
}
if (mOutUsbEndpoint == null && dir == UsbConstants.USB_DIR_OUT && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
mOutUsbEndpoint = endpoint;
}
}
}
USBMonitor.java 文件源码
项目:AndroidUvcCameras
阅读 25
收藏 0
点赞 0
评论 0
/**
* open specific interface
* @param interfaceIndex
* @return
*/
public synchronized UsbInterface open(final int interfaceIndex) {
if (DEBUG) Log.i(TAG, "UsbControlBlock#open:" + interfaceIndex);
final UsbDevice device = mWeakDevice.get();
UsbInterface intf = null;
intf = mInterfaces.get(interfaceIndex);
if (intf == null) {
intf = device.getInterface(interfaceIndex);
if (intf != null) {
synchronized (mInterfaces) {
mInterfaces.append(interfaceIndex, intf);
}
}
}
return intf;
}
USBMonitor.java 文件源码
项目:AndroidUvcCameras
阅读 26
收藏 0
点赞 0
评论 0
/**
* close specified interface. USB device itself still keep open.
* @param interfaceIndex
*/
public synchronized void close() {
if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");
if (mConnection != null) {
final int n = mInterfaces.size();
int key;
UsbInterface intf;
for (int i = 0; i < n; i++) {
key = mInterfaces.keyAt(i);
intf = mInterfaces.get(key);
mConnection.releaseInterface(intf);
}
mConnection.close();
mConnection = null;
final USBMonitor monitor = mWeakMonitor.get();
if (monitor != null) {
if (monitor.mOnDeviceConnectListener != null) {
final UsbDevice device = mWeakDevice.get();
monitor.mOnDeviceConnectListener.onDisconnect(device, this);
}
monitor.mCtrlBlocks.remove(getDevice());
}
}
}
AlternateUsbInterface.java 文件源码
项目:AndroidDvbDriver
阅读 19
收藏 0
点赞 0
评论 0
public static List<AlternateUsbInterface> forUsbInterface(UsbDeviceConnection deviceConnection, UsbInterface usbInterface) {
byte[] rawDescriptors = deviceConnection.getRawDescriptors();
List<AlternateUsbInterface> alternateSettings = new ArrayList<>(2);
int offset = 0;
while(offset < rawDescriptors.length) {
int bLength = rawDescriptors[offset] & 0xFF;
int bDescriptorType = rawDescriptors[offset + 1] & 0xFF;
if (bDescriptorType == 0x04) {
// interface descriptor, we are not interested
int bInterfaceNumber = rawDescriptors[offset + 2] & 0xFF;
int bAlternateSetting = rawDescriptors[offset + 3] & 0xFF;
if (bInterfaceNumber == usbInterface.getId()) {
alternateSettings.add(new AlternateUsbInterface(usbInterface, bAlternateSetting));
}
}
// go to next structure
offset += bLength;
}
if (alternateSettings.size() < 1) throw new IllegalStateException();
return alternateSettings;
}
AlternateUsbInterfaceTest.java 文件源码
项目:AndroidDvbDriver
阅读 17
收藏 0
点赞 0
评论 0
@Test
public void getAlternateSetting() throws Exception {
UsbDeviceConnection usbDeviceConnection = mockConnectionWithRawDescriptors(new byte[] {
18, 1, 0, 2, 0, 0, 0, 64, -38, 11, 56, 40, 0, 1, 1, 2, 3, 1, // Device Descriptor
9, 2, 34, 0, 2, 1, 4, -128, -6, // Configuration Descriptor
9, 4, 0, 0, 1, -1, -1, -1, 5, // Interface Descriptor for interface 0 with alternate setting 0
9, 4, 0, 1, 1, -1, -1, -1, 5, // Interface Descriptor for interface 0 with alternate setting 1
7, 5, -127, 2, 0, 2, 0, // Endpoint Descriptor
9, 4, 1, 0, 0, -1, -1, -1, 5 // Interface Descriptor for interface 1 with alternate setting 0
});
// Interface 0 has alternate settings {0, 1}
UsbInterface i0 = mockInterface(0);
assertThat(AlternateUsbInterface.forUsbInterface(usbDeviceConnection, i0),
equalTo(asList(new AlternateUsbInterface(i0, 0), new AlternateUsbInterface(i0, 1))));
// Interface 1 has alternate settings {0}
UsbInterface i1 = mockInterface(1);
assertThat(AlternateUsbInterface.forUsbInterface(usbDeviceConnection, i1),
equalTo(singletonList(new AlternateUsbInterface(i1, 0))));
}
AdbTestActivity.java 文件源码
项目:buildAPKsSamples
阅读 25
收藏 0
点赞 0
评论 0
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.adb);
mLog = (TextView)findViewById(R.id.log);
mManager = (UsbManager)getSystemService(Context.USB_SERVICE);
// check for existing devices
for (UsbDevice device : mManager.getDeviceList().values()) {
UsbInterface intf = findAdbInterface(device);
if (setAdbInterface(device, intf)) {
break;
}
}
// listen for new devices
IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
registerReceiver(mUsbReceiver, filter);
}
AdbTestActivity.java 文件源码
项目:buildAPKsSamples
阅读 20
收藏 0
点赞 0
评论 0
private boolean setAdbInterface(UsbDevice device, UsbInterface intf) {
if (mDeviceConnection != null) {
if (mInterface != null) {
mDeviceConnection.releaseInterface(mInterface);
mInterface = null;
}
mDeviceConnection.close();
mDevice = null;
mDeviceConnection = null;
}
if (device != null && intf != null) {
UsbDeviceConnection connection = mManager.openDevice(device);
if (connection != null) {
log("open succeeded");
if (connection.claimInterface(intf, false)) {
log("claim interface succeeded");
mDevice = device;
mDeviceConnection = connection;
mInterface = intf;
mAdbDevice = new AdbDevice(this, mDeviceConnection, intf);
log("call start");
mAdbDevice.start();
return true;
} else {
log("claim interface failed");
connection.close();
}
} else {
log("open failed");
}
}
if (mDeviceConnection == null && mAdbDevice != null) {
mAdbDevice.stop();
mAdbDevice = null;
}
return false;
}
UsbHelper.java 文件源码
项目:sample-usbenum
阅读 27
收藏 0
点赞 0
评论 0
/**
* Enumerate the endpoints and interfaces on the connected device.
*
* @param device Device to query.
* @return String description of the device configuration.
*/
public static String readDevice(UsbDevice device) {
StringBuilder sb = new StringBuilder();
sb.append("Device Name: " + device.getDeviceName() + "\n");
sb.append(String.format(
"Device Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n",
nameForClass(device.getDeviceClass()),
device.getDeviceSubclass(), device.getDeviceProtocol()));
for (int i = 0; i < device.getInterfaceCount(); i++) {
UsbInterface intf = device.getInterface(i);
sb.append(String.format(Locale.US,
"-- Interface %d Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n",
intf.getId(),
nameForClass(intf.getInterfaceClass()),
intf.getInterfaceSubclass(),
intf.getInterfaceProtocol()));
sb.append(String.format(Locale.US, " -- Endpoint Count: %d\n",
intf.getEndpointCount()));
}
return sb.toString();
}
MainActivity.java 文件源码
项目:astrobee_android
阅读 23
收藏 0
点赞 0
评论 0
protected void setupUsb(UsbDevice device) {
UsbInterface inf = device.getInterface(0);
UsbDeviceConnection conn = mUsbManager.openDevice(device);
if (conn == null) {
Log.wtf("MainActivity", "unable to open device?");
return;
}
if (!conn.claimInterface(inf, true)) {
conn.close();
Log.wtf("MainActivity", "unable to claim interface!");
return;
}
mBlinkDevice = device;
mBlinkConn = conn;
}
USBMonitor.java 文件源码
项目:UVCCameraZxing
阅读 25
收藏 0
点赞 0
评论 0
/**
* open specific interface
* @param interfaceIndex
* @return
*/
public synchronized UsbInterface open(final int interfaceIndex) {
if (DEBUG) Log.i(TAG, "UsbControlBlock#open:" + interfaceIndex);
final UsbDevice device = mWeakDevice.get();
UsbInterface intf = null;
intf = mInterfaces.get(interfaceIndex);
if (intf == null) {
intf = device.getInterface(interfaceIndex);
if (intf != null) {
synchronized (mInterfaces) {
mInterfaces.append(interfaceIndex, intf);
}
}
}
return intf;
}
USBMonitor.java 文件源码
项目:UVCCameraZxing
阅读 23
收藏 0
点赞 0
评论 0
/**
* close specified interface. USB device itself still keep open.
*/
public synchronized void close() {
if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");
if (mConnection != null) {
final int n = mInterfaces.size();
int key;
UsbInterface intf;
for (int i = 0; i < n; i++) {
key = mInterfaces.keyAt(i);
intf = mInterfaces.get(key);
mConnection.releaseInterface(intf);
}
mConnection.close();
mConnection = null;
final USBMonitor monitor = mWeakMonitor.get();
if (monitor != null) {
if (monitor.mOnDeviceConnectListener != null) {
final UsbDevice device = mWeakDevice.get();
monitor.mOnDeviceConnectListener.onDisconnect(device, this);
}
monitor.mCtrlBlocks.remove(getDevice());
}
}
}
USBMonitor.java 文件源码
项目:AndroidUvcCameras
阅读 25
收藏 0
点赞 0
评论 0
/**
* open specific interface
* @param interfaceIndex
* @return
*/
public synchronized UsbInterface open(final int interfaceIndex) {
if (DEBUG) Log.i(TAG, "UsbControlBlock#open:" + interfaceIndex);
final UsbDevice device = mWeakDevice.get();
UsbInterface intf = null;
intf = mInterfaces.get(interfaceIndex);
if (intf == null) {
intf = device.getInterface(interfaceIndex);
if (intf != null) {
synchronized (mInterfaces) {
mInterfaces.append(interfaceIndex, intf);
}
}
}
return intf;
}
USBMonitor.java 文件源码
项目:AndroidUvcCameras
阅读 24
收藏 0
点赞 0
评论 0
/**
* close specified interface. USB device itself still keep open.
* @param interfaceIndex
*/
public synchronized void close() {
if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");
if (mConnection != null) {
final int n = mInterfaces.size();
int key;
UsbInterface intf;
for (int i = 0; i < n; i++) {
key = mInterfaces.keyAt(i);
intf = mInterfaces.get(key);
mConnection.releaseInterface(intf);
}
mConnection.close();
mConnection = null;
final USBMonitor monitor = mWeakMonitor.get();
if (monitor != null) {
if (monitor.mOnDeviceConnectListener != null) {
final UsbDevice device = mWeakDevice.get();
monitor.mOnDeviceConnectListener.onDisconnect(device, this);
}
monitor.mCtrlBlocks.remove(getDevice());
}
}
}
WaltUsbConnection.java 文件源码
项目:walt
阅读 27
收藏 0
点赞 0
评论 0
@Override
public void onConnect() {
// Serial mode only
// TODO: find the interface and endpoint indexes no matter what mode it is
int ifIdx = 1;
int epInIdx = 1;
int epOutIdx = 0;
UsbInterface iface = usbDevice.getInterface(ifIdx);
if (usbConnection.claimInterface(iface, true)) {
logger.log("Interface claimed successfully\n");
} else {
logger.log("ERROR - can't claim interface\n");
return;
}
endpointIn = iface.getEndpoint(epInIdx);
endpointOut = iface.getEndpoint(epOutIdx);
super.onConnect();
}
UsbWriter.java 文件源码
项目:bootloadHID-android
阅读 20
收藏 0
点赞 0
评论 0
private boolean setDevice(UsbDevice device) {
Logger.d("setDevice " + device);
clearDevice();
if (null == device) {
return false;
}
if (device.getVendorId() != mVendorId) {
printDevice(device);
Logger.i("Not a target vendor: expecting %d", mVendorId);
return false;
}
if (device.getProductId() != mProductId) {
printDevice(device);
Logger.i("Not a target product: expecting %d", mProductId);
return false;
}
if (!mUsbManager.hasPermission(device)) {
Logger.d("request permission");
mUsbManager.requestPermission(device, mPermissionIntent);
return false;
}
printDevice(device);
try {
UsbInterface usbinterface = device.getInterface(0);
UsbDeviceConnection connection = mUsbManager.openDevice(device);
if (!connection.claimInterface(usbinterface, true)) {
return false;
}
mDevice = device;
mConnection = connection;
Logger.d("open SUCCESS");
if (null != mOnDeviceListener) {
mOnDeviceListener.onAttached();
}
return true;
} catch (Exception e) {
Logger.e(e, e.getLocalizedMessage());
}
return false;
}
MainActivity.java 文件源码
项目:lp2go
阅读 20
收藏 0
点赞 0
评论 0
private boolean setUsbInterface(android.hardware.usb.UsbDevice device, UsbInterface intf) {
if (mDeviceConnection != null) {
if (mInterface != null) {
mDeviceConnection.releaseInterface(mInterface);
mInterface = null;
}
mDeviceConnection.close();
mDevice = null;
mDeviceConnection = null;
}
if (device != null && intf != null) {
UsbDeviceConnection connection = mUsbManager.openDevice(device);
if (connection != null) {
if (connection.claimInterface(intf, true)) {
mDevice = device;
mDeviceConnection = connection;
mInterface = intf;
mFcDevice = new FcUsbDevice(this, mDeviceConnection, intf,
mXmlObjects);
mFcDevice.getObjectTree().setXmlObjects(mXmlObjects);
mFcDevice.start();
return true;
} else {
connection.close();
}
}
}
if (mDeviceConnection == null && mFcDevice != null) {
mFcDevice.stop();
mFcDevice = null;
}
return false;
}
MidiInputDevice.java 文件源码
项目:TrueTone
阅读 20
收藏 0
点赞 0
评论 0
/**
* constructor
*
* @param usbDevice
* @param usbDeviceConnection
* @param usbInterface
* @param midiEventListener
* @throws IllegalArgumentException endpoint not found.
*/
public MidiInputDevice(UsbDevice usbDevice, UsbDeviceConnection usbDeviceConnection, UsbInterface usbInterface, UsbEndpoint usbEndpoint, OnMidiInputEventListener midiEventListener) throws IllegalArgumentException {
//this.usbDevice = usbDevice;
this.usbDeviceConnection = usbDeviceConnection;
this.usbInterface = usbInterface;
this.midiEventListener = midiEventListener;
waiterThread = new WaiterThread();
inputEndpoint = usbEndpoint;
usbDeviceConnection.claimInterface(usbInterface, true);
waiterThread.setPriority(8);
waiterThread.setName("MidiInputDevice[" + usbDevice.getDeviceName() + "].WaiterThread");
waiterThread.start();
FragMentManager.getInstance().updateUSBConnection(true);
}
USBMonitor.java 文件源码
项目:DeviceConnect-Android
阅读 24
收藏 0
点赞 0
评论 0
/**
* get interface
* @param interface_id
* @param altsetting
* @return
* @throws IllegalStateException
*/
public synchronized UsbInterface getInterface(final int interface_id, final int altsetting) throws IllegalStateException {
checkConnection();
SparseArray<UsbInterface> intfs = mInterfaces.get(interface_id);
if (intfs == null) {
intfs = new SparseArray<UsbInterface>();
mInterfaces.put(interface_id, intfs);
}
UsbInterface intf = intfs.get(altsetting);
if (intf == null) {
final UsbDevice device = mWeakDevice.get();
final int n = device.getInterfaceCount();
for (int i = 0; i < n; i++) {
final UsbInterface temp = device.getInterface(i);
if ((temp.getId() == interface_id) && (temp.getAlternateSetting() == altsetting)) {
intf = temp;
break;
}
}
if (intf != null) {
intfs.append(altsetting, intf);
}
}
return intf;
}
OtgDeviceFacade.java 文件源码
项目:OTGDiskBackup
阅读 20
收藏 0
点赞 0
评论 0
public OtgDeviceFacade(UsbInterface usbInterface, byte lun, UsbDeviceConnection usbDeviceConnection,
UsbDevice usbDevice) {
this.cbwBuffer = ByteBuffer.wrap(new byte[USB_CBW_LENGTH]);
this.cswBuffer = ByteBuffer.wrap(new byte[USB_CSW_LENGTH]);
this.ufiCmdRequestSenseBuffer = ByteBuffer.wrap(new byte[UFI_CMD_REQUEST_SENSE_LENGTH]);
this.ufiCmdReadCapacityBuffer = ByteBuffer.wrap(new byte[UFI_CMD_READ_CAPACITY_LENGTH]);
this.ufiCmdReadBuffer = ByteBuffer.wrap(new byte[UFI_CMD_READ_LENGTH]);
this.ufiCmdWriteBuffer = ByteBuffer.wrap(new byte[UFI_CMD_WRITE_LENGTH]);
this.cbwTag = 0;
this.sectorSize = 512;
this.receiveBuffer = new byte[8192];
this.usbDeviceConnection = usbDeviceConnection;
this.lun = lun;
initEnpoints(usbInterface);
initCommandBuffers();
}
UsbMidiDeviceFactoryAndroid.java 文件源码
项目:365browser
阅读 23
收藏 0
点赞 0
评论 0
/**
* Request a device access permission if there is a MIDI interface in the device.
*
* @param device a USB device
*/
private void requestDevicePermissionIfNecessary(UsbDevice device) {
for (UsbDevice d : mRequestedDevices) {
if (d.getDeviceId() == device.getDeviceId()) {
// It is already requested.
return;
}
}
for (int i = 0; i < device.getInterfaceCount(); ++i) {
UsbInterface iface = device.getInterface(i);
if (iface.getInterfaceClass() == UsbConstants.USB_CLASS_AUDIO
&& iface.getInterfaceSubclass() == UsbMidiDeviceAndroid.MIDI_SUBCLASS) {
// There is at least one interface supporting MIDI.
mUsbManager.requestPermission(device,
PendingIntent.getBroadcast(ContextUtils.getApplicationContext(), 0,
new Intent(ACTION_USB_PERMISSION), 0));
mRequestedDevices.add(device);
break;
}
}
}
UsbIpService.java 文件源码
项目:USBIPServerForAndroid
阅读 21
收藏 0
点赞 0
评论 0
public static void dumpInterfaces(UsbDevice dev) {
for (int i = 0; i < dev.getInterfaceCount(); i++) {
System.out.printf("%d - Iface %d (%02x/%02x/%02x)\n",
i, dev.getInterface(i).getId(),
dev.getInterface(i).getInterfaceClass(),
dev.getInterface(i).getInterfaceSubclass(),
dev.getInterface(i).getInterfaceProtocol());
UsbInterface iface = dev.getInterface(i);
for (int j = 0; j < iface.getEndpointCount(); j++) {
System.out.printf("\t%d - Endpoint %d (%x/%x)\n",
j, iface.getEndpoint(j).getEndpointNumber(),
iface.getEndpoint(j).getAddress(),
iface.getEndpoint(j).getAttributes());
}
}
}
ConnectedUsbDevice.java 文件源码
项目:android-weather-station
阅读 22
收藏 0
点赞 0
评论 0
public ConnectedUsbDevice(UsbDeviceConnection connection, UsbInterface usbInterface) {
this.connection = connection;
this.usbInterface = usbInterface;
initConnection(connection);
int endPoints = usbInterface.getEndpointCount();
int interfaceProtocol = usbInterface.getInterfaceProtocol();
System.out.println("EndPoints: " + endPoints + " | interfaces: " + interfaceProtocol);
out = usbInterface.getEndpoint(1);
in = usbInterface.getEndpoint(2);
for (int x = 0; x < endPoints; x++) {
UsbEndpoint endpoint = usbInterface.getEndpoint(x);
boolean bulk = endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK;
boolean crtl = endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_CONTROL;
boolean inDir = endpoint.getDirection() == UsbConstants.USB_DIR_IN;
boolean outDir = endpoint.getDirection() == UsbConstants.USB_DIR_OUT;
System.out.println("ID: " + x + " Bulk: " + bulk + " Ctrl: " + crtl + " Out: " + outDir + " In: " + inDir);
}
}
FTDriver.java 文件源码
项目:RHome
阅读 23
收藏 0
点赞 0
评论 0
private boolean setFTDIEndpoints(UsbInterface[] intf, int portNum) {
UsbEndpoint epIn;
UsbEndpoint epOut;
if (intf[0] == null) {
return false;
}
for (int i = 0; i < portNum; ++i) {
epIn = intf[i].getEndpoint(0);
epOut = intf[i].getEndpoint(1);
if (epIn != null && epOut != null) {
mFTDIEndpointIN[i] = epIn;
mFTDIEndpointOUT[i] = epOut;
} else {
return false;
}
}
return true;
}
UsbMidiDeviceAndroid.java 文件源码
项目:chromium_webview
阅读 25
收藏 0
点赞 0
评论 0
/**
* Constructs a UsbMidiDeviceAndroid.
* @param manager
* @param device The USB device which this object is assocated with.
*/
UsbMidiDeviceAndroid(UsbManager manager, UsbDevice device) {
mConnection = manager.openDevice(device);
mEndpointMap = new HashMap<Integer, UsbEndpoint>();
mRequestMap = new HashMap<UsbEndpoint, UsbRequest>();
for (int i = 0; i < device.getInterfaceCount(); ++i) {
UsbInterface iface = device.getInterface(i);
if (iface.getInterfaceClass() != UsbConstants.USB_CLASS_AUDIO ||
iface.getInterfaceSubclass() != MIDI_SUBCLASS) {
continue;
}
mConnection.claimInterface(iface, true);
for (int j = 0; j < iface.getEndpointCount(); ++j) {
UsbEndpoint endpoint = iface.getEndpoint(j);
if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
mEndpointMap.put(endpoint.getEndpointNumber(), endpoint);
}
}
}
}
SynthesizerService.java 文件源码
项目:music-synthesizer-for-android-old
阅读 21
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private void scanUsbMidi() {
UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
Log.i("synth", "USB device count=" + deviceList.size());
for (UsbDevice device : deviceList.values()) {
UsbInterface intf = UsbMidiDevice.findMidiInterface(device);
if (intf != null) {
if (usbManager.hasPermission(device)) {
if (connectUsbMidi(device)) {
break;
}
} else {
usbDeviceNeedsPermission_ = device;
}
}
}
}
USBMonitor.java 文件源码
项目:AndroidUvcCameras
阅读 24
收藏 0
点赞 0
评论 0
/**
* close specified interface. USB device itself still keep open.
* @param interfaceIndex
*/
public void close(final int interfaceIndex) {
UsbInterface intf = null;
synchronized (mInterfaces) {
intf = mInterfaces.get(interfaceIndex);
if (intf != null) {
mInterfaces.delete(interfaceIndex);
mConnection.releaseInterface(intf);
}
}
}
ControllerActivity.java 文件源码
项目:InstantUpload
阅读 32
收藏 0
点赞 0
评论 0
private UsbInterface findUsbInterface(UsbDevice device) {
//Log.d (TAG, "findAdbInterface " + device.getDeviceName());
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface intf = device.getInterface(i);
Log.d (TAG, "Interface " +i + " Class " +intf.getInterfaceClass() +" Prot " +intf.getInterfaceProtocol());
if (intf.getInterfaceClass() == 6
//255 && intf.getInterfaceSubclass() == 66 && intf.getInterfaceProtocol() == 1
) {
return intf;
}
}
return null;
}
BaselineInitiator.java 文件源码
项目:InstantUpload
阅读 22
收藏 0
点赞 0
评论 0
protected UsbInterface findUsbInterface(UsbDevice device) {
//Log.d (TAG, "findAdbInterface " + device.getDeviceName());
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface intf = device.getInterface(i);
Log.d (TAG, "Interface " +i + " Class " +intf.getInterfaceClass() +" Prot " +intf.getInterfaceProtocol());
if (intf.getInterfaceClass() == 6
//255 && intf.getInterfaceSubclass() == 66 && intf.getInterfaceProtocol() == 1
) {
return intf;
}
}
return null;
}