Example usage for android.hardware.usb UsbConstants USB_DIR_OUT

List of usage examples for android.hardware.usb UsbConstants USB_DIR_OUT

Introduction

In this page you can find the example usage for android.hardware.usb UsbConstants USB_DIR_OUT.

Prototype

int USB_DIR_OUT

To view the source code for android.hardware.usb UsbConstants USB_DIR_OUT.

Click Source Link

Document

Used to signify direction of data for a UsbEndpoint is OUT (host to device)

Usage

From source file:org.ros.android.android_acm_serial.AcmDevice.java

/**
 * Goes through the given UsbInterface's endpoints and finds the incoming
 * and outgoing bulk transfer endpoints.
 * @return Array with incoming (first) and outgoing (second) USB endpoints
 * @return <code>null</code>  in case either of the endpoints is not found
 *//*from   www.j  a v  a2s.  co  m*/
private AcmUsbEndpoints getAcmEndpoints(UsbInterface usbInterface) {
    UsbEndpoint outgoingEndpoint = null;
    UsbEndpoint incomingEndpoint = null;
    for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
        UsbEndpoint endpoint = usbInterface.getEndpoint(i);
        log.info("Interface: " + i + "/" + "Class: " + usbInterface.getInterfaceClass());
        if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA) {
            if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
                log.info("Endpoint " + i + "/" + usbInterface.getEndpointCount() + ": " + endpoint + ". Type = "
                        + endpoint.getType());
                outgoingEndpoint = endpoint;
            } else if (endpoint.getDirection() == UsbConstants.USB_DIR_IN) {
                log.info("Endpoint " + i + "/" + usbInterface.getEndpointCount() + ": " + endpoint + ". Type = "
                        + endpoint.getType());
                incomingEndpoint = endpoint;
            }
        }
    }
    if (outgoingEndpoint == null || incomingEndpoint == null) {
        return null;
    } else {
        return new AcmUsbEndpoints(incomingEndpoint, outgoingEndpoint);
    }
}

From source file:com.dslr.dashboard.PtpService.java

private void initUsbConnection() {

    try {/*w w w.  j  a v  a2s  . c o m*/
        if (mUsbDevice != null) {
            if (mUsbIntf == null) {
                for (int i = 0; i < mUsbDevice.getInterfaceCount(); i++) {
                    UsbInterface uintf = mUsbDevice.getInterface(i);
                    if (uintf.getInterfaceClass() == UsbConstants.USB_CLASS_STILL_IMAGE) {
                        // we have a still image interface
                        // Log.d(MainActivity.TAG, "Imaging USB interface found");
                        mUsbIntf = uintf;
                        break;
                    }
                }
                if (mUsbIntf != null) {
                    // get the endpoints
                    for (int i = 0; i < mUsbIntf.getEndpointCount(); i++) {
                        UsbEndpoint ep = mUsbIntf.getEndpoint(i);
                        if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
                            if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
                                mUsbWriteEp = ep;
                                // Log.d(MainActivity.TAG, "write endpoint found");
                            }
                        } else {
                            switch (ep.getType()) {
                            case UsbConstants.USB_ENDPOINT_XFER_BULK:
                                mUsbReadEp = ep;
                                // Log.d(MainActivity.TAG, "read endpoint found");
                                break;
                            case UsbConstants.USB_ENDPOINT_XFER_INT:
                                mUsbInterruptEp = ep;
                                // Log.d(MainActivity.TAG, "interrupt endpoint found");
                                break;
                            }
                        }
                    }
                } else
                    Log.d(TAG, "No compatible USB interface found");
            } else
                Log.d(TAG, "USB interface found");
            // if we have read and write endpoints then we good to go
            if (mUsbReadEp != null && mUsbWriteEp != null) {
                if (!mIsUsbDeviceInitialized) {
                    mUsbConnection = mUsbManager.openDevice(mUsbDevice);
                    mIsUsbDeviceInitialized = mUsbConnection != null;
                }
                if (mIsUsbDeviceInitialized) {
                    // Log.d(TAG, "USB Device Initialized");
                    if (!mIsUsbInterfaceClaimed) {
                        mIsUsbInterfaceClaimed = mUsbConnection.claimInterface(mUsbIntf, true);
                        // Log.d(TAG, "USB Interface claimed: " + isInterfaceClaimed);
                    }
                    sendPtpServiceEvent(PtpServiceEvent.UsbDeviceInitialized);
                    // create the USB communicator
                    PtpUsbCommunicator communicator = new PtpUsbCommunicator(new PtpSession());
                    // initialize the USB communicator
                    communicator.initCommunicator(mUsbConnection, mUsbWriteEp, mUsbReadEp, mUsbInterruptEp);
                    // initialize the PTP device
                    mPtpDevice.initialize(mUsbDevice.getVendorId(), mUsbDevice.getProductId(), communicator);
                }
            }

        } else
            Log.d(TAG, "No USB device present");

    } catch (Exception e) {
        Log.d(TAG, "InitUsb exception: " + e.getMessage());
    }
}

From source file:org.chromium.ChromeUsb.java

private void controlTransfer(CordovaArgs args, JSONObject params, final CallbackContext callbackContext)
        throws JSONException, UsbError {
    ConnectedDevice dev = getDevice(params);

    int direction = directionFromName(params.getString("direction"));
    int requestType = controlRequestTypeFromName(params.getString("requestType"));
    int recipient = recipientFromName(params.getString("recipient"));

    byte[] transferBuffer = getByteBufferForTransfer(args, params, UsbConstants.USB_DIR_OUT);
    byte[] receiveBuffer = getByteBufferForTransfer(args, params, UsbConstants.USB_DIR_IN);

    int ret = dev.controlTransfer(direction | requestType | recipient, params.getInt("request"),
            params.getInt("value"), params.getInt("index"), transferBuffer, receiveBuffer,
            params.getInt("timeout"));
    if (ret < 0) {
        throw new UsbError("Control transfer returned " + ret);
    }//from  www.jav a  2  s.c o  m

    /* control transfer is bidirectional, buffer should alway be passed */
    callbackContext.success(Arrays.copyOf(receiveBuffer, receiveBuffer.length));
}

From source file:org.chromium.ChromeUsb.java

static String directionName(int direction) {
    switch (direction) {
    case UsbConstants.USB_DIR_IN:
        return "in";
    case UsbConstants.USB_DIR_OUT:
        return "out";
    default://from  w  ww. ja  v  a 2  s.  c  om
        return "ERR:" + direction;
    }
}

From source file:org.chromium.ChromeUsb.java

private static int directionFromName(String direction) throws UsbError {
    direction = direction.toLowerCase();
    if ("out".equals(direction)) {
        return UsbConstants.USB_DIR_OUT; /* 0x00 */
    } else if ("in".equals(direction)) {
        return UsbConstants.USB_DIR_IN; /* 0x80 */
    } else {//from w w w.jav  a 2  s  .c  o m
        throw new UsbError("Unknown transfer direction: " + direction);
    }
}

From source file:org.chromium.ChromeUsb.java

private static byte[] getByteBufferForTransfer(CordovaArgs args, JSONObject params, int direction)
        throws JSONException {
    if (direction == UsbConstants.USB_DIR_OUT) {
        // OUT transfer requires data positional argument.
        return args.getArrayBuffer(ARG_INDEX_DATA_ARRAYBUFFER);
    } else {/* www . j  av  a2s  .c  o m*/
        // IN transfer requires client to pass the length to receive.
        return new byte[params.optInt("length")];
    }
}