Working reset, flipped logic

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Nhi by BAT

Revision:
31:e5024aeca3a7
Parent:
30:79cdf893c8b8
Child:
32:e87bb6e83072
--- a/main.cpp	Fri Nov 17 15:17:36 2017 +0000
+++ b/main.cpp	Fri Nov 17 16:24:33 2017 +0000
@@ -132,7 +132,7 @@
 int main()
 {
 
-    
+
     // SETUP
     // pull up the pushbutton to prevent bouncing
     pb1.mode(PullUp);
@@ -251,7 +251,7 @@
 
     //TEXT-TO-SPEECH LOGIC
     myTTS.volume(18); //max volume
-    string repeat = "Please try again.";
+    myTTS.voice(2);
 
     myTTS.speakf("SWelcome to Bat, the Braille Assistive Teacher. This device will help you learn how to write and type braille.\r");  // Send the desired string to convert to speech
     myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
@@ -264,7 +264,7 @@
         //string presspin;
         string presspin = "STo write the letter ";
         presspin = presspin + letter[i];
-        presspin = presspin + ", press pins";
+        presspin = presspin + ", press buttons";
 
         for (int j = 1; j < numpinsups; j++) {  // get what pins to press
             currpress = pinsup[j];
@@ -292,14 +292,79 @@
         myTTS.speakf("%s\r",presspin);
         myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
         wait(1);
-        
+        //pc.printf("hello");
+
+
+
+        //WORKS UP TO HERE
         char userinput = buttonarr.checkVal();
+        //pc.printf("userinput: %c", userinput);
         // get input
         //pc.printf("Your input was: %c", userinput);
-        
+        int currwrong;
+        string wrongpin;
         // check result
         int* wrongpins = buttonarr.wrongPins(userinput, currletter);
-        
+        //string presspin;
+        //wrongpins[0] != 1
+        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");
+            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
+            //UPDATE THE PINS THAT ARE WRONG BY CHECKING AGAIN BELOW
+            userinput = buttonarr.checkVal();
+            // get input
+            //pc.printf("Your input was: %c", userinput);
+
+            // check result
+            wrongpins = buttonarr.wrongPins(userinput, currletter);
+            test = 0;
+        }
+        myTTS.speakf("SGood job! Your answer is correct.\r");
+        myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+        int reset = 1;
+        myTTS.speakf("SNow reset 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) {
+            userinput = buttonarr.checkVal();
+            if(userinput == 'X') {
+                reset = 0;
+            } else {
+                reset = 0;
+                myTTS.speakf("SNot all of the buttons were reset. Please try again.\r");
+                myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+            }
+        }
         //pc.printf("wrongpins are: %d", wrongpins[0]);
     }
     //myTTS.speakf("STo write the letter %s, press pins %D\r",letter[i]);