summaryrefslogtreecommitdiff
path: root/lib/usbhost/USB_Host_Shield_2.0/examples/adk
diff options
context:
space:
mode:
Diffstat (limited to 'lib/usbhost/USB_Host_Shield_2.0/examples/adk')
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino89
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/adk/adk_barcode/adk_barcode.ino91
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/adk/demokit_20/demokit_20.ino103
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/adk/term_test/term_test.ino65
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/adk/term_time/term_time.ino50
5 files changed, 398 insertions, 0 deletions
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino
new file mode 100644
index 0000000000..d59b9bb3dc
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino
@@ -0,0 +1,89 @@
+// The source for the Android application can be found at the following link: https://github.com/Lauszus/ArduinoBlinkLED
+// The code for the Android application is heavily based on this guide: http://allaboutee.com/2011/12/31/arduino-adk-board-blink-an-led-with-your-phone-code-and-explanation/ by Miguel
+#include <adk.h>
+
+//
+// CAUTION! WARNING! ATTENTION! VORSICHT! ADVARSEL! ¡CUIDADO! ВНИМАНИЕ!
+//
+// Pin 13 is occupied by the SCK pin on various Arduino boards,
+// including Uno, Duemilanove, etc., so use a different pin for those boards.
+//
+// CAUTION! WARNING! ATTENTION! VORSICHT! ADVARSEL! ¡CUIDADO! ВНИМАНИЕ!
+//
+#if defined(LED_BUILTIN)
+#define LED LED_BUILTIN // Use built in LED
+#else
+#define LED 9 // Set to something here that makes sense for your board.
+#endif
+
+
+// Satisfy IDE, which only needs to see the include statment in the ino.
+#ifdef dobogusinclude
+#include <spi4teensy3.h>
+#include <SPI.h>
+#endif
+
+USB Usb;
+ADK adk(&Usb, "TKJElectronics", // Manufacturer Name
+ "ArduinoBlinkLED", // Model Name
+ "Example sketch for the USB Host Shield", // Description (user-visible string)
+ "1.0", // Version
+ "http://www.tkjelectronics.dk/uploads/ArduinoBlinkLED.apk", // URL (web page to visit if no installed apps support the accessory)
+ "123456789"); // Serial Number (optional)
+
+uint32_t timer;
+bool connected;
+
+void setup() {
+ Serial.begin(115200);
+#if !defined(__MIPSEL__)
+ while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
+#endif
+ if (Usb.Init() == -1) {
+ Serial.print("\r\nOSCOKIRQ failed to assert");
+ while (1); // halt
+ }
+ pinMode(LED, OUTPUT);
+ Serial.print("\r\nArduino Blink LED Started");
+}
+
+void loop() {
+ Usb.Task();
+
+ if (adk.isReady()) {
+ if (!connected) {
+ connected = true;
+ Serial.print(F("\r\nConnected to accessory"));
+ }
+
+ uint8_t msg[1];
+ uint16_t len = sizeof(msg);
+ uint8_t rcode = adk.RcvData(&len, msg);
+ if (rcode && rcode != hrNAK) {
+ Serial.print(F("\r\nData rcv: "));
+ Serial.print(rcode, HEX);
+ } else if (len > 0) {
+ Serial.print(F("\r\nData Packet: "));
+ Serial.print(msg[0]);
+ digitalWrite(LED, msg[0] ? HIGH : LOW);
+ }
+
+ if (millis() - timer >= 1000) { // Send data every 1s
+ timer = millis();
+ rcode = adk.SndData(sizeof(timer), (uint8_t*)&timer);
+ if (rcode && rcode != hrNAK) {
+ Serial.print(F("\r\nData send: "));
+ Serial.print(rcode, HEX);
+ } else if (rcode != hrNAK) {
+ Serial.print(F("\r\nTimer: "));
+ Serial.print(timer);
+ }
+ }
+ } else {
+ if (connected) {
+ connected = false;
+ Serial.print(F("\r\nDisconnected from accessory"));
+ digitalWrite(LED, LOW);
+ }
+ }
+}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/adk/adk_barcode/adk_barcode.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/adk/adk_barcode/adk_barcode.ino
new file mode 100644
index 0000000000..a308ff0f83
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/adk/adk_barcode/adk_barcode.ino
@@ -0,0 +1,91 @@
+/**/
+/* A sketch demonstrating data exchange between two USB devices - a HID barcode scanner and ADK-compatible Android phone */
+/**/
+#include <adk.h>
+#include <hidboot.h>
+#include <usbhub.h>
+
+// Satisfy IDE, which only needs to see the include statment in the ino.
+#ifdef dobogusinclude
+#include <spi4teensy3.h>
+#include <SPI.h>
+#endif
+
+USB Usb;
+USBHub Hub1(&Usb);
+USBHub Hub2(&Usb);
+HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);
+
+ADK adk(&Usb,"Circuits@Home, ltd.",
+ "USB Host Shield",
+ "Arduino Terminal for Android",
+ "1.0",
+ "http://www.circuitsathome.com",
+ "0000000000000001");
+
+
+class KbdRptParser : public KeyboardReportParser
+{
+
+protected:
+ void OnKeyDown (uint8_t mod, uint8_t key);
+ void OnKeyPressed(uint8_t key);
+};
+
+void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
+{
+ uint8_t c = OemToAscii(mod, key);
+
+ if (c)
+ OnKeyPressed(c);
+}
+
+/* what to do when symbol arrives */
+void KbdRptParser::OnKeyPressed(uint8_t key)
+{
+const char* new_line = "\n";
+uint8_t rcode;
+uint8_t keylcl;
+
+ if( adk.isReady() == false ) {
+ return;
+ }
+
+ keylcl = key;
+
+ if( keylcl == 0x13 ) {
+ rcode = adk.SndData( strlen( new_line ), (uint8_t *)new_line );
+ }
+ else {
+ rcode = adk.SndData( 1, &keylcl );
+ }
+
+ Serial.print((char) keylcl );
+ Serial.print(" : ");
+ Serial.println( keylcl, HEX );
+};
+
+KbdRptParser Prs;
+
+void setup()
+{
+ Serial.begin(115200);
+#if !defined(__MIPSEL__)
+ while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
+#endif
+ Serial.println("\r\nADK demo start");
+
+ if (Usb.Init() == -1) {
+ Serial.println("OSCOKIRQ failed to assert");
+ while(1); //halt
+ }//if (Usb.Init() == -1...
+
+ Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);
+
+ delay( 200 );
+}
+
+void loop()
+{
+ Usb.Task();
+}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/adk/demokit_20/demokit_20.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/adk/demokit_20/demokit_20.ino
new file mode 100644
index 0000000000..f65adf57bb
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/adk/demokit_20/demokit_20.ino
@@ -0,0 +1,103 @@
+#include <adk.h>
+#include <usbhub.h>
+
+// Satisfy IDE, which only needs to see the include statment in the ino.
+#ifdef dobogusinclude
+#include <spi4teensy3.h>
+#include <SPI.h>
+#endif
+
+USB Usb;
+USBHub hub0(&Usb);
+USBHub hub1(&Usb);
+ADK adk(&Usb,"Google, Inc.",
+ "DemoKit",
+ "DemoKit Arduino Board",
+ "1.0",
+ "http://www.android.com",
+ "0000000012345678");
+uint8_t b, b1;
+
+
+#define LED1_RED 3
+#define BUTTON1 2
+
+void init_buttons()
+{
+ pinMode(BUTTON1, INPUT);
+
+ // enable the internal pullups
+ digitalWrite(BUTTON1, HIGH);
+}
+
+void init_leds()
+{
+ digitalWrite(LED1_RED, 0);
+
+ pinMode(LED1_RED, OUTPUT);
+}
+
+void setup()
+{
+ Serial.begin(115200);
+#if !defined(__MIPSEL__)
+ while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
+#endif
+ Serial.println("\r\nADK demo start");
+
+ if (Usb.Init() == -1) {
+ Serial.println("OSCOKIRQ failed to assert");
+ while(1); //halt
+ }//if (Usb.Init() == -1...
+
+
+ init_leds();
+ init_buttons();
+ b1 = digitalRead(BUTTON1);
+}
+
+void loop()
+{
+ uint8_t rcode;
+ uint8_t msg[3] = { 0x00 };
+ Usb.Task();
+
+ if( adk.isReady() == false ) {
+ analogWrite(LED1_RED, 255);
+ return;
+ }
+ uint16_t len = sizeof(msg);
+
+ rcode = adk.RcvData(&len, msg);
+ if( rcode ) {
+ USBTRACE2("Data rcv. :", rcode );
+ }
+ if(len > 0) {
+ USBTRACE("\r\nData Packet.");
+ // assumes only one command per packet
+ if (msg[0] == 0x2) {
+ switch( msg[1] ) {
+ case 0:
+ analogWrite(LED1_RED, 255 - msg[2]);
+ break;
+ }//switch( msg[1]...
+ }//if (msg[0] == 0x2...
+ }//if( len > 0...
+
+ msg[0] = 0x1;
+
+ b = digitalRead(BUTTON1);
+ if (b != b1) {
+ USBTRACE("\r\nButton state changed");
+ msg[1] = 0;
+ msg[2] = b ? 0 : 1;
+ rcode = adk.SndData( 3, msg );
+ if( rcode ) {
+ USBTRACE2("Button send: ", rcode );
+ }
+ b1 = b;
+ }//if (b != b1...
+
+
+ delay( 10 );
+}
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/adk/term_test/term_test.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/adk/term_test/term_test.ino
new file mode 100644
index 0000000000..db681c3b50
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/adk/term_test/term_test.ino
@@ -0,0 +1,65 @@
+#include <adk.h>
+#include <usbhub.h>
+
+// Satisfy IDE, which only needs to see the include statment in the ino.
+#ifdef dobogusinclude
+#include <spi4teensy3.h>
+#include <SPI.h>
+#endif
+
+USB Usb;
+//USBHub Hub(&Usb);
+
+ADK adk(&Usb,"Circuits@Home, ltd.",
+ "USB Host Shield",
+ "Arduino Terminal for Android",
+ "1.0",
+ "http://www.circuitsathome.com",
+ "0000000000000001");
+
+void setup()
+{
+ Serial.begin(115200);
+#if !defined(__MIPSEL__)
+ while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
+#endif
+ Serial.println("\r\nADK demo start");
+
+ if (Usb.Init() == -1) {
+ Serial.println("OSCOKIRQ failed to assert");
+ while(1); //halt
+ }//if (Usb.Init() == -1...
+}
+
+void loop()
+{
+ uint8_t rcode;
+ uint8_t msg[64] = { 0x00 };
+ const char* recv = "Received: ";
+
+ Usb.Task();
+
+ if( adk.isReady() == false ) {
+ return;
+ }
+ uint16_t len = 64;
+
+ rcode = adk.RcvData(&len, msg);
+ if( rcode & ( rcode != hrNAK )) {
+ USBTRACE2("Data rcv. :", rcode );
+ }
+ if(len > 0) {
+ USBTRACE("\r\nData Packet.");
+
+ for( uint8_t i = 0; i < len; i++ ) {
+ Serial.print((char)msg[i]);
+ }
+ /* sending back what was received */
+ rcode = adk.SndData( strlen( recv ), (uint8_t *)recv );
+ rcode = adk.SndData( strlen(( char * )msg ), msg );
+
+ }//if( len > 0 )...
+
+ delay( 1000 );
+}
+
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/adk/term_time/term_time.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/adk/term_time/term_time.ino
new file mode 100644
index 0000000000..a3f1dbc8cb
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/adk/term_time/term_time.ino
@@ -0,0 +1,50 @@
+#include <adk.h>
+#include <usbhub.h>
+
+// Satisfy IDE, which only needs to see the include statment in the ino.
+#ifdef dobogusinclude
+#include <spi4teensy3.h>
+#include <SPI.h>
+#endif
+
+USB Usb;
+
+ADK adk(&Usb,"Circuits@Home, ltd.",
+ "USB Host Shield",
+ "Arduino Terminal for Android",
+ "1.0",
+ "http://www.circuitsathome.com",
+ "0000000000000001");
+
+void setup()
+{
+ Serial.begin(115200);
+#if !defined(__MIPSEL__)
+ while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
+#endif
+ Serial.println("\r\nADK demo start");
+
+ if (Usb.Init() == -1) {
+ Serial.println("OSCOKIRQ failed to assert");
+ while(1); //halt
+ }//if (Usb.Init() == -1...
+}
+
+void loop()
+{
+ uint8_t buf[ 12 ] = { 0 }; //buffer to convert unsigned long to ASCII
+ const char* sec_ela = " seconds elapsed\r";
+ uint8_t rcode;
+
+ Usb.Task();
+ if( adk.isReady() == false ) {
+ return;
+ }
+
+ ultoa( millis()/1000, (char *)buf, 10 );
+
+ rcode = adk.SndData( strlen((char *)buf), buf );
+ rcode = adk.SndData( strlen( sec_ela), (uint8_t *)sec_ela );
+
+ delay( 1000 );
+}