Trying to separate read/write mode from typing mode

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:
Wed Nov 29 15:14:26 2017 +0000
Parent:
33:3090ec93b4aa
Child:
35:ef0921d9b5bd
Child:
36:593bae6b342b
Commit message:
Button logic works;

Changed in this revision

buttonArray.cpp Show annotated file Show diff for this revision Revisions of this file
buttonArray.h 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
--- a/buttonArray.cpp	Wed Nov 29 00:40:16 2017 +0000
+++ b/buttonArray.cpp	Wed Nov 29 15:14:26 2017 +0000
@@ -13,14 +13,14 @@
 
 // map input braille to ascii
 // braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII
-char buttonArray::checkVal()
+char buttonArray::checkVal(char* braille)
 {
     //pc.printf(" checkVal \n");
-    char* braille;
-    char val = NULL;
-    int test = button1.getPress();
+    //char* braille;
+    char val = 'K';
+    /*int test = button1.getPress();
     sprintf(braille, "%d%d%d%d%d%d", test, button2.getPress(),
-            button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
+            button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());*/
     //pc.printf(" %s \n", braille);
     if (strcmp(braille, "000000") == 0) val = 'X';
     if (strcmp(braille, "011111") == 0) val = 'A';
@@ -33,8 +33,8 @@
     if (strcmp(braille, "001101") == 0) val = 'H';
     if (strcmp(braille, "101101") == 0) val = 'I';
     if (strcmp(braille, "101001") == 0) val = 'J';
-    if (strcmp(braille, "010011") == 0) val = 'M';
-    if (strcmp(braille, "010101") == 0) val = 'O';
+    if (strcmp(braille, "101100") == 0) val = 'M';
+    if (strcmp(braille, "101010") == 0) val = 'O';
     /*if (strcmp(braille, "011111") == 0) val = 'K';
     if (strcmp(braille, "011111") == 0) val = 'L';
     if (strcmp(braille, "011111") == 0) val = 'N';
@@ -64,6 +64,7 @@
     if (val == 'Z') braille = "111111";
     if (val == 'M') braille = "010011";
     if (val == 'O') braille = "010101";
+    if (val == 'K') braille = "100000";
     // check if reset
     if (val == ' ') braille = "111111";
     return braille;
@@ -89,11 +90,12 @@
 
 // return feedback on which pins need to be corrected
 // takes in current and actual char as input and returns status of each char
-int* buttonArray::wrongPins(char input, char actual)
+int* buttonArray::wrongPins(char* inarr, char actual)
 {
+    // TODO check initial value of wrong
     int* wrong;
     wrong = new int[7];
-    char* inarr = getBraille(input);
+    //char* inarr = getBraille(input);
     //pc.printf("input %s\n", inarr);
     char* actarr = getBraille(actual);
     //pc.printf("wrong pins");
--- a/buttonArray.h	Wed Nov 29 00:40:16 2017 +0000
+++ b/buttonArray.h	Wed Nov 29 15:14:26 2017 +0000
@@ -20,8 +20,8 @@
     buttonArray(); // Default
     buttonArray(button button1, button button2, button button3, button button4, button button5, button button6);
     // functions
-    int* wrongPins(char input, char actual);
-    char checkVal(); // return buttons ascii representation
+    int* wrongPins(char* input, char actual);
+    char checkVal(char* braille); // return buttons ascii representation
     void releaseButtons();// release all buttons;
     int* pinsUp(char val);    
     char* getBraille(char val);
--- 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;