svoe

Dependencies:   mbed mbed-STM32F103C8T6 MPU6050_1

Committer:
dima285
Date:
Tue Aug 06 14:13:55 2019 +0000
Branch:
svoe
Revision:
23:bc05a104be10
Parent:
17:bd6b6ac89e0e
06.08.19

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Stas285 15:960b922433d1 1 char sound_out_send_buf[10]= {0x7E, 0xFF, 06, 03, 00, 00, 00, 00, 00, 0xEF};
Stas285 15:960b922433d1 2 char sound_in_receive_buf[64];
Stas285 15:960b922433d1 3 int sound_in_receive_counter;
Stas285 6:6e89cdc3db92 4
Stas285 6:6e89cdc3db92 5 void play(short int record_num){
Stas285 15:960b922433d1 6 sound_out_send_buf[5] = (char)(record_num >> 8); //high byte
Stas285 15:960b922433d1 7 sound_out_send_buf[6] = (char)record_num; //low byte
Stas285 6:6e89cdc3db92 8 short int sum = 0;
Stas285 15:960b922433d1 9 for (int i=1; i<7; i++) sum -= sound_out_send_buf[i];
Stas285 15:960b922433d1 10 sound_out_send_buf[7] = (char)(sum >> 8); //high byte
Stas285 15:960b922433d1 11 sound_out_send_buf[8] = (char)sum; //low byte
Stas285 15:960b922433d1 12 for (int i = 0; i < 10; i++) sound_out.putc(sound_out_send_buf[i]);
Stas285 15:960b922433d1 13 }
Stas285 15:960b922433d1 14
Stas285 15:960b922433d1 15 void start_recognizer(){
Stas285 15:960b922433d1 16 sound_in.putc(0xAA);
Stas285 15:960b922433d1 17 sound_in.putc(0x05); //0x09); //2+N
Stas285 15:960b922433d1 18 sound_in.putc(0x30); //command "Load to recognizer"
Stas285 15:960b922433d1 19 sound_in.putc(0x00); //load command 00 to recognizer
Stas285 15:960b922433d1 20 sound_in.putc(0x01);
Stas285 15:960b922433d1 21 sound_in.putc(0x02);
Stas285 15:960b922433d1 22 // sound_in.putc(0x03);
Stas285 15:960b922433d1 23 // sound_in.putc(0x04);
Stas285 15:960b922433d1 24 // sound_in.putc(0x05);
Stas285 15:960b922433d1 25 // sound_in.putc(0x06); //load command 06 to recognizer
Stas285 15:960b922433d1 26 sound_in.putc(0x0A);
Stas285 6:6e89cdc3db92 27 }
dima285 17:bd6b6ac89e0e 28
Stas285 15:960b922433d1 29
Stas285 15:960b922433d1 30 void voice_command_process(){
Stas285 15:960b922433d1 31 if(sound_in.readable()){
dima285 23:bc05a104be10 32 //if (myled == 0 ) myled = 1;else myled = 0;
Stas285 15:960b922433d1 33 char tmc = sound_in.getc();
dima285 17:bd6b6ac89e0e 34 wifi.putc(tmc);
Stas285 15:960b922433d1 35 if (tmc == 0xAA) sound_in_receive_counter = 0; else sound_in_receive_counter++; if(sound_in_receive_counter > 15) sound_in_receive_counter = 15;
Stas285 15:960b922433d1 36 sound_in_receive_buf[sound_in_receive_counter] = tmc;
Stas285 15:960b922433d1 37 if (sound_in_receive_counter == 5){
Stas285 15:960b922433d1 38 switch(tmc){
dima285 17:bd6b6ac89e0e 39 case 0: play(rand()%10+1); break;
dima285 17:bd6b6ac89e0e 40 case 1: play(rand()%10+1); break;
dima285 17:bd6b6ac89e0e 41 case 2: play(rand()%10+1); break;
dima285 17:bd6b6ac89e0e 42 case 3: play(rand()%10+1); break;
Stas285 15:960b922433d1 43 case 4: play(1); break;
Stas285 15:960b922433d1 44 case 5: play(1); break;
Stas285 15:960b922433d1 45 case 6: play(1); break;
Stas285 15:960b922433d1 46 }
Stas285 15:960b922433d1 47 }
Stas285 15:960b922433d1 48 }
Stas285 15:960b922433d1 49 }
dima285 17:bd6b6ac89e0e 50
dima285 17:bd6b6ac89e0e 51
dima285 17:bd6b6ac89e0e 52 /*void sound_in_init(){
dima285 17:bd6b6ac89e0e 53 sound_in.attach(&voice_command_receive);
dima285 17:bd6b6ac89e0e 54 }*/