svoe
Dependencies: mbed mbed-STM32F103C8T6 MPU6050_1
Diff: sound.h
- Revision:
- 15:960b922433d1
- Parent:
- 6:6e89cdc3db92
- Child:
- 17:bd6b6ac89e0e
- Child:
- 18:af32a5e7e8ae
--- a/sound.h Sun Nov 18 13:33:28 2018 +0000 +++ b/sound.h Sat Dec 01 14:25:04 2018 +0000 @@ -1,12 +1,47 @@ -//char sound_send_buf[10]= {0x7E, 0xFF, 06, 00, 00, 00, 00, 00, 00, 0xEF}; -char sound_send_buf[10]= {0x7E, 0xFF, 06, 03, 00, 00, 00, 00, 00, 0xEF}; +char sound_out_send_buf[10]= {0x7E, 0xFF, 06, 03, 00, 00, 00, 00, 00, 0xEF}; +char sound_in_receive_buf[64]; +int sound_in_receive_counter; void play(short int record_num){ - sound_send_buf[5] = (char)(record_num >> 8); //high byte - sound_send_buf[6] = (char)record_num; //low byte + sound_out_send_buf[5] = (char)(record_num >> 8); //high byte + sound_out_send_buf[6] = (char)record_num; //low byte short int sum = 0; - for (int i=1; i<7; i++) sum += sound_send_buf[i]; - sound_send_buf[7] = (char)(sum >> 8); //high byte - sound_send_buf[8] = (char)sum; //low byte - for (int i = 0; i < 10; i++) pc.putc(sound_send_buf[i]); + for (int i=1; i<7; i++) sum -= sound_out_send_buf[i]; + sound_out_send_buf[7] = (char)(sum >> 8); //high byte + sound_out_send_buf[8] = (char)sum; //low byte + for (int i = 0; i < 10; i++) sound_out.putc(sound_out_send_buf[i]); + } + +void start_recognizer(){ + sound_in.putc(0xAA); + sound_in.putc(0x05); //0x09); //2+N + sound_in.putc(0x30); //command "Load to recognizer" + sound_in.putc(0x00); //load command 00 to recognizer + sound_in.putc(0x01); + sound_in.putc(0x02); +// sound_in.putc(0x03); +// sound_in.putc(0x04); +// sound_in.putc(0x05); +// sound_in.putc(0x06); //load command 06 to recognizer + sound_in.putc(0x0A); } + +void voice_command_process(){ + if(sound_in.readable()){ + char tmc = sound_in.getc(); + if (tmc == 0xAA) sound_in_receive_counter = 0; else sound_in_receive_counter++; if(sound_in_receive_counter > 15) sound_in_receive_counter = 15; + sound_in_receive_buf[sound_in_receive_counter] = tmc; + if (sound_in_receive_counter == 5){ + switch(tmc){ + case 0: play(1); break; + case 1: play(1); break; + case 2: play(1); break; + case 3: play(1); break; + case 4: play(1); break; + case 5: play(1); break; + case 6: play(1); break; + } + } + } + } + \ No newline at end of file