BAT / Mbed 2 deprecated BAT_Read

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

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