Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
easyvr.h
00001 #ifndef EASYVR_H_DEFINED 00002 #define EASYVR_H_DEFINED 00003 00004 #include <mbed.h> 00005 00006 #define ARG_MIN '@' 00007 #define ARG_MAX '`' 00008 #define ARG_ZERO 'A' 00009 #define ARG_ACK ' ' 00010 00011 #define CMD_BREAK 'b' 00012 #define CMD_SLEEP 's' 00013 #define CMD_KNOB 'k' 00014 #define CMD_LEVEL 'v' 00015 #define CMD_LANGUAGE 'l' 00016 #define CMD_TIMEOUT 'o' 00017 #define CMD_RECOG_SI 'i' 00018 #define CMD_TRAIN_SD 't' 00019 #define CMD_GROUP_SD 'g' 00020 #define CMD_UNGROUP_SD 'u' 00021 #define CMD_RECOG_SD 'd' 00022 #define CMD_ERASE_SD 'e' 00023 #define CMD_NAME_SD 'n' 00024 #define CMD_COUNT_SD 'c' 00025 #define CMD_DUMP_SD 'p' 00026 #define CMD_MASK_SD 'm' 00027 #define CMD_RESETALL 'r' 00028 #define CMD_ID 'x' 00029 #define CMD_DELAY 'y' 00030 #define CMD_BAUDRATE 'a' 00031 #define CMD_QUERY_IO 'q' 00032 #define CMD_PLAY_SX 'w' 00033 #define CMD_DUMP_SX 'h' 00034 00035 #define STS_MASK 'k' 00036 #define STS_COUNT 'c' 00037 #define STS_AWAKEN 'w' 00038 #define STS_DATA 'd' 00039 #define STS_ERROR 'e' 00040 #define STS_INVALID 'v' 00041 #define STS_TIMEOUT 't' 00042 #define STS_INTERR 'i' 00043 #define STS_SUCCESS 'o' 00044 #define STS_RESULT 'r' 00045 #define STS_SIMILAR 's' 00046 #define STS_OUT_OF_MEM 'm' 00047 #define STS_ID 'x' 00048 #define STS_PIN 'p' 00049 #define STS_TABLE_SX 'd' 00050 00051 #define ERR_DATACOL_TOO_NOISY 0x3 00052 #define ERR_DATACOL_TOO_SOFT 0x4 00053 #define ERR_DATACOL_TOO_LOUD 0x5 00054 #define ERR_DATACOL_TOO_SOON 0x6 00055 #define ERR_DATACOL_TOO_CHOPPY 0x7 00056 #define ERR_RECOG_FAIL 0x11 00057 #define ERR_RECOG_LOW_CONF 0x12 00058 #define ERR_RECOG_MID_CONF 0x13 00059 #define ERR_RECOG_BAD_TEMPLATE 0x14 00060 #define ERR_RECOG_DURATION 0x17 00061 #define ERR_SYNTH_BAD_VERSION 0x4A 00062 #define ERR_SYNTH_BAD_MSG 0x4E 00063 #define ERR_NOT_A_WORD 0x80 00064 00065 #define i2a(i) ((char)((i)+ARG_ZERO)) 00066 #define a2i(a) ((int)((a)-ARG_ZERO)) 00067 00068 extern Serial term; 00069 00070 /** EasyVR class for ECE 4180 lab 4. 00071 * Used for interfacing with an EasyVR module. 00072 * 00073 * Example: 00074 * @code 00075 * #include "mbed.h" 00076 * #include "easyvr.h" 00077 * 00078 * EasyVR easyVR( p27, p28 ); 00079 * 00080 * int main() 00081 * { 00082 * easyVR.wakeup(); 00083 * easyVR.setup(); 00084 * } 00085 * @endcode 00086 */ 00087 class EasyVR 00088 { 00089 public: 00090 /** EasyVR constructor. 00091 * Initializes the serial interface for the EasyVR module. 00092 * 00093 * @param tx The TX pin on the mbed that should be used. This connects to the EasyVR's RX pin. 00094 * @param rx The RX pin on the mbed that should be used. This connects to the EasyVR's TX pin. 00095 */ 00096 EasyVR( PinName tx, PinName rx ); 00097 00098 /** Wakes up the EasyVR by sending it a "break" signal until a reply 00099 * of "success" has been received. 00100 */ 00101 void wakeup(); 00102 00103 /** Sets up the EasyVR. This includes ensuring the EasyVR module is a valid EasyVR device, 00104 * setting its timeout value, and its language. 00105 * 00106 * @param lang The language to be used, as an encoded integer. i.e. 0 is 'A', 1 is 'B', and so forth. 00107 * @param timeout The timeout to be used, in seconds, as an encoded integer. 00108 */ 00109 void setup( int lang, int timeout ); 00110 00111 /** Sends a single byte to the EasyVR. This is most commonly used to send commands 00112 * and parameters for those commands. Note that this is just a wrapper for the EasyVR's 00113 * serial interface's putc() function. 00114 * 00115 * @param byte The byte to be sent. 00116 * @see Serial.putc() 00117 */ 00118 void send( char byte ); 00119 00120 /** Receives a single byte from the EasyVR. This is most commonly used to receive 00121 * signals from the EasyVR. Note that this is just a wrapper for the EasyVR's serial 00122 * interface's getc() function. 00123 * 00124 * Be aware that this is a blocking method - it will stall the program until a byte is received! 00125 * 00126 * @return A single byte from the EasyVR. 00127 * @see Serial.putc() 00128 */ 00129 char receive(); 00130 00131 /** Sets the EasyVR's baud rate. For speech recognition, this must be exactly 9600. 00132 * 00133 * @param rate The baud rate the EasyVR should communicate with. 00134 * @see Serial.baud() 00135 */ 00136 void baud( int rate ); 00137 00138 private: 00139 Serial dev; 00140 }; 00141 00142 #endif // EASYVR_H_DEFINED
Generated on Fri Jul 15 2022 06:55:58 by
1.7.2