سؤال

The goal is to connect a guitar to USB host capable Android device, do some processing on the signal and play it through the device.

Problem is I'm not finding much documentation on it. The device shows up can contains 6 interfaces.

However, in all the examples I see, the first interface is always used..

UsbInterface intf = device.getInterface(0);

My device contains 6 interfaces BUT the first interface, i.e. getInterface(0) has no endpoints. 3/6 have no endpoints but the other 3 all have 1 end point.

I read that you need to find the correct interface and endpoint. In my case, I only want an IN endpoint to receive data.

Any advice on how to that would be very appreciated.

Cheers

هل كانت مفيدة؟

المحلول

This is how I got down to the bottom of it.

The last interface, I believe is the one I am looking for.

  • It has a direction value of USB_DIR_IN (3)
  • It has a endpoint type value USB_ENDPOINT_XFER_ISOC (1) signifying the regular isochronous connection I was looking for

    // Cycle through interfaces and print out endpoint info
    StringBuilder builder = new StringBuilder();
    
    for (int i=0; i<device.getInterfaceCount(); i++)
    {
        String epDirString = "No endpoints";
        String epTypeString = "No endpoints";
    
        if (device.getInterface(i).getEndpointCount() > 0)
        {
            epDirString = String.valueOf(device.getInterface(i).getEndpoint(0).getDirection());
            epTypeString = String.valueOf(device.getInterface(i).getEndpoint(0).getType());
        }
    
        builder.append("Int. " + i + " EP count: " + device.getInterface(i).getEndpointCount() + 
                       " || EP direction: " + epDirString + " || EP type: " + epTypeString + "\n");
    }
    
    // Show results in a dialog
    Builder dBuilder = new AlertDialog.Builder(USBActivity.this);       
    dBuilder.setMessage(builder.toString()).show();
    
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top