Chad Miller / EasyVR

Dependents:   Lab4

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers easyvr.cpp Source File

easyvr.cpp

00001 #include <easyvr.h>
00002 
00003 EasyVR::EasyVR( PinName tx, PinName rx ) : dev( tx, rx )
00004 {
00005     // Nothing
00006 }
00007 
00008 void EasyVR::wakeup()
00009 {
00010     do
00011     {
00012         send( CMD_BREAK );
00013         wait( 0.2 );
00014     } while( receive() != STS_SUCCESS );
00015 }
00016 
00017 void EasyVR::setup( int lang, int timeout )
00018 {
00019     char err;
00020     
00021     send( CMD_ID );
00022     
00023     if( ( err = receive() ) != STS_ID )
00024         term.printf( "(in setup() line %d) Error: %c\r\n", __LINE__, err );
00025     
00026     send( ARG_ACK );
00027     
00028     switch( a2i( err = receive() ) )
00029     {
00030         case 0:
00031             term.printf( "VRbot detected\r\n" );
00032             break;
00033         case 1:
00034             term.printf( "EasyVR detected\r\n" );
00035             break;
00036         default:
00037             term.printf( "(in setup() line %d) Error: %c\r\n", __LINE__, err );
00038             break;
00039     }
00040     
00041     send( CMD_LANGUAGE );
00042     send( i2a( lang ) );
00043     
00044     if( ( err = receive() ) != STS_SUCCESS )
00045         term.printf( "(in setup() line %d) Error: %c\r\n", __LINE__, err );
00046     
00047     send( CMD_TIMEOUT );
00048     send( i2a( timeout ) );
00049     
00050     if( ( err = receive() ) != STS_SUCCESS )
00051         term.printf( "(in setup() line %d) Error: %c\r\n", __LINE__, err );
00052 }
00053 
00054 void EasyVR::send( char byte )
00055 {
00056     dev.putc( byte );
00057 }
00058 
00059 char EasyVR::receive()
00060 {
00061     return dev.getc();
00062 }
00063 
00064 void EasyVR::baud( int rate )
00065 {
00066     dev.baud( rate );
00067 }