2

I want to have a 2 two way (in and out) HID communication between a leonardo and an Android tablet (acting as a host). On the leonardo, I use Nicohood HID project I have successfully managed to make the code work on Linux, Windows and MacOs, so it is possible.

Using a pure android implementation, I can only receive data from the leonardo but not send to it...

From what I have seen in the descriptor, the data are sent from the device (IN direction) using a specific endpoint. For the other way (OUT, to the device), we must use the control endpoint.

Nevertheless, it doesn't work on android. Here is the code I used :

UsbDeviceConnection mUsbConnection = mUsbManager.openDevice(myDevice);
byte data[] = {7, 11, 13, 17};
int resOut = mUsbConnection.controlTransfer(0x21, 9, 200, 2, data, data.length, 50);

 // => resOut value is always -1 (didn't succeed to communicate)

For the parameters, I used the answers to this question: Using Android to Communicate with a USB HID Device and looked at libusb / nicohood hid communication examples on linux...

Out of luck, I tried to change the value from "200" to "0" or the index from 0 to 1 or 2, but I don't really know what they mean, and it didn't really help...

How can I send data to the device using the control endpoint with android ?

PS : I can read HID messages from the device, so it is not a permission issue.

Community
  • 1
  • 1
ice3
  • 335
  • 3
  • 15
  • Did you get a chance to put USB analyzer in between the android device and the micro controller to see why OUT transactions are failing? One question - What is the error you are getting? Is it USB transaction error or STALL error? – Shaibal Mar 21 '17 at 07:23

0 Answers0