Android UsbEndpoint - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android UsbEndpoint class.

This code example shows how to use the following methods:getType
            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) {
            Log.e(TAG, "endpoint is not interrupt type");
            return; 
        } 
        mDevice = device;
        mEndpointIntr = ep;
        if (device != null) {
            UsbDeviceConnection connection = mUsbManager.openDevice(device);
            if (connection != null && connection.claimInterface(intf, true)) {
                Log.d(TAG, "open SUCCESS");
                mConnection = connection;
                Thread thread = new Thread(this);
                thread.start();
 
            } else { 
6
CodeRank
This code example shows how to use the following methods:getDirection, getType
            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)) {
            //Start the polling thread 
            Toast.makeText(this, "open SUCCESS", Toast.LENGTH_SHORT).show();
            mConnection = connection;
            mRunning = true;
            Thread thread = new Thread(null, this, "ScaleMonitor");
5
CodeRank
This code example shows how to use the following methods:getInterval
        final int d = ep.getDirection();
        return (d == UsbConstants.USB_DIR_IN) ? "IN" : "OUT";
    } 
 
    public static String getIntervalString(UsbEndpoint ep) {
        final int interval = ep.getInterval();
        return "" + interval;
    } 
 
    public static String getMaxPacketSizeString(UsbEndpoint ep) {
        final int size = ep.getMaxPacketSize();
        return "" + size;
    } 
 
    public static String getTypeString(UsbEndpoint ep) {
        switch (ep.getType()) {
            case UsbConstants.USB_ENDPOINT_XFER_CONTROL:
                return "Control"; 
            case UsbConstants.USB_ENDPOINT_XFER_INT:
                return "Interrupt"; 
4
CodeRank
This code example shows how to use the following methods:getMaxPacketSize, equals
This code example shows how to use the following methods:getDirection, getType
 
		// endpoint should be of type bulk 
		UsbEndpoint ep = intf.getEndpoint(0);
		UsbEndpoint epOut = null;
		UsbEndpoint epIn = null;
		if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
			if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
				epOut = ep;
				//Toast toast = Toast.makeText(context, "endpoint 0 is out", duration); 
				//toast.show(); 
			} else { 
				epIn = ep;
				//Toast toast = Toast.makeText(context, "endpoint 0 is in", duration); // actually is in 
				//toast.show(); 
			} 
			mEndpointIn = epIn;
		} else { 
			return; 
		} 
 
4
CodeRank
This code example shows how to use the following methods:getMaxPacketSize
    public void close() { 
        connection.close();
    } 
 
    public int getMaxPacketInSize() { 
        return bulkIn.getMaxPacketSize();
    } 
 
    public int getMaxPacketOutSize() { 
        return bulkOut.getMaxPacketSize();
    } 
 
    public UsbRequest createInRequest() {
        UsbRequest r = new UsbRequest();
        r.initialize(connection, bulkIn);
        return r;
    } 
 
    public int bulkTransferOut(byte[] buffer, int length, int timeout) {
        return connection.bulkTransfer(bulkOut, buffer, length, timeout);
4
CodeRank
This code example shows how to use the following methods:getEndpointNumber
    private static final Comparator<Map<String, Object>> EP_COMPARATOR = new Comparator<Map<String, Object>>() {
        @Override 
        public int compare(Map<String, Object> object1, Map<String, Object> object2) { 
            final UsbEndpoint ep1 = (UsbEndpoint) object1.get(EndpointMapKeys.ENDPOINT); 
            final UsbEndpoint ep2 = (UsbEndpoint) object2.get(EndpointMapKeys.ENDPOINT); 
            return Integer.valueOf(ep1.getEndpointNumber()).compareTo( 
                    Integer.valueOf(ep2.getEndpointNumber())); 
        } 
    }; 
 
    private void showEndpoints(UsbInterface iface) {
        if (!isAdded()) {
            return; 
        } 
 
        final int endpointCount = iface.getEndpointCount();
        final List<Map<String, Object>> epEntries = Lists.newArrayListWithCapacity(endpointCount);
        for (int i = 0; i < endpointCount; i++) {
            final Map<String, Object> epEntry = Maps.newHashMap();
            final UsbEndpoint endpoint = iface.getEndpoint(i);
4
CodeRank
This code example shows how to use the following methods:getMaxPacketSize
    } 
 
    @Override 
    public int read(byte[] dest, int timeoutMillis) throws IOException {
        int readAmt = Math.min(dest.length, mReadBuffer.length);
        readAmt = Math.min(readAmt, mReadEndpoint.getMaxPacketSize());
        final int transferred = mConnection.bulkTransfer(mReadEndpoint, mReadBuffer, readAmt,
                timeoutMillis);
 
        if (transferred < 0) {
            // This sucks: we get -1 on timeout, not 0 as preferred. 
            // We *should* use UsbRequest, except it has a bug/api oversight 
            // where there is no way to determine the number of bytes read 
            // in response :\ -- http://b.android.com/28023 
            return 0; 
        } 
        System.arraycopy(mReadBuffer, 0, dest, 0, transferred);
        return transferred;
    } 
 
4
CodeRank
This code example shows how to use the following methods:getMaxPacketSize
				int writeTmoutMs
				) { 
			mUsbConnection = connection;
			mUsbEndpoint = bulkInEndpoint;
			mTimeout = writeTmoutMs;
			rcvPkt = new byte[mUsbEndpoint.getMaxPacketSize()];
		} 
 
		public UsbSerialInputStream(UsbDeviceConnection connection,
				UsbEndpoint bulkOutEndpoint) {
			this(connection, bulkOutEndpoint, DEFAULT_READ_TIMEOUT_MS);
		} 
 
		@Override 
		public int read() throws IOException { 
			synchronized(this) {
				int rcvd = read(rcvPkt, 0, 1);
				if (rcvd == 0) throw new IOException("timeout");
				return rcvPkt[0] & 0xff;
			} 
4
CodeRank
This code example shows how to use the following methods:getType
			appendLogText("could not find endpoint"); 
			return; 
		} 
		// endpoint should be of type interrupt 
		UsbEndpoint ep = intf.getEndpoint(0);
		if (ep.getType() != UsbConstants.USB_ENDPOINT_XFER_INT) {
 
			appendLogText("endpoint is not interrupt type"); 
			return; 
		} 
 
		mDevice = device;
		mEndpointIntr = ep;
		if (device != null) {
			UsbDeviceConnection connection = mUsbManager.openDevice(device);
			if (connection != null && connection.claimInterface(intf, true)) {
				appendLogText("open SUCCESS"); 
				mConnection = connection;
				Thread thread = new Thread(this);
				thread.start();
3
CodeRank

Related Android UsbEndpoint Questions & Answers:

See Code Examples for Android UsbEndpoint Methods: