Here are the examples of the java api class android.hardware.usb.UsbEndpoint taken from open source projects.
1. UsbTransport#getIoEndpoints()
Project: open-keychain
File: UsbTransport.java
File: UsbTransport.java
/** * Get device's bulk-in and bulk-out endpoints * * @param usbInterface usb device interface * @return pair of builk-in and bulk-out endpoints respectively */ @NonNull private static Pair<UsbEndpoint, UsbEndpoint> getIoEndpoints(final UsbInterface usbInterface) { UsbEndpoint bulkIn = null, bulkOut = null; for (int i = 0; i < usbInterface.getEndpointCount(); i++) { final UsbEndpoint endpoint = usbInterface.getEndpoint(i); if (endpoint.getType() != UsbConstants.USB_ENDPOINT_XFER_BULK) { continue; } if (endpoint.getDirection() == UsbConstants.USB_DIR_IN) { bulkIn = endpoint; } else if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) { bulkOut = endpoint; } } return new Pair<>(bulkIn, bulkOut); }
2. UsbMidiDeviceAndroid#send()
Project: chromium_webview
File: UsbMidiDeviceAndroid.java
File: UsbMidiDeviceAndroid.java
/** * Sends a USB-MIDI data to the device. * @param endpointNumber The endpoint number of the destination endpoint. * @param bs The data to be sent. */ @CalledByNative void send(int endpointNumber, byte[] bs) { if (mConnection == null) { return; } if (!mEndpointMap.containsKey(endpointNumber)) { return; } UsbEndpoint endpoint = mEndpointMap.get(endpointNumber); UsbRequest request; if (mRequestMap.containsKey(endpoint)) { request = mRequestMap.get(endpoint); } else { request = new UsbRequest(); request.initialize(mConnection, endpoint); mRequestMap.put(endpoint, request); } request.queue(ByteBuffer.wrap(bs), bs.length); }
3. UsbRequestAssert#hasEndpoint()
Project: assertj-android
File: UsbRequestAssert.java
File: UsbRequestAssert.java
public UsbRequestAssert hasEndpoint(UsbEndpoint endpoint) { isNotNull(); UsbEndpoint actualEndpoint = actual.getEndpoint(); // assertThat(actualEndpoint).overridingErrorMessage("Expected endpoint <%s> but was <%s>.", endpoint, // actualEndpoint).isEqualTo(endpoint); return this; }
4. ScaleActivity#setDevice()
Project: accessory-samples
File: ScaleActivity.java
File: ScaleActivity.java
/* * Enumerate the endpoints and interfaces on the connected * device to find the Interrupt endpoint we need to poll * for the scale data. */ private void setDevice(UsbDevice device) { Log.d(TAG, "setDevice " + device); if (device == null) { //Cancel connections mConnection = null; mRunning = false; resetDisplay(); return; } //Verify the device has what we need if (device.getInterfaceCount() != 1) { Log.e(TAG, "could not find interface"); return; } UsbInterface intf = device.getInterface(0); // device should have one endpoint if (intf.getEndpointCount() != 1) { Log.e(TAG, "could not find endpoint"); return; } // endpoint should be of type interrupt UsbEndpoint ep = intf.getEndpoint(0); if (ep.getType() != UsbConstants.USB_ENDPOINT_XFER_INT || ep.getDirection() != UsbConstants.USB_DIR_IN) { Log.e(TAG, "endpoint is not Interrupt IN"); return; } mDevice = device; mEndpointIntr = ep; UsbDeviceConnection connection = mUsbManager.openDevice(device); if (connection != null && connection.claimInterface(intf, true)) { mConnection = connection; //Get scale attributes updateAttributesData(mConnection); //Update the weight limit information updateLimitData(mConnection); //Start the polling thread mRunning = true; Thread thread = new Thread(null, this, "ScaleMonitor"); thread.start(); } else { mConnection = null; mRunning = false; } }