2

I need some help finding the documentation of .read(). I know this is easy, but I can't find it. I've search and searched, and this page on the android side is the closest I could find - http://developer.android.com/guide/topics/usb/accessory.html.

Here is the arduino code splice I am trying to interpret. I need to know how to modify the read() part for my needs. Thanks

AndroidAccessory acc("Manufacturer",
"Model",
"Description",
"1.0",
"hey.now.what",
"0000000012345678");

acc.read(msgIn, sizeof(msgIn), 1)
SwimBikeRun
  • 4,192
  • 11
  • 49
  • 85

1 Answers1

1

I was looking the same thing as you did. After googling around and trying it by myself, I managed to build up something like this:

Declaration:

int AndroidAccessory::read(void *buff, int len, unsigned int nakLimit);

Reads data from the Android device into the array pointed to by buff. It reads len number of bytes. Reading is stopped when len bytes is read or nakLimit number of NAKs is received from the USB controller. In case of Full Speed USB a NAK will be generated every 1ms. (according to the second source link).

The return value is the number of bytes available, not the number of bytes read. If you read less bytes than there are available, those extra bytes seem to be ignored.

In my experiments I found out that NAK interval is much smaller. With my Arduino Mega ADK, I found out that one second wait equals roughly nakLimit of 14000.

Sources:

Community
  • 1
  • 1
Zouppen
  • 1,214
  • 11
  • 17