Letters in typing mode

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Test_Type by BAT

Files at this revision

API Documentation at this revision

Comitter:
aismail1997
Date:
Fri Nov 03 18:56:01 2017 +0000
Parent:
21:c5df903f068a
Child:
23:23970cf718ee
Commit message:
speaker and lin pot code commented out

Changed in this revision

button.cpp Show annotated file Show diff for this revision Revisions of this file
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
emic2.lib 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/button.cpp	Wed Nov 01 15:22:13 2017 +0000
+++ b/button.cpp	Fri Nov 03 18:56:01 2017 +0000
@@ -1,9 +1,13 @@
 #include "mbed.h"
 #include "button.h"
+#include "emic2.h"
+
+emic2 myTTS(p28, p27); //serial RX,TX pins to emic
+//DigitalOut led4(LED4);
 
 // button constructor
 button::button(PwmOut servo, DigitalIn pb, int id)
-    : servo(servo), pb(pb), state(0), press(0), id(id){}
+    : servo(servo), pb(pb), state(0), press(0), id(id) {}
 /*button::button(PwmOut servo, DigitalIn pb, AnalogIn lp)
     : servo(servo), pb(pb), linpot(lp), press(0), state(0) {}
 */
@@ -53,10 +57,10 @@
 // get current state of the button
 int button::getLp()
 {
-/*    if (linpot < 2)
-        return 1;
-    else*/
-        return 0;
+    /*    if (linpot < 2)
+            return 1;
+        else*/
+    return 0;
 }
 
 // move servo into the slot
@@ -93,6 +97,12 @@
         moveServoIn();
         state = 1;
         press = 1;
+
+        // Speaker says stuff
+        /*myTTS.volume(18); //max volume
+        myTTS.speakf("S");//Speak command starts with "S"
+        myTTS.speakf("Hey, you pressed a pin!");  // Send the desired string to convert to speech
+        myTTS.speakf("\r"); //marks end of speak command*/
     }
     // state 2 - button is down, pb = 0
     if (pb == 0 && state == 1) {
--- a/buttonArray.cpp	Wed Nov 01 15:22:13 2017 +0000
+++ b/buttonArray.cpp	Fri Nov 03 18:56:01 2017 +0000
@@ -1,6 +1,8 @@
 #include "mbed.h"
 #include "buttonArray.h"
 
+// type mode
+
 // buttonArray constructor
 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) {}
@@ -11,21 +13,82 @@
 // braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII
 char buttonArray::checkVal()
 {
-    char* input;
+    char* braille;
     char val = NULL;
-    sprintf(input, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
+    sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
             button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
-    if (strcmp(input, "000000") == 0) val = NULL;
-    if (strcmp(input, "011111") == 0) val = 'A';
-    if (strcmp(input, "001101") == 0) val = 'M';
-    if (strcmp(input, "011001") == 0) val = 'O';
+    if (strcmp(braille, "000000") == 0) val = '@';
+    if (strcmp(braille, "011111") == 0) val = 'A';
+    if (strcmp(braille, "001111") == 0) val = 'B';
+    if (strcmp(braille, "011011") == 0) val = 'C';
+    if (strcmp(braille, "011001") == 0) val = 'D';
+    if (strcmp(braille, "011101") == 0) val = 'E';
+    if (strcmp(braille, "001011") == 0) val = 'F';
+    if (strcmp(braille, "001001") == 0) val = 'G';
+    if (strcmp(braille, "001101") == 0) val = 'H';
+    if (strcmp(braille, "101101") == 0) val = 'I';
+    if (strcmp(braille, "101001") == 0) val = 'J';
+    /*if (strcmp(braille, "011111") == 0) val = 'K';
+    if (strcmp(braille, "011111") == 0) val = 'L';
+    if (strcmp(braille, "011111") == 0) val = 'N';
+    if (strcmp(braille, "011111") == 0) val = 'P';
+    if (strcmp(braille, "011111") == 0) val = 'Q';
+    if (strcmp(braille, "011111") == 0) val = 'R';
+    if (strcmp(braille, "011111") == 0) val = 'S';
+    if (strcmp(braille, "011111") == 0) val = 'T';
+    if (strcmp(braille, "011111") == 0) val = 'U';
+    if (strcmp(braille, "011111") == 0) val = 'V';
+    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';*/
     // check if reset
-    if (strcmp(input, "111111") == 0) val = ' ';
+    if (strcmp(braille, "111111") == 0) val = '!';
     return val;
 }
 
-// return feedback on which pin to correct
+// get braille represention of char
+char* buttonArray::getBraille(char val)
+{
+    char* braille;
+    if (val == NULL) braille = "000000";
+    if (val == 'A') braille = "011111";
+    if (val == 'M') braille = "010011";
+    if (val == 'O') braille = "010101";
+    // check if reset
+    if (val == ' ') braille = "111111";
+    return braille;
+}
 
+// return an array of which pins need to be up
+int* buttonArray::pinsToPress(char val)
+{
+    int* pinstopress;
+    char* braille = getBraille(val);
+    int j = 0;
+    for (int i = 0; i < 6; i++) {
+        if (braille[i] == '0') {
+            pinstopress[j] = i;
+            j++;
+        }
+    }
+    return pinstopress;
+}
+
+// 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)
+{
+    if (input == NULL) return NULL;
+    int wrong[6];
+    char* inarr = getBraille(input);
+    char* actarr = getBraille(actual);
+    for (int i = 0; i < 6; i++) {
+        wrong[i] = (inarr[i] != actarr[i]);
+    }
+    return wrong;
+}
 
 // release buttons
 void buttonArray::releaseButtons()
@@ -36,5 +99,3 @@
         button1.setPress(0);
     }
 }
-//
-
--- a/buttonArray.h	Wed Nov 01 15:22:13 2017 +0000
+++ b/buttonArray.h	Fri Nov 03 18:56:01 2017 +0000
@@ -20,7 +20,9 @@
     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
     void releaseButtons();// release all buttons;
-    
+    int* pinsToPress(char val);    
+    char* getBraille(char val);
 };
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/emic2.lib	Fri Nov 03 18:56:01 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/4180_1/code/emic2/#b95ede38e19d
--- a/main.cpp	Wed Nov 01 15:22:13 2017 +0000
+++ b/main.cpp	Fri Nov 03 18:56:01 2017 +0000
@@ -21,9 +21,9 @@
 
 //DigitalOut led1(LED1);
 //DigitalOut led3(LED3);
-DigitalOut led4(LED4);
+//DigitalOut led4(LED4);
 
-//AnalogIn linpot(p20);
+DigitalIn linpot(p9);
 //Serial pc(USBTX, USBRX);
 //SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
 //AnalogOut DACout(p26);
@@ -147,7 +147,7 @@
     pb6.mode(PullUp);
     wait(.001);
 
-    // servo begins at 30 degrees
+    // servos begin at 30 degrees
     // replace with a button setup function
     for(int i=0; i<=3; i++) {
         myservo = i/100.0;
@@ -217,13 +217,18 @@
     // play results on speaker
     // save results
 
-    // read linear potentiometer
-    //if (linpot < 0.5) {
-    //float potval = linpot;
-    //pc.printf("linear pot: %f\n", potval);
+    //pc.printf("%c\n", buttonarr.checkVal()); // check input
+    //pc.printf("%s\n", buttonarr.getBraille('A')); // check mapping
+    //pc.printf("%d\n", buttonarr.pinsToPress('A'));
+    //pc.printf("%d\n", buttonarr.wrongPins('M', 'O'));
+    //pc.printf("%c\n", buttonarr.releaseButtons());
 
     // MAIN THREAD
     while(true) {
+
+        // read linear potentiometer
+        //led4 = linpot;
+
         Thread::wait(500); // wait till thread is done
     }
 }
\ No newline at end of file