Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_senior_design_Testnew by
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 = 'X'; 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, "101011") == 0) val = 'I'; 00035 if (strcmp(braille, "101001") == 0) val = 'J'; 00036 /*if (strcmp(braille, "011111") == 0) val = 'K'; 00037 if (strcmp(braille, "000111") == 0) val = 'L';*/ 00038 if (strcmp(braille, "010011") == 0) val = 'M'; 00039 if (strcmp(braille, "010001") == 0) val = 'N'; 00040 if (strcmp(braille, "010101") == 0) val = 'O'; 00041 /*if (strcmp(braille, "000011") == 0) val = 'P'; 00042 if (strcmp(braille, "000001") == 0) val = 'Q'; 00043 if (strcmp(braille, "000101") == 0) val = 'R'; 00044 if (strcmp(braille, "100011") == 0) val = 'S'; 00045 if (strcmp(braille, "100001") == 0) val = 'T'; 00046 if (strcmp(braille, "010110") == 0) val = 'U'; 00047 if (strcmp(braille, "000110") == 0) val = 'V'; 00048 if (strcmp(braille, "101000") == 0) val = 'W'; 00049 if (strcmp(braille, "010010") == 0) val = 'X'; 00050 if (strcmp(braille, "010000") == 0) val = 'Y'; 00051 if (strcmp(braille, "010100") == 0) val = 'Z';*/ 00052 // check if reset 00053 if (strcmp(braille, "111111") == 0) val = 'Z'; 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 == 'B') braille = "001111"; 00064 if (val == 'C') braille = "011011"; 00065 if (val == 'D') braille = "011001"; 00066 if (val == 'E') braille = "011101"; 00067 if (val == 'F') braille = "001011"; 00068 if (val == 'G') braille = "001001"; 00069 if (val == 'H') braille = "001101"; 00070 if (val == 'I') braille = "101011"; 00071 if (val == 'J') braille = "101001"; 00072 /*if (val == 'K') braille = "011111"; 00073 if (val == 'L') braille = "000111";*/ 00074 if (val == 'M') braille = "010011"; 00075 if (val == 'N') braille = "010001"; 00076 if (val == 'O') braille = "010101"; 00077 /*if (val == 'P') braille = "000011"; 00078 if (val == 'Q') braille = "000001"; 00079 if (val == 'R') braille = "000101"; 00080 if (val == 'S') braille = "100011"; 00081 if (val == 'T') braille = "100001"; 00082 if (val == 'U') braille = "010110"; 00083 if (val == 'V') braille = "000110"; 00084 if (val == 'W') braille = "101000"; 00085 if (val == 'X') braille = "010010"; 00086 if (val == 'Y') braille = "010000"; 00087 if (val == 'Z') braille = "010100";*/ 00088 // check if reset 00089 if (val == ' ') braille = "111111"; 00090 return braille; 00091 } 00092 00093 // return an array of which pins need to be up 00094 int* buttonArray::pinsUp(char val) 00095 { 00096 int* pinsup; 00097 //pinsup = new int[7]; 00098 char* braille = getBraille(val); 00099 int j = 1; 00100 for (int i = 0; i < 6; i++) { 00101 if (braille[i] == '0') { 00102 pinsup[j] = i+1; 00103 j++; 00104 } 00105 } 00106 // record size of array in the first element 00107 pinsup[0] = j; 00108 return pinsup; 00109 } 00110 00111 // return feedback on which pins need to be corrected 00112 // takes in current and actual char as input and returns status of each char 00113 int* buttonArray::wrongPins(char* inarr, char actual) 00114 { 00115 // TODO check initial value of wrong 00116 int* wrong; 00117 wrong = new int[7]; 00118 char* actarr = getBraille(actual); 00119 //pc.printf("wrong pins"); 00120 int j = 1; 00121 for (int i = 0; i < 6; i++) { 00122 if(inarr[i] != actarr[i]) { 00123 wrong[j] = i+1; 00124 //pc.printf("%d ", wrong[j]); 00125 j++; 00126 } 00127 } 00128 // record size of array in the first element 00129 wrong[0] = j; 00130 return wrong; 00131 } 00132 00133 // release buttons 00134 void buttonArray::releaseButtons() 00135 { 00136 if (button1.getPress()) { 00137 button1.moveServoOut(); 00138 button1.setState(3); 00139 button1.setPress(0); 00140 } 00141 if (button2.getPress()) { 00142 button2.moveServoOut(); 00143 button2.setState(3); 00144 button2.setPress(0); 00145 } 00146 if (button3.getPress()) { 00147 button3.moveServoOut(); 00148 button3.setState(3); 00149 button3.setPress(0); 00150 } 00151 if (button4.getPress()) { 00152 button4.moveServoOut(); 00153 button4.setState(3); 00154 button4.setPress(0); 00155 } 00156 if (button5.getPress()) { 00157 button5.moveServoOut(); 00158 button5.setState(3); 00159 button5.setPress(0); 00160 } 00161 if (button6.getPress()) { 00162 button6.moveServoOut(); 00163 button6.setState(3); 00164 button6.setPress(0); 00165 } 00166 } 00167 00168 void buttonArray::setup() 00169 { 00170 // servos begin at 30 degrees 00171 // replace with a button setup function 00172 button1.setup(); 00173 button2.setup(); 00174 button3.setup(); 00175 button4.setup(); 00176 button5.setup(); 00177 button6.setup(); 00178 }
Generated on Tue Jul 12 2022 16:58:49 by
1.7.2
