Working reset, flipped logic

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Nhi by BAT

Files at this revision

API Documentation at this revision

Comitter:
aismail1997
Date:
Fri Dec 01 03:36:28 2017 +0000
Parent:
35:593bae6b342b
Commit message:
Flipped code worked. Added placeholders for type mode. Word code not working!!!

Changed in this revision

buttonArray.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 593bae6b342b -r d873136dfb12 buttonArray.cpp
--- a/buttonArray.cpp	Thu Nov 30 22:07:00 2017 +0000
+++ b/buttonArray.cpp	Fri Dec 01 03:36:28 2017 +0000
@@ -99,7 +99,7 @@
     //pc.printf("wrong pins");
     int j = 1;
     for (int i = 0; i < 6; i++) {
-        if(inarr[i] == actarr[i]) {
+        if(inarr[i] != actarr[i]) {
             wrong[j] = i+1;
             //pc.printf("%d ", wrong[j]);
             j++;
diff -r 593bae6b342b -r d873136dfb12 main.cpp
--- a/main.cpp	Thu Nov 30 22:07:00 2017 +0000
+++ b/main.cpp	Fri Dec 01 03:36:28 2017 +0000
@@ -143,6 +143,7 @@
     // servos begin at 30 degrees
     // replace with a button setup function
     buttonarr.setup();
+    //buttonarr.setMode();
 
     //led1 = 1;
     //led2 = 1;
@@ -200,79 +201,36 @@
     t5.start(button5_thread);
     //t6.start(button6_thread);
 
-    // start threads for reset, mode, start
-    //Thread t1(start_thread);
-    //pc.printf("start thread");
-    //Thread t2(submit_thread);
-    // setup SDcard and Speaker
-
-    // when started
-    //while (start == 0){}
-    //Thread t3(button_thread);
-    //pc.printf("button thread");
-    //Thread t4(button2_thread);
-    //pc.printf("button2 thread");
-
-    //Thread t3(submit_thread);
-
-    // when submitted
-    //while (submit == 0) {}
-
-    // start button threads and submit thread
-    // if submit close button threads and submit thread
-    // check result
-    // play results on speaker
-    // save results
-
     char currletter;
     int lettersize = sizeof(letter)/sizeof(letter[0]);
-    /*for (int i = 0; i < lettersize; i++) {
-        currletter = letter[i][0];
-        //pc.printf("currletter %c \n", currletter);
-        //pc.printf("braille %s \n", buttonarr.getBraille(currletter));
-    }*/
-
-    /*int* pinsup = buttonarr.pinsUp('M');
-    int currpress;
-    // get what pins to press
-    for (int i = 1; i <= pinsup[0]; i++) {
-        // speaker stuff
-        currpress = pinsup[i];
-    }*/
-
-    /*int* wrongpins = buttonarr.wrongPins('M', 'O');
-    int currwrong;
-    // get what pins are wrong
-    for (int i = 1; i <= wrongpins[0]; i++) {
-        // speaker stuff
-        currwrong = wrongpins[i];
-    }*/
-
+    int type = 0;
 
     //TEXT-TO-SPEECH LOGIC
-    myTTS.volume(18); //max volume
+    myTTS.volume(1); //max volume
     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
+    //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
     char* braille;
     char userinput;
 
     // INITIAL RESET
-    int reset = 1;
-    myTTS.speakf("SPlease 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(2);
-        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
+    if (type == 0) {
+        int reset = 1;
+        myTTS.speakf("SPlease 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(2);
+            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
+            }
         }
     }
 
@@ -317,23 +275,25 @@
 
         //WORKS UP TO HERE
         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);
+        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);
-        //string presspin;
-        //wrongpins[0] != 1
         int test = 1;
         while(test == 1) {
             //pc.printf("In while loop");
@@ -371,9 +331,16 @@
                 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);
+                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);
 
@@ -381,41 +348,127 @@
                 wrongpins = buttonarr.wrongPins(braille, currletter);
             } else {
                 test = 0;
-                myTTS.speakf("SGood job! Your answer is correct.\r");
+                myTTS.speakf("SGood job!\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) {
 
-            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;
-                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
+        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 {
+                    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]);
     }
-    //myTTS.speakf("STo write the letter %s, press pins %D\r",letter[i]);
-    //myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+
+// WORD CODE
+
+// WORD COUNTER
+// go through each word
+// go through each letter in the word
+// get user input
+// when buttons reset - save previous letter
+// loop until submit button is pressed
+// compare words
+// check what letters were wrong
+// give wrong letters - correct spelling is...
+
+    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.ready(); //ready waits for speech to finish from last command with a ":" response
+
+    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 ";
+        for (int j = 0; j < currword.length(); j++) {
+            presspin = presspin + ", "+ currword[j];
+        }
+        //myTTS.speakf("S%s\r", presspin);
+        //myTTS.ready();
+    }
+
+    /*
+        // 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 ";
+            for (int j = 0; j < currword.length(); j++) {
+                presspin = presspin + ", "+ currword[j];
+            }
+            myTTS.speakf("S%s\r", presspin);
+            myTTS.ready();
+
+            string wordinput = "";
 
-    //buttonarr.releaseButtons();
-    //pc.printf("current braille %c \n", buttonarr.checkVal());
-    //pc.printf("%c\n", buttonarr.releaseButtons());
+            // loop through each of the letters
+            //olduserinput;
+            int incorrect = 1;
+            //char userinput;
+            //char* braille;
+
+            // 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;
+
+                    // wait for input
+                    while (strcmp(braille, "000000") == 0) {}
 
-    // MAIN THREAD
-    while(true) {
+                    // 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;
+                }
 
-        // read linear potentiometer
-        //led4 = linpot;
+                // 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
+                }
+            }
+
+        }*/
+
+// MAIN THREAD
+    while(true) {
 
         Thread::wait(500); // wait till thread is done
     }