class for emic 2 speech synthesis module

Dependents:   Alexa_Text BAT_senior_design_Azra BAT_senior_design_Nhi BAT_senior_design_Test ... more

Files at this revision

API Documentation at this revision

Comitter:
4180_1
Date:
Wed Nov 25 03:24:16 2015 +0000
Commit message:
ver 1.0

Changed in this revision

emic2.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r b95ede38e19d emic2.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/emic2.h	Wed Nov 25 03:24:16 2015 +0000
@@ -0,0 +1,41 @@
+#define speakf printf
+class emic2 : public Stream
+{
+public :
+    emic2(PinName tx, PinName rx): _cmd(tx,rx) {
+        _cmd.baud(9600);
+        _cmd.putc('X'); //stop talking if reset and not a power on
+        _cmd.putc('\r'); // Send a CR in case the system is already up
+        wait(1); //delay for emic power on boot or reset respone
+        while (_cmd.getc() != ':');   // When the Emic 2 has initialized and is ready, it will send a single ':'
+        while (_cmd.readable()) _cmd.getc();//flush out buffer just in case
+    };
+    void ready() {
+        while (_cmd.getc() != ':');
+        while (_cmd.readable()) _cmd.getc();//flush out recieve buffer just in case
+    };
+    int readable() {
+        return _cmd.readable();
+    };
+    int getc() {
+        return _cmd.getc();
+    }
+    void volume(int x) {
+        speakf("V%D\r",x);
+        ready();
+    }
+    void voice(int x) {
+        speakf("N%D\r",x);
+        ready();
+    }
+protected :
+    Serial     _cmd;
+    //used by printf - supply it and printf works!
+    virtual int _putc(int c) {
+        _cmd.putc(c);
+        return 0;
+    };
+    virtual int _getc() {
+        return -1;
+    };
+};