Working read code with mode button

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Testnew by BAT

Revision:
36:1248dfa0740b
Parent:
35:3090ec93b4aa
Child:
37:ef0921d9b5bd
Child:
38:593bae6b342b
--- a/main.cpp	Wed Nov 29 00:40:16 2017 +0000
+++ b/main.cpp	Wed Nov 29 15:14:26 2017 +0000
@@ -199,7 +199,7 @@
     t4.start(button4_thread);
     t5.start(button5_thread);
     //t6.start(button6_thread);
-    
+
     // start threads for reset, mode, start
     //Thread t1(start_thread);
     //pc.printf("start thread");
@@ -248,7 +248,7 @@
         currwrong = wrongpins[i];
     }*/
 
-    
+
     //TEXT-TO-SPEECH LOGIC
     myTTS.volume(18); //max volume
     myTTS.voice(2);
@@ -295,16 +295,22 @@
         //pc.printf("hello");
 
         //WORKS UP TO HERE
-        char userinput = buttonarr.checkVal();
+        char* braille;
+        sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
+                button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
+        char userinput = buttonarr.checkVal(braille);
+        pc.printf(" %s ", braille);
         int test1 = button1.getPress();
         pc.printf(" %d\n", test1);
+        pc.printf(" %c ", userinput);
         //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);
+        pc.printf("\n %c %c", userinput, currletter);
+        int* wrongpins = buttonarr.wrongPins(braille, currletter);
         //string presspin;
         //wrongpins[0] != 1
         int test = 1;
@@ -338,26 +344,36 @@
                 }
             }
             //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);
+            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
+                //UPDATE THE PINS THAT ARE WRONG BY CHECKING AGAIN BELOW
+                //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);
+                // get input
+                //pc.printf("Your input was: %c", userinput);
 
-            // check result
-            wrongpins = buttonarr.wrongPins(userinput, currletter);
-            test = 0;
+                // check result
+                wrongpins = buttonarr.wrongPins(braille, currletter);
+            } else {
+                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
+            }
         }
-        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') {
+
+            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 {
                 reset = 0;