Test fork nhi

Dependencies:   SDFileSystem mbed-rtos mbed emic2

Fork of BAT_senior_design by BAT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers buttonArray.cpp Source File

buttonArray.cpp

00001 #include "mbed.h"
00002 #include "buttonArray.h"
00003 
00004 // type mode
00005 
00006 // buttonArray constructor
00007 buttonArray::buttonArray(button b1, button b2, button b3, button b4, button b5, button b6)
00008     : button1(b1), button2(b2), button3(b3), button4(b4), button5(b5), button6(b6) {}
00009 
00010 //Serial pc(USBTX, USBRX);
00011 
00012 // FUNCTIONS
00013 
00014 // map input braille to ascii
00015 // braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII
00016 char buttonArray::checkVal(char* braille)
00017 {
00018     //pc.printf(" checkVal \n");
00019     //char* braille;
00020     char val = 'K';
00021     /*int test = button1.getPress();
00022     sprintf(braille, "%d%d%d%d%d%d", test, button2.getPress(),
00023             button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());*/
00024     //pc.printf(" %s \n", braille);
00025     if (strcmp(braille, "000000") == 0) val = '@';
00026     if (strcmp(braille, "011111") == 0) val = 'A';
00027     if (strcmp(braille, "001111") == 0) val = 'B';
00028     if (strcmp(braille, "011011") == 0) val = 'C';
00029     if (strcmp(braille, "011001") == 0) val = 'D';
00030     if (strcmp(braille, "011101") == 0) val = 'E';
00031     if (strcmp(braille, "001011") == 0) val = 'F';
00032     if (strcmp(braille, "001001") == 0) val = 'G';
00033     if (strcmp(braille, "001101") == 0) val = 'H';
00034     if (strcmp(braille, "101101") == 0) val = 'I';
00035     if (strcmp(braille, "101001") == 0) val = 'J';
00036     if (strcmp(braille, "010011") == 0) val = 'M';
00037     if (strcmp(braille, "010101") == 0) val = 'O';
00038     /*if (strcmp(braille, "011111") == 0) val = 'K';
00039     if (strcmp(braille, "011111") == 0) val = 'L';
00040     if (strcmp(braille, "011111") == 0) val = 'N';
00041     if (strcmp(braille, "011111") == 0) val = 'P';
00042     if (strcmp(braille, "011111") == 0) val = 'Q';
00043     if (strcmp(braille, "011111") == 0) val = 'R';
00044     if (strcmp(braille, "011111") == 0) val = 'S';
00045     if (strcmp(braille, "011111") == 0) val = 'T';
00046     if (strcmp(braille, "011111") == 0) val = 'U';
00047     if (strcmp(braille, "011111") == 0) val = 'V';
00048     if (strcmp(braille, "011111") == 0) val = 'W';
00049     if (strcmp(braille, "011111") == 0) val = 'X';
00050     if (strcmp(braille, "011111") == 0) val = 'Y';
00051     if (strcmp(braille, "011111") == 0) val = 'Z';*/
00052     // check if reset
00053     if (strcmp(braille, "111111") == 0) val = '!';
00054     //pc.printf(" %c \n", val);
00055     return val;
00056 }
00057 
00058 // get braille represention of char
00059 char* buttonArray::getBraille(char val)
00060 {
00061     char* braille;
00062     if (val == 'A') braille = "011111";
00063     if (val == 'X') braille = "000000";
00064     if (val == 'Z') braille = "111111";
00065     if (val == 'M') braille = "010011";
00066     if (val == 'O') braille = "010101";
00067     if (val == 'K') braille = "100000";
00068     // check if reset
00069     if (val == ' ') braille = "111111";
00070     return braille;
00071 }
00072 
00073 // return an array of which pins need to be up
00074 int* buttonArray::pinsUp(char val)
00075 {
00076     int* pinsup;
00077     //pinsup = new int[7];
00078     char* braille = getBraille(val);
00079     int j = 1;
00080     for (int i = 0; i < 6; i++) {
00081         if (braille[i] == '0') {
00082             pinsup[j] = i+1;
00083             j++;
00084         }
00085     }
00086     // record size of array in the first element
00087     pinsup[0] = j;
00088     return pinsup;
00089 }
00090 
00091 // return feedback on which pins need to be corrected
00092 // takes in current and actual char as input and returns status of each char
00093 int* buttonArray::wrongPins(char* inarr, char actual)
00094 {
00095     // TODO check initial value of wrong
00096     int* wrong;
00097     wrong = new int[7];
00098     char* actarr = getBraille(actual);
00099     //pc.printf("wrong pins");
00100     int j = 1;
00101     for (int i = 0; i < 6; i++) {
00102         if(inarr[i] == actarr[i]) {
00103             wrong[j] = i+1;
00104             //pc.printf("%d ", wrong[j]);
00105             j++;
00106         }
00107     }
00108     // record size of array in the first element
00109     wrong[0] = j;
00110     return wrong;
00111 }
00112 
00113 // release buttons
00114 void buttonArray::releaseButtons()
00115 {
00116     if (button1.getPress()) {
00117         button1.moveServoOut();
00118         button1.setState(3);
00119         button1.setPress(0);
00120     }
00121     if (button2.getPress()) {
00122         button2.moveServoOut();
00123         button2.setState(3);
00124         button2.setPress(0);
00125     }
00126     if (button3.getPress()) {
00127         button3.moveServoOut();
00128         button3.setState(3);
00129         button3.setPress(0);
00130     }
00131     if (button4.getPress()) {
00132         button4.moveServoOut();
00133         button4.setState(3);
00134         button4.setPress(0);
00135     }
00136     if (button5.getPress()) {
00137         button5.moveServoOut();
00138         button5.setState(3);
00139         button5.setPress(0);
00140     }
00141     if (button6.getPress()) {
00142         button6.moveServoOut();
00143         button6.setState(3);
00144         button6.setPress(0);
00145     }
00146 }
00147 
00148 void buttonArray::setup()
00149 {
00150     // servos begin at 30 degrees
00151     // replace with a button setup function
00152     button1.setup();
00153     button2.setup();
00154     button3.setup();
00155     button4.setup();
00156     button5.setup();
00157     button6.setup();
00158 }