
emic2
emic2.h@3:677be555b290, 2020-06-19 (annotated)
- Committer:
- rickyqqj
- Date:
- Fri Jun 19 09:29:45 2020 +0000
- Revision:
- 3:677be555b290
- Parent:
- 2:32f26fe1d8ad
This is the central program for the Caecus central MCU
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:2128ea16088c | 1 | #define speakf printf |
4180_1 | 0:2128ea16088c | 2 | class emic2 : public Stream |
rickyqqj | 2:32f26fe1d8ad | 3 | |
4180_1 | 0:2128ea16088c | 4 | { |
4180_1 | 0:2128ea16088c | 5 | public : |
rickyqqj | 2:32f26fe1d8ad | 6 | emic2(PinName tx, PinName rx, PinName fakers): _cmd(tx,rx) { |
4180_1 | 0:2128ea16088c | 7 | _cmd.baud(9600); |
4180_1 | 0:2128ea16088c | 8 | _cmd.putc('X'); //stop talking if reset and not a power on |
4180_1 | 0:2128ea16088c | 9 | _cmd.putc('\r'); // Send a CR in case the system is already up |
rickyqqj | 2:32f26fe1d8ad | 10 | |
rickyqqj | 2:32f26fe1d8ad | 11 | DigitalIn frx(PF_1); |
4180_1 | 0:2128ea16088c | 12 | wait(1); //delay for emic power on boot or reset respone |
rickyqqj | 2:32f26fe1d8ad | 13 | while (frx == 1); //00111010 |
rickyqqj | 2:32f26fe1d8ad | 14 | /* while (_cmd.getc() != ':'); // When the Emic 2 has initialized and is ready, it will send a single ':' |
rickyqqj | 2:32f26fe1d8ad | 15 | while (_cmd.readable()) _cmd.getc();//flush out buffer just in case */ |
4180_1 | 0:2128ea16088c | 16 | }; |
4180_1 | 0:2128ea16088c | 17 | void ready() { |
rickyqqj | 2:32f26fe1d8ad | 18 | DigitalIn frx(PF_1); |
rickyqqj | 2:32f26fe1d8ad | 19 | while (frx == 1); |
rickyqqj | 2:32f26fe1d8ad | 20 | |
rickyqqj | 2:32f26fe1d8ad | 21 | |
rickyqqj | 2:32f26fe1d8ad | 22 | /* while (_cmd.getc() != ':'); |
rickyqqj | 2:32f26fe1d8ad | 23 | while (_cmd.readable()) _cmd.getc();//flush out recieve buffer just in case*/ |
4180_1 | 0:2128ea16088c | 24 | }; |
4180_1 | 0:2128ea16088c | 25 | int readable() { |
4180_1 | 0:2128ea16088c | 26 | return _cmd.readable(); |
4180_1 | 0:2128ea16088c | 27 | }; |
4180_1 | 0:2128ea16088c | 28 | int getc() { |
4180_1 | 0:2128ea16088c | 29 | return _cmd.getc(); |
4180_1 | 0:2128ea16088c | 30 | } |
4180_1 | 0:2128ea16088c | 31 | void volume(int x) { |
4180_1 | 0:2128ea16088c | 32 | speakf("V%D\r",x); |
4180_1 | 0:2128ea16088c | 33 | ready(); |
4180_1 | 0:2128ea16088c | 34 | } |
4180_1 | 0:2128ea16088c | 35 | void voice(int x) { |
4180_1 | 0:2128ea16088c | 36 | speakf("N%D\r",x); |
4180_1 | 0:2128ea16088c | 37 | ready(); |
4180_1 | 0:2128ea16088c | 38 | } |
4180_1 | 0:2128ea16088c | 39 | protected : |
4180_1 | 0:2128ea16088c | 40 | Serial _cmd; |
4180_1 | 0:2128ea16088c | 41 | //used by printf - supply it and printf works! |
4180_1 | 0:2128ea16088c | 42 | virtual int _putc(int c) { |
4180_1 | 0:2128ea16088c | 43 | _cmd.putc(c); |
4180_1 | 0:2128ea16088c | 44 | return 0; |
4180_1 | 0:2128ea16088c | 45 | }; |
4180_1 | 0:2128ea16088c | 46 | virtual int _getc() { |
4180_1 | 0:2128ea16088c | 47 | return -1; |
4180_1 | 0:2128ea16088c | 48 | }; |
4180_1 | 0:2128ea16088c | 49 | }; |