Fork of original senior design repo

Dependencies:   SDFileSystem mbed-rtos mbed wave_player emic2

Fork of BAT_senior_design by BAT

Files at this revision

API Documentation at this revision

Comitter:
aismail1997
Date:
Fri Nov 17 15:17:36 2017 +0000
Parent:
25:b9bd85682db1
Commit message:
buttonarray functions work!

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 b9bd85682db1 -r 79cdf893c8b8 buttonArray.cpp
--- a/buttonArray.cpp	Wed Nov 15 16:42:48 2017 +0000
+++ b/buttonArray.cpp	Fri Nov 17 15:17:36 2017 +0000
@@ -7,17 +7,21 @@
 buttonArray::buttonArray(button b1, button b2, button b3, button b4, button b5, button b6)
     : button1(b1), button2(b2), button3(b3), button4(b4), button5(b5), button6(b6) {}
 
+//Serial pc(USBTX, USBRX);
+
 // FUNCTIONS
 
 // map input braille to ascii
 // braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII
 char buttonArray::checkVal()
 {
+    //pc.printf(" checkVal \n");
     char* braille;
     char val = NULL;
     sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
             button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
-    if (strcmp(braille, "000000") == 0) val = '@';
+    //pc.printf(" %s \n", braille);
+    if (strcmp(braille, "000000") == 0) val = 'X';
     if (strcmp(braille, "011111") == 0) val = 'A';
     if (strcmp(braille, "001111") == 0) val = 'B';
     if (strcmp(braille, "011011") == 0) val = 'C';
@@ -28,6 +32,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, "011111") == 0) val = 'K';
     if (strcmp(braille, "011111") == 0) val = 'L';
     if (strcmp(braille, "011111") == 0) val = 'N';
@@ -41,10 +47,10 @@
     if (strcmp(braille, "011111") == 0) val = 'W';
     if (strcmp(braille, "011111") == 0) val = 'X';
     if (strcmp(braille, "011111") == 0) val = 'Y';
-    if (strcmp(braille, "011111") == 0) val = 'Z';
-    if (strcmp(braille, "010101") == 0) val = 'O';*/
+    if (strcmp(braille, "011111") == 0) val = 'Z';*/
     // check if reset
-    if (strcmp(braille, "111111") == 0) val = '!';
+    if (strcmp(braille, "111111") == 0) val = 'Z';
+    //pc.printf(" %c \n", val);
     return val;
 }
 
@@ -52,8 +58,9 @@
 char* buttonArray::getBraille(char val)
 {
     char* braille;
-    if (val == NULL) braille = "000000";
     if (val == 'A') braille = "011111";
+    if (val == 'X') braille = "000000";
+    if (val == 'Z') braille = "111111";
     if (val == 'M') braille = "010011";
     if (val == 'O') braille = "010101";
     // check if reset
@@ -65,6 +72,7 @@
 int* buttonArray::pinsUp(char val)
 {
     int* pinsup;
+    pinsup = new int[7];
     char* braille = getBraille(val);
     int j = 1;
     for (int i = 0; i < 6; i++) {
@@ -82,15 +90,18 @@
 // takes in current and actual char as input and returns status of each char
 int* buttonArray::wrongPins(char input, char actual)
 {
-    if (input == NULL) return NULL;
     int* wrong;
+    wrong = new int[7];
     char* inarr = getBraille(input);
+    //pc.printf("input %s\n", inarr);
     char* actarr = getBraille(actual);
-    int j = 0;
+    //pc.printf("wrong pins");
+    int j = 1;
     for (int i = 0; i < 6; i++) {
         if(inarr[i] != actarr[i]) {
+            wrong[j] = i+1;
+            //pc.printf("%d ", wrong[j]);
             j++;
-            wrong[j] = i+1;
         }
     }
     // record size of array in the first element
@@ -106,27 +117,27 @@
         button1.setState(3);
         button1.setPress(0);
     }
-        if (button2.getPress()) {
+    if (button2.getPress()) {
         button2.moveServoOut();
         button2.setState(3);
         button2.setPress(0);
     }
-        if (button3.getPress()) {
+    if (button3.getPress()) {
         button3.moveServoOut();
         button3.setState(3);
         button3.setPress(0);
     }
-        if (button4.getPress()) {
+    if (button4.getPress()) {
         button4.moveServoOut();
         button4.setState(3);
         button4.setPress(0);
     }
-        if (button5.getPress()) {
+    if (button5.getPress()) {
         button5.moveServoOut();
         button5.setState(3);
         button5.setPress(0);
     }
-        if (button6.getPress()) {
+    if (button6.getPress()) {
         button6.moveServoOut();
         button6.setState(3);
         button6.setPress(0);
diff -r b9bd85682db1 -r 79cdf893c8b8 main.cpp
--- a/main.cpp	Wed Nov 15 16:42:48 2017 +0000
+++ b/main.cpp	Fri Nov 17 15:17:36 2017 +0000
@@ -29,7 +29,7 @@
 //DigitalOut led4(LED4);
 
 DigitalIn linpot(p9);
-Serial pc(USBTX, USBRX);
+//Serial pc(USBTX, USBRX);
 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
 //AnalogOut DACout(p26);
 //wave_player waver(&DACout);
@@ -132,7 +132,7 @@
 int main()
 {
 
-    /*
+    
     // SETUP
     // pull up the pushbutton to prevent bouncing
     pb1.mode(PullUp);
@@ -141,26 +141,26 @@
     pb4.mode(PullUp);
     pb5.mode(PullUp);
     pb6.mode(PullUp);
-    wait(.001); */
+    wait(.001);
 
     // servos begin at 30 degrees
     // replace with a button setup function
-    buttonarr.setup();
+    //buttonarr.setup();
 
     //led1 = 1;
     //led2 = 1;
-    /*Thread t1(button_thread);
-    Thread t2(button2_thread);
+    Thread t1(button_thread);
+    //Thread t2(button2_thread);
     Thread t3(button3_thread);
     Thread t4(button4_thread);
     Thread t5(button5_thread);
-    Thread t6(button6_thread);
+    //Thread t6(button6_thread);
     t1.start(button_thread);
-    t2.start(button2_thread);
+    //t2.start(button2_thread);
     t3.start(button3_thread);
     t4.start(button4_thread);
     t5.start(button5_thread);
-    t6.start(button6_thread);*/
+    //t6.start(button6_thread);
 
     // PARSE INPUT FILE FOR LETTERS AND WORDS
     char delimiter = ',';
@@ -173,13 +173,13 @@
     int counter = 0;
     FILE *fp = fopen("/sd/plan.txt", "r"); //create file
     if(fp == NULL) {
-        pc.printf("Could not open file for write\n");
+        //pc.printf("Could not open file for write\n");
     }
     check = fgetc(fp); //grabs a char from file
     while(check != '\n') {  //while not at the end of line for letters
         if((check == delimiter) && (temp.length() == 1)) {  //at a comma and have a letter stored
             letter[counter] = temp; //write letter
-            pc.printf("Letter: %s \n", letter[counter]);
+            //pc.printf("Letter: %s \n", letter[counter]);
             counter = counter + 1;  //increment counter
         } else {
             temp = check;   //store letter
@@ -191,7 +191,7 @@
     while(!feof(fp)) {  //while not at the end of line for words
         if(check == delimiter) {  //when at the comma at the end of a word
             word[counter] = tempword;   //write word
-            pc.printf("Word: %s \n", word[counter]);
+            //pc.printf("Word: %s \n", word[counter]);
             tempword = "";
             counter = counter + 1;  //increment counter
         } else {
@@ -227,28 +227,27 @@
 
     char currletter;
     int lettersize = sizeof(letter)/sizeof(letter[0]);
-    pc.printf("lettersize %d \n", lettersize);
     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));
+        //pc.printf("currletter %c \n", currletter);
+        //pc.printf("braille %s \n", buttonarr.getBraille(currletter));
     }
 
-    int* pinsup = buttonarr.pinsUp('M');
+    /*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* 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];
-    }
+    }*/
 
     //TEXT-TO-SPEECH LOGIC
     myTTS.volume(18); //max volume
@@ -258,7 +257,7 @@
     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);
+        //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
@@ -292,6 +291,16 @@
         }
         myTTS.speakf("%s\r",presspin);
         myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+        wait(1);
+        
+        char userinput = buttonarr.checkVal();
+        // get input
+        //pc.printf("Your input was: %c", userinput);
+        
+        // check result
+        int* wrongpins = buttonarr.wrongPins(userinput, currletter);
+        
+        //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