public void SetOperationMode ()
{
byte[] sendArray = new byte[257];
byte[] detectionMode = {
(byte) 0x01,(byte) 0x17,(byte) 0xEE,(byte) 0x15,(byte) 0x40,(byte) 0x02,(byte) 0x02,
(byte) 0x00,(byte) 0x67,(byte) 0x0F,(byte) 0x80,(byte) 0x01,
(byte) 0xFF,(byte) 0x81,(byte) 0x01,(byte) 0x00,(byte) 0x82,
(byte) 0x01,(byte) 0x00,(byte) 0x83,(byte) 0x01,(byte) 0x00,
(byte) 0x84,(byte) 0x01,(byte) 0x00
};
System.arraycopy(detectionMode, 0, sendArray, 0, detectionMode.length);
int requestType = UsbConstants.USB_DIR_OUT | UsbConstants.USB_TYPE_CLASS | UsbConstants.USB_INTERFACE_SUBCLASS_BOOT;
int request = 0x09;
int value = 0x0301;
int index = 0x0000;
// write to device to set it in detectionMode, 0x01 for feature report 1
int read_response = sendFeatureReport(0x01, sendArray, sendArray.length);
String responseString = "Request";
Log.i(responseString, Integer.toString(read_response));
String byteString = byteArrayToHex(detectionMode);
Log.i(responseString, byteString);
//Read the response of the previous request
byte readBuffer[] = new byte[258];
// read from the device, 0x02 for feature report 2
read_response = getFeatureReport(0x02, readBuffer, readBuffer.length);
responseString = "Response";
Log.i(responseString, Integer.toString(read_response));
byteString = byteArrayToHex(readBuffer);
Log.i(responseString, byteString);
}
public int SendFeatureReport(int reportId, byte[] data, int length) {
if ((reportId & 0xFF) != reportId)
throw new IllegalArgumentException("reportId may only set the lowest 8 bits");
return zForceAirConnection.controlTransfer(
UsbConstants.USB_DIR_OUT | UsbConstants.USB_TYPE_CLASS | UsbConstants.USB_INTERFACE_SUBCLASS_BOOT,
0x09,
reportId | 0x0300,
0x0000, data, length, 0);
}
public int GetFeatureReport(int reportId, byte[] data, int length) {
if ((reportId & 0xFF) != reportId)
throw new IllegalArgumentException("reportId may only set the lowest 8 bits");
return zForceAirConnection.controlTransfer(
UsbConstants.USB_DIR_IN | UsbConstants.USB_TYPE_CLASS | UsbConstants.USB_INTERFACE_SUBCLASS_BOOT,
0x01,
reportId | 0x0300,
0x0000, data, length, 0);
} |