Ricky Jiang
/
TTSmbed_groupproject
emic2
emic2.h
- Committer:
- rickyqqj
- Date:
- 2020-03-02
- Revision:
- 2:32f26fe1d8ad
- Parent:
- 0:2128ea16088c
File content as of revision 2:32f26fe1d8ad:
#define speakf printf class emic2 : public Stream { public : emic2(PinName tx, PinName rx, PinName fakers): _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 DigitalIn frx(PF_1); wait(1); //delay for emic power on boot or reset respone while (frx == 1); //00111010 /* 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() { DigitalIn frx(PF_1); while (frx == 1); /* 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; }; };