From f1a569f18c80080149712dfe802ce4861feb6b1e Mon Sep 17 00:00:00 2001 From: Oleg Mazurov Date: Sat, 10 Sep 2011 20:13:18 -0600 Subject: [PATCH] ADK terminal demos added --- Usb.h | 10 ++++- examples/adk/term_test/term_test.pde | 63 ++++++++++++++++++++++++++++ examples/adk/term_time/term_time.pde | 49 ++++++++++++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 examples/adk/term_test/term_test.pde create mode 100644 examples/adk/term_time/term_time.pde diff --git a/Usb.h b/Usb.h index 8676589f..665ac578 100644 --- a/Usb.h +++ b/Usb.h @@ -18,6 +18,10 @@ e-mail : support@circuitsathome.com #ifndef _usb_h_ #define _usb_h_ + +//#define BOARD_BLACK_WIDDOW + + #define USB_METHODS_INLINE #include @@ -37,8 +41,12 @@ e-mail : support@circuitsathome.com /* shield pins. First parameter - SS pin, second parameter - INT pin */ -//typedef MAX3421e MAX3421E; // Black Widow + +#ifdef BOARD_BLACK_WIDDOW +typedef MAX3421e MAX3421E; // Black Widow +#else typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560 +#endif #define USBTRACE(s) (Serial.print((s))) #define USBTRACE2(s,r) (Serial.print((s)), Serial.println((r),HEX)) diff --git a/examples/adk/term_test/term_test.pde b/examples/adk/term_test/term_test.pde new file mode 100644 index 00000000..baacfc7d --- /dev/null +++ b/examples/adk/term_test/term_test.pde @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +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); + 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(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/examples/adk/term_time/term_time.pde b/examples/adk/term_time/term_time.pde new file mode 100644 index 00000000..071d5c6b --- /dev/null +++ b/examples/adk/term_time/term_time.pde @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +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); + 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 ); +}