Words in Typing mode
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_Type_word by
Diff: main.cpp
- Revision:
- 39:8cc80f0b4398
- Parent:
- 38:68f7f54b723b
- Child:
- 40:85be3490d3a7
--- a/main.cpp Sat Dec 02 01:49:48 2017 +0000 +++ b/main.cpp Sat Dec 02 23:53:06 2017 +0000 @@ -209,171 +209,6 @@ myTTS.volume(1); //max volume is 18 myTTS.voice(2); -/* - char* braille; - char userinput; - - // INITIAL RESET - if (type == 0) { - int reset = 1; - myTTS.speakf("SWelcome to Bat, the Braille Assistive Teacher. This device will help you learn how to write and type braille. Please setup the device by pressing down all the buttons.\r"); - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response - while(reset == 1) { - wait(3); - sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(), - button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress()); - userinput = buttonarr.checkVal(braille); - if(userinput == 'Z') { - reset = 0; - } else { - //reset = 0; - myTTS.speakf("SSetup failed. Please try again.\r"); - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response - } - } - } - - for(int i = 0; i < lettersize; i++) { //iterate through the letter array - char currletter = letter[i][0]; - //pc.printf("letter: %c \n", currletter); - int* pinsup = buttonarr.pinsUp(currletter); - int currpress; - int numpinsups = pinsup[0]; // size of array is first element of pinsup - //string presspin; - string presspin = "STo write the letter "; - presspin = presspin + letter[i]; - presspin = presspin + ", press buttons"; - - for (int j = 1; j < numpinsups; j++) { // get what pins to press - currpress = pinsup[j]; - switch (currpress) { - case 1: - presspin = presspin + " 1,"; - break; - case 2: - presspin = presspin + " 2,"; - break; - case 3: - presspin = presspin + " 3,"; - break; - case 4: - presspin = presspin + " 4,"; - break; - case 5: - presspin = presspin + " 5,"; - break; - case 6: - presspin = presspin + " 6,"; - break; - } - } - myTTS.speakf("%s\r",presspin); - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response - wait(2); - //pc.printf("hello"); - - //WORKS UP TO HERE - char* braille; - char userinput; - char* oldbraille; - if (type == 0) { - sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(), - button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress()); - userinput = buttonarr.checkVal(braille); - } else { - // TYPE MODE - sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), - !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); - userinput = buttonarr.checkVal(braille); - oldbraille = braille; - } - - int currwrong; - string wrongpin; - // check result - pc.printf("\n %c %c", userinput, currletter); - int* wrongpins = buttonarr.wrongPins(braille, currletter); - int test = 1; - while(test == 1) { - //pc.printf("In while loop"); - wrongpin = "SYour answer is incorrect. Buttons"; - //wrongpin = wrongpin + letter[i]; - //wrongpin = wrongpin + ", press pins"; - for (int j = 1; j < wrongpins[0]; j++) { // get what pins are wrong - currwrong = wrongpins[j]; - //pc.printf("currwrong: %d", currwrong); - switch (currwrong) { - case 1: - wrongpin = wrongpin + " 1,"; - break; - case 2: - wrongpin = wrongpin + " 2,"; - break; - case 3: - wrongpin = wrongpin + " 3,"; - break; - case 4: - wrongpin = wrongpin + " 4,"; - break; - case 5: - wrongpin = wrongpin + " 5,"; - break; - case 6: - wrongpin = wrongpin + " 6,"; - break; - } - } - //pc.printf("end for loop"); - if (wrongpins[0] > 1) { - wrongpin = wrongpin + " are wrong. Please try again."; - myTTS.speakf("%s\r",wrongpin); - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response - wait(2); - //UPDATE THE PINS THAT ARE WRONG BY CHECKING AGAIN BELOW - //char* braille; - if (type == 0) { - sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(), - button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress()); - userinput = buttonarr.checkVal(braille); - } else { - // TYPE MODE - sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(), - button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress()); - userinput = buttonarr.checkVal(braille); - } - // get input - //pc.printf("Your input was: %c", userinput); - - // check result - wrongpins = buttonarr.wrongPins(braille, currletter); - } else { - test = 0; - myTTS.speakf("SGood job!\r"); - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response - } - } - - if (type == 0) { - int reset = 1; - myTTS.speakf("SNow reset by pressing down all the buttons.\r"); - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response - while(reset == 1) { - char* braille; - sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(), - button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress()); - userinput = buttonarr.checkVal(braille); - if(userinput == 'Z') { - reset = 0; - } else { - wait(2); - myTTS.speakf("SPlease try again.\r"); - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response - } - } - } - //pc.printf("wrongpins are: %d", wrongpins[0]); - }*/ - // WORD CODE // WORD COUNTER @@ -388,12 +223,22 @@ //SETTING UP SERVOS TO RELEASE FOR TYPING MODE FREEZES THE CODE buttonarr.setup(); //Reset servos so that buttons are up for typing mode + + button1.setMode(1); + button2.setMode(1); + button3.setMode(1); + button4.setMode(1); + button5.setMode(1); + button6.setMode(1); + string currword; int wordsize = sizeof(word)/sizeof(word[0]); //myTTS.speakf("SLet us now put these letters together to form words. Please reset buttons after each letter. Press down the submit button when done.\r"); // Send the desired string to convert to speech myTTS.speakf("SPlease switch the device into typing mode. Press down the submit button when done.\r"); // Send the desired string to convert to speech myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + + // loop through each of the words for(int i = 0; i < wordsize; i++) { //iterate through the word array currword = word[i]; string presspin = "To type the word "; @@ -402,73 +247,83 @@ for (int j = 0; j < currword.length(); j++) { presspin = presspin + ", "+ currword[j]; } - //myTTS.speakf("S%s\r", presspin); //UNCOMMENTING HERE WILL MESS UP READ/WRITE CODE - //myTTS.ready(); - } + + myTTS.speakf("S%s\r", presspin); + myTTS.ready(); + + // loop through each of the letters + int incorrect = 1; + char userinput; - - // loop through each of the words - for(int i = 0; i < wordsize; i++) { //iterate through the word array - currword = word[i]; - string presspin = "To type the word "; - presspin = presspin + word[i]; - presspin = presspin + ", type letters "; + // while(!submit) + while (incorrect == 1) { + //myTTS.speakf("S%s\r", presspin); + //myTTS.ready(); + + char wordinput[currword.length()]; + // replace for loop with submit + // while (!submit) { + for (int j = 0; j < currword.length(); j++) { - presspin = presspin + ", "+ currword[j]; - } - myTTS.speakf("S%s\r", presspin); - myTTS.ready(); - string wordinput = ""; - - // loop through each of the letters - //olduserinput; - int incorrect = 1; - //char userinput; - //char* braille; + //currletter = currword[j]; + // check if all buttons were pressed - // while(!submit) - while (incorrect) { - // replace for loop with submit - // while (!submit) { - for (int j = 0; j < currword.length(); j++) { - //currletter = currword[j]; - // check if all buttons were pressed - wait(1); + char* braille; + char* oldbraille; - char* braille; - char* oldbraille; + wait(1); + + sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), + !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); + //pc.printf("test %s ", braille); - // wait for input - while (strcmp(braille, "000000") == 0) {} + // wait for input + while (strcmp(braille, "111111") == 0) { + sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), + !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); + } + //pc.printf("reached"); - // while buttons have not been released - while (strcmp(braille, "000000") != 0) { - oldbraille = braille; - sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(), - button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress()); - } - - // at the end of this, oldbraille contains the letter representation - // flip braille values - //userinput = checkVal(oldbraille); - wordinput[j] = buttonarr.checkVal(oldbraille); - //wordinput[j] = olduserinput; + // while buttons have not been released + int oldsum = 0; + int sum = 0; + while ((strcmp(braille, "111111") != 0) && (oldsum <= sum)) { + oldbraille = braille; + oldsum = sum; + sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), + !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); + sum = button1.getPress() + button2.getPress() + button3.getPress() + button4.getPress() + + button5.getPress() + button6.getPress(); } - // check result of words - if (wordinput.compare(currword) == 0) { // input is correct - incorrect = 0; - myTTS.speakf("Good job!\r"); - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response - } else { - incorrect = 0; // delete this line - myTTS.speakf("SPlease try again!.\r"); - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + // at the end of this, oldbraille contains the letter representation + //pc.printf("%s ", oldbraille); + userinput = buttonarr.checkVal(oldbraille); + pc.printf("%c ", userinput); + wordinput[j] = userinput; + } + + // check result of words + incorrect = 0; + for (int k = 0; k < currword.length(); k++) { + if (currword[k] != wordinput[k]) { // if any letter doesn't match + incorrect = 1; // spelling is wrong } } + if (incorrect == 1) { + myTTS.speakf("SPlease try again! %s\r", presspin); + myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + //wait(2); + //incorrect = 1; + } else { + //wait(1); + myTTS.speakf("SGood job!\r"); + myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + } } + } // MAIN THREAD while(true) {