#include "mbed.h" #include "string.h" #include DigitalOut leds[] = { (LED1), (LED2), (LED3), (LED4) }; Serial device(p13, p14); // tx, rx Serial pc(USBTX,USBRX); int main() { //main variables char output[4]; char rchar = 'z'; char status = '0'; int count = 0; int numLeds = sizeof(leds)/sizeof(DigitalOut); //wake up device device.putc('b'); while (device.getc()!='o') { device.putc('b'); leds[0] = 1; wait(0.2); } //reset all leds initially for(int i = 0; i < numLeds; i++) { leds[i] = 0; } //wait until ready while (device.readable()!=0) {} //main loop while (1) { wait: leds[3] = !leds[3]; //alternate last LED so user knows when the VR is listening while (pc.readable() == 0) {} //wait for a readable byte status = pc.getc(); if(status == 'n') { while ( count < 4 ) { leds[3] = !leds[3]; device.putc('d'); //Start Group Recognition device.putc('B'); //Use Group 1 wait(3); //give the EasyVR time to gather input (actual wait time around 4~5 sec) if (device.getc()=='r') { //wait for success byte from EasyVR device.putc(' '); rchar=device.getc(); //retrieve if( rchar != 'v' ) { //if retrieved char isnt the garbage character output[count] = rchar; //store char leds[count] = 1; count++; } else { //pc.printf("recognition failed\n"); } } } //successful input string //reset all leds for(int i = 0; i < numLeds; i++) { leds[i] = 0; } } else { //not correct string request byte, wait for 'n' goto wait; } //Successful Request, send confirmation byte pc.putc('n'); for(int i = 0; i < 4; i++) { do { while (pc.readable() == 0) {} //wait for a readable byte status = pc.getc(); } while( status != ' '); pc.putc(output[i]); } //terminate communication do { while (pc.readable() == 0) {} //wait for a readable byte status = pc.getc(); } while( status != ' '); pc.putc('s'); //send termination byte count = 0; } }