1 | /*
|
---|
2 |
|
---|
3 | ADK Terminal Test
|
---|
4 |
|
---|
5 | This demonstrates USB Host connectivity between an
|
---|
6 | Android phone and an Arduino Due.
|
---|
7 |
|
---|
8 | The ADK for the Arduino Due is a work in progress
|
---|
9 | For additional information on the Arduino ADK visit
|
---|
10 | http://labs.arduino.cc/ADK/Index
|
---|
11 |
|
---|
12 | created 27 June 2012
|
---|
13 | by Cristian Maglie
|
---|
14 |
|
---|
15 | */
|
---|
16 |
|
---|
17 | #include "variant.h"
|
---|
18 | #include <stdio.h>
|
---|
19 | #include <adk.h>
|
---|
20 |
|
---|
21 | // Accessory descriptor. It's how Arduino identifies itself to Android.
|
---|
22 | char applicationName[] = "Arduino_Terminal"; // the app on your phone
|
---|
23 | char accessoryName[] = "Arduino Due"; // your Arduino board
|
---|
24 | char companyName[] = "Arduino SA";
|
---|
25 |
|
---|
26 | // Make up anything you want for these
|
---|
27 | char versionNumber[] = "1.0";
|
---|
28 | char serialNumber[] = "1";
|
---|
29 | char url[] = "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTerminal_ICS_0001.apk";
|
---|
30 |
|
---|
31 | USBHost Usb;
|
---|
32 | ADK adk(&Usb, companyName, applicationName, accessoryName, versionNumber, url, serialNumber);
|
---|
33 |
|
---|
34 | void setup()
|
---|
35 | {
|
---|
36 | cpu_irq_enable();
|
---|
37 | printf("\r\nADK demo start\r\n");
|
---|
38 | delay(200);
|
---|
39 | }
|
---|
40 |
|
---|
41 | #define RCVSIZE 128
|
---|
42 |
|
---|
43 | void loop()
|
---|
44 | {
|
---|
45 | uint8_t buf[RCVSIZE];
|
---|
46 | uint32_t nbread = 0;
|
---|
47 | char helloworld[] = "Hello World!\r\n";
|
---|
48 |
|
---|
49 | Usb.Task();
|
---|
50 |
|
---|
51 | if (adk.isReady())
|
---|
52 | {
|
---|
53 | /* Write hello string to ADK */
|
---|
54 | adk.write(strlen(helloworld), (uint8_t *)helloworld);
|
---|
55 |
|
---|
56 | delay(1000);
|
---|
57 |
|
---|
58 | /* Read data from ADK and print to UART */
|
---|
59 | adk.read(&nbread, RCVSIZE, buf);
|
---|
60 | if (nbread > 0)
|
---|
61 | {
|
---|
62 | printf("RCV: ");
|
---|
63 | for (uint32_t i = 0; i < nbread; ++i)
|
---|
64 | {
|
---|
65 | printf("%c", (char)buf[i]);
|
---|
66 | }
|
---|
67 | printf("\r\n");
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|