本文整理汇总了Java中android.hardware.usb.UsbConstants类的典型用法代码示例。如果您正苦于以下问题:Java UsbConstants类的具体用法?Java UsbConstants怎么用?Java UsbConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UsbConstants类属于android.hardware.usb包,在下文中一共展示了UsbConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AdbDevice
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
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;
}
示例2: UsbHidDevice
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
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;
}
}
}
示例3: reset
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
/**
* Sends a USB level CLASS_DEVICE_RESET control message.
* All PTP-over-USB devices support this operation.
* This is documented to clear stalls and camera-specific suspends,
* flush buffers, and close the current session.
*
*/
public void reset() throws PTPException
{
if (mConnection == null) throw new PTPException("No Connection");
mConnection.controlTransfer(
(int) ( UsbConstants.USB_DIR_OUT |
UsbConstants.USB_TYPE_CLASS /* |
UsbConstants.RECIPIENT_INTERFACE */),
CLASS_DEVICE_RESET,
0,
0,
new byte[0],
0,
DEFAULT_TIMEOUT //,
//false
);
session.close();
}
示例4: isCdcDevice
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
public static boolean isCdcDevice(UsbDevice device)
{
int iIndex = device.getInterfaceCount();
for(int i=0;i<=iIndex-1;i++)
{
UsbInterface iface = device.getInterface(i);
if(iface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
return true;
}
return false;
}
示例5: requestDevicePermissionIfNecessary
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
/**
* 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;
}
}
}
示例6: getStringDescriptor
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
/**
* Returns the string descriptor bytes for the given index
* @param index index of the descriptor
* @return the string descriptor bytes for the given index.
*/
@CalledByNative
byte[] getStringDescriptor(int index) {
if (mConnection == null) {
return new byte[0];
}
byte[] buffer = new byte[255];
int type = UsbConstants.USB_DIR_IN | UsbConstants.USB_TYPE_STANDARD;
int request = REQUEST_GET_DESCRIPTOR;
int value = (STRING_DESCRIPTOR_TYPE << 8) | index;
int read = mConnection.controlTransfer(type, request, value, 0, buffer, buffer.length, 0);
if (read < 0) {
return new byte[0];
}
return Arrays.copyOf(buffer, read);
}
示例7: controlTransfer
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
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);
}
/* control transfer is bidirectional, buffer should alway be passed */
callbackContext.success(Arrays.copyOf(receiveBuffer, receiveBuffer.length));
}
示例8: bulkTransfer
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
private void bulkTransfer(CordovaArgs args, JSONObject params,
final CallbackContext callbackContext) throws JSONException, UsbError {
ConnectedDevice dev = getDevice(params);
int endpointAddress = params.getInt("endpoint");
int interfaceNumber = endpointAddress >> ENDPOINT_IF_SHIFT;
int endpointNumber = endpointAddress & ((1 << ENDPOINT_IF_SHIFT) - 1);
if (interfaceNumber >= dev.getInterfaceCount() ||
endpointNumber >= dev.getEndpointCount(interfaceNumber)) {
throw new UsbError("Enpoint not found: " + endpointAddress);
}
int direction = directionFromName(params.getString("direction"));
byte[] buffer = getByteBufferForTransfer(args, params, direction);
int ret = dev.bulkTransfer(interfaceNumber, endpointNumber, direction, buffer,
params.getInt("timeout"));
if (ret < 0) {
throw new UsbError("Bulk transfer returned " + ret);
}
if (direction == UsbConstants.USB_DIR_IN) {
callbackContext.success(Arrays.copyOf(buffer, ret));
} else {
callbackContext.success();
}
}
示例9: interruptTransfer
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
private void interruptTransfer(CordovaArgs args, JSONObject params,
final CallbackContext callbackContext) throws JSONException, UsbError {
ConnectedDevice dev = getDevice(params);
int endpointAddress = params.getInt("endpoint");
int interfaceNumber = endpointAddress >> ENDPOINT_IF_SHIFT;
int endpointNumber = endpointAddress & ((1 << ENDPOINT_IF_SHIFT) - 1);
if (interfaceNumber >= dev.getInterfaceCount() ||
endpointNumber >= dev.getEndpointCount(interfaceNumber)) {
throw new UsbError("Enpoint not found: " + endpointAddress);
}
int direction = directionFromName(params.getString("direction"));
byte[] buffer = getByteBufferForTransfer(args, params, direction);
int ret = dev.interruptTransfer(interfaceNumber, endpointNumber, direction, buffer,
params.getInt("timeout"));
if (ret < 0) {
throw new UsbError("Interrupt transfer returned " + ret);
}
if (direction == UsbConstants.USB_DIR_IN) {
callbackContext.success(Arrays.copyOf(buffer, ret));
} else {
callbackContext.success();
}
}
示例10: getProductName
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
private String getProductName(UsbDevice device) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return getProductNameFromOs(device);
} else {
int deviceClass = device.getDeviceClass();
if (deviceClass != UsbConstants.USB_CLASS_PER_INTERFACE) {
return getClassName(deviceClass);
} else {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < device.getInterfaceCount(); i++) {
deviceClass = device.getInterface(i).getInterfaceClass();
if (builder.length() > 0) {
builder.append('/');
}
builder.append(getClassName(deviceClass));
}
return builder.toString();
}
}
}
示例11: open
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
@Override
public boolean open() {
iface = device.getInterface(0);
Log.d(TAG, "Endpoint Count: " + iface.getEndpointCount());
UsbEndpoint ep0 = iface.getEndpoint(0);
UsbEndpoint ep1 = iface.getEndpoint(1);
if (ep0.getDirection() == UsbConstants.USB_DIR_IN) {
in = ep0;
out = ep1;
} else {
in = ep1;
out = ep0;
}
con = manager.openDevice(device);
return con != null;
}
示例12: getVersionString
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
/**
* Returns the Version String of the HackRF.
*
* Note: This function interacts with the USB Hardware and
* should not be called from a GUI Thread!
*
* @return HackRF Version String
* @throws HackrfUsbException
*/
public String getVersionString() throws HackrfUsbException
{
byte[] buffer = new byte[255];
int len = 0;
len = this.sendUsbRequest(UsbConstants.USB_DIR_IN, HACKRF_VENDOR_REQUEST_VERSION_STRING_READ, 0, 0, buffer);
if (len < 1)
{
Log.e(logTag, "getVersionString: USB Transfer failed!");
throw(new HackrfUsbException("USB Transfer failed!"));
}
return new String(buffer);
}
示例13: getPartIdAndSerialNo
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
/**
* Returns the Part ID + Serial Number of the HackRF.
*
* Note: This function interacts with the USB Hardware and
* should not be called from a GUI Thread!
*
* @return int[2+6] => int[0-1] is Part ID; int[2-5] is Serial No
* @throws HackrfUsbException
*/
public int[] getPartIdAndSerialNo() throws HackrfUsbException
{
byte[] buffer = new byte[8+16];
int[] ret = new int[2+4];
if(this.sendUsbRequest(UsbConstants.USB_DIR_IN, HACKRF_VENDOR_REQUEST_BOARD_PARTID_SERIALNO_READ,
0, 0, buffer) != 8+16)
{
Log.e(logTag, "getPartIdAndSerialNo: USB Transfer failed!");
throw(new HackrfUsbException("USB Transfer failed!"));
}
for(int i = 0; i < 6; i++)
{
ret[i] = this.byteArrayToInt(buffer, 4*i);
}
return ret;
}
示例14: setSampleRate
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
/**
* Sets the Sample Rate of the HackRF.
*
* Note: This function interacts with the USB Hardware and
* should not be called from a GUI Thread!
*
* @param sampRate Sample Rate in Hz
* @param divider Divider
* @return true on success
* @throws HackrfUsbException
*/
public boolean setSampleRate(int sampRate, int divider) throws HackrfUsbException
{
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
try {
byteOut.write(this.intToByteArray(sampRate));
byteOut.write(this.intToByteArray(divider));
} catch (IOException e) {
Log.e(logTag,"setSampleRate: Error while converting arguments to byte buffer.");
return false;
}
if(this.sendUsbRequest(UsbConstants.USB_DIR_OUT, HACKRF_VENDOR_REQUEST_SAMPLE_RATE_SET,
0, 0, byteOut.toByteArray()) != 8)
{
Log.e(logTag, "setSampleRate: USB Transfer failed!");
throw(new HackrfUsbException("USB Transfer failed!"));
}
return true;
}
示例15: setTxVGAGain
import android.hardware.usb.UsbConstants; //导入依赖的package包/类
/**
* Sets the TX VGA Gain of the HackRF.
*
* Note: This function interacts with the USB Hardware and
* should not be called from a GUI Thread!
*
* @param gain TX VGA Gain (0-62)
* @return true on success
* @throws HackrfUsbException
*/
public boolean setTxVGAGain(int gain) throws HackrfUsbException
{
byte[] retVal = new byte[1];
if(gain > 47)
{
Log.e(logTag,"setTxVGAGain: TX VGA Gain must be within 0-47!");
return false;
}
if(this.sendUsbRequest(UsbConstants.USB_DIR_IN, HACKRF_VENDOR_REQUEST_SET_TXVGA_GAIN,
0, gain, retVal) != 1)
{
Log.e(logTag, "setTxVGAGain: USB Transfer failed!");
throw(new HackrfUsbException("USB Transfer failed!"));
}
if (retVal[0] == 0)
{
Log.e(logTag,"setTxVGAGain: HackRF returned with an error!");
return false;
}
return true;
}