EasyVR by Chad and Alty

Dependents:   Lab4

This is code for the EasyVR module that is used with Lab 4.

Revision:
0:5d93573903ed
diff -r 000000000000 -r 5d93573903ed easyvr.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/easyvr.cpp	Mon Oct 19 14:40:25 2015 +0000
@@ -0,0 +1,67 @@
+#include <easyvr.h>
+
+EasyVR::EasyVR( PinName tx, PinName rx ) : dev( tx, rx )
+{
+    // Nothing
+}
+
+void EasyVR::wakeup()
+{
+    do
+    {
+        send( CMD_BREAK );
+        wait( 0.2 );
+    } while( receive() != STS_SUCCESS );
+}
+
+void EasyVR::setup( int lang, int timeout )
+{
+    char err;
+    
+    send( CMD_ID );
+    
+    if( ( err = receive() ) != STS_ID )
+        term.printf( "(in setup() line %d) Error: %c\r\n", __LINE__, err );
+    
+    send( ARG_ACK );
+    
+    switch( a2i( err = receive() ) )
+    {
+        case 0:
+            term.printf( "VRbot detected\r\n" );
+            break;
+        case 1:
+            term.printf( "EasyVR detected\r\n" );
+            break;
+        default:
+            term.printf( "(in setup() line %d) Error: %c\r\n", __LINE__, err );
+            break;
+    }
+    
+    send( CMD_LANGUAGE );
+    send( i2a( lang ) );
+    
+    if( ( err = receive() ) != STS_SUCCESS )
+        term.printf( "(in setup() line %d) Error: %c\r\n", __LINE__, err );
+    
+    send( CMD_TIMEOUT );
+    send( i2a( timeout ) );
+    
+    if( ( err = receive() ) != STS_SUCCESS )
+        term.printf( "(in setup() line %d) Error: %c\r\n", __LINE__, err );
+}
+
+void EasyVR::send( char byte )
+{
+    dev.putc( byte );
+}
+
+char EasyVR::receive()
+{
+    return dev.getc();
+}
+
+void EasyVR::baud( int rate )
+{
+    dev.baud( rate );
+}