You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.4 KiB

  1. #include <adk.h>
  2. #include <usbhub.h>
  3. // Satisfy IDE, which only needs to see the include statment in the ino.
  4. #ifdef dobogusinclude
  5. #include <spi4teensy3.h>
  6. #include <SPI.h>
  7. #endif
  8. USB Usb;
  9. //USBHub Hub(&Usb);
  10. ADK adk(&Usb,"Circuits@Home, ltd.",
  11. "USB Host Shield",
  12. "Arduino Terminal for Android",
  13. "1.0",
  14. "http://www.circuitsathome.com",
  15. "0000000000000001");
  16. void setup()
  17. {
  18. Serial.begin(115200);
  19. #if !defined(__MIPSEL__)
  20. while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  21. #endif
  22. Serial.println("\r\nADK demo start");
  23. if (Usb.Init() == -1) {
  24. Serial.println("OSCOKIRQ failed to assert");
  25. while(1); //halt
  26. }//if (Usb.Init() == -1...
  27. }
  28. void loop()
  29. {
  30. uint8_t rcode;
  31. uint8_t msg[64] = { 0x00 };
  32. const char* recv = "Received: ";
  33. Usb.Task();
  34. if( adk.isReady() == false ) {
  35. return;
  36. }
  37. uint16_t len = 64;
  38. rcode = adk.RcvData(&len, msg);
  39. if( rcode & ( rcode != hrNAK )) {
  40. USBTRACE2("Data rcv. :", rcode );
  41. }
  42. if(len > 0) {
  43. USBTRACE("\r\nData Packet.");
  44. for( uint8_t i = 0; i < len; i++ ) {
  45. Serial.print((char)msg[i]);
  46. }
  47. /* sending back what was received */
  48. rcode = adk.SndData( strlen( recv ), (uint8_t *)recv );
  49. rcode = adk.SndData( strlen(( char * )msg ), msg );
  50. }//if( len > 0 )...
  51. delay( 1000 );
  52. }