안녕하세요?
Windows C++에서 USB HID 장비를 HidD_SetFeature 함수를 이용하여 다음과 같이 제어하였습니다.
unsigned char feature[9] = {0};
feature[0] = 0;
feature[1] = 0xFE;
if(HidD_SetFeature(hDevice, feature, 9))
return 0;
return -1;
이와 같은 제어를 안드로이드에서 하려면 어떻게 해야 하나요?
UsbManager에서 디바이스 검색 및 오픈까지는 정상으로 되어 product name, manufacturer name 까지는 정상으로 얻었습니다.
public boolean open(UsbManager manager, UsbDevice device)
{
UsbDeviceConnection connection = manager.openDevice(device);
if(connection == null)
return false;
UsbInterface intf = device.getInterface(0);
// Claims exclusive access to a UsbInterface.
// This must be done before sending or receiving data on
// any UsbEndpoints belonging to the interface.
connection.claimInterface(intf, true);
// getRawDescriptors can be used to access descriptors
// not supported directly via the higher level APIs,
// like getting the manufacturer and product names.
// because it returns bytes, you can get a variety of
// different data types.
byte[] rawDescs = connection.getRawDescriptors();
String manufacturer = "", product = "";
try
{
byte[] buffer = new byte[255];
int idxMan = rawDescs[14];
int idxPrd = rawDescs[15];
int rdo = connection.controlTransfer(UsbConstants.USB_DIR_IN
| UsbConstants.USB_TYPE_STANDARD, STD_USB_REQUEST_GET_DESCRIPTOR,
(LIBUSB_DT_STRING << 8) | idxMan, 0, buffer, 0xFF, 0);
manufacturer = new String(buffer, 2, rdo - 2, "UTF-16LE");
rdo = connection.controlTransfer(UsbConstants.USB_DIR_IN
| UsbConstants.USB_TYPE_STANDARD, STD_USB_REQUEST_GET_DESCRIPTOR,
(LIBUSB_DT_STRING << 8) | idxPrd, 0, buffer, 0xFF, 0);
product = new String(buffer, 2, rdo - 2, "UTF-16LE");
byte [] feature = new byte[9];
for(int i = 0; i < feature.length; i ++)
feature[i] = 0;
feature[1] = (byte)0xFE;
// 이것이 제대로 안되네요....
// connection.controlTransfer(0x20, 0x09,
// 0x0, 0x01, feature, feature.length, 0);
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
return true;
}
여기서 feature를 어떻게 전송해야 하는지 좀 가르쳐 주세요.....
감사합니다.