Fork of original senior design repo
Dependencies: SDFileSystem mbed-rtos mbed wave_player emic2
Fork of BAT_senior_design 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() 00017 { 00018 //pc.printf(" checkVal \n"); 00019 char* braille; 00020 char val = NULL; 00021 sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(), 00022 button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress()); 00023 //pc.printf(" %s \n", braille); 00024 if (strcmp(braille, "000000") == 0) val = 'X'; 00025 if (strcmp(braille, "011111") == 0) val = 'A'; 00026 if (strcmp(braille, "001111") == 0) val = 'B'; 00027 if (strcmp(braille, "011011") == 0) val = 'C'; 00028 if (strcmp(braille, "011001") == 0) val = 'D'; 00029 if (strcmp(braille, "011101") == 0) val = 'E'; 00030 if (strcmp(braille, "001011") == 0) val = 'F'; 00031 if (strcmp(braille, "001001") == 0) val = 'G'; 00032 if (strcmp(braille, "001101") == 0) val = 'H'; 00033 if (strcmp(braille, "101101") == 0) val = 'I'; 00034 if (strcmp(braille, "101001") == 0) val = 'J'; 00035 if (strcmp(braille, "010011") == 0) val = 'M'; 00036 if (strcmp(braille, "010101") == 0) val = 'O'; 00037 /*if (strcmp(braille, "011111") == 0) val = 'K'; 00038 if (strcmp(braille, "011111") == 0) val = 'L'; 00039 if (strcmp(braille, "011111") == 0) val = 'N'; 00040 if (strcmp(braille, "011111") == 0) val = 'P'; 00041 if (strcmp(braille, "011111") == 0) val = 'Q'; 00042 if (strcmp(braille, "011111") == 0) val = 'R'; 00043 if (strcmp(braille, "011111") == 0) val = 'S'; 00044 if (strcmp(braille, "011111") == 0) val = 'T'; 00045 if (strcmp(braille, "011111") == 0) val = 'U'; 00046 if (strcmp(braille, "011111") == 0) val = 'V'; 00047 if (strcmp(braille, "011111") == 0) val = 'W'; 00048 if (strcmp(braille, "011111") == 0) val = 'X'; 00049 if (strcmp(braille, "011111") == 0) val = 'Y'; 00050 if (strcmp(braille, "011111") == 0) val = 'Z';*/ 00051 // check if reset 00052 if (strcmp(braille, "111111") == 0) val = 'Z'; 00053 //pc.printf(" %c \n", val); 00054 return val; 00055 } 00056 00057 // get braille represention of char 00058 char* buttonArray::getBraille(char val) 00059 { 00060 char* braille; 00061 if (val == 'A') braille = "011111"; 00062 if (val == 'X') braille = "000000"; 00063 if (val == 'Z') braille = "111111"; 00064 if (val == 'M') braille = "010011"; 00065 if (val == 'O') braille = "010101"; 00066 // check if reset 00067 if (val == ' ') braille = "111111"; 00068 return braille; 00069 } 00070 00071 // return an array of which pins need to be up 00072 int* buttonArray::pinsUp(char val) 00073 { 00074 int* pinsup; 00075 pinsup = new int[7]; 00076 char* braille = getBraille(val); 00077 int j = 1; 00078 for (int i = 0; i < 6; i++) { 00079 if (braille[i] == '0') { 00080 pinsup[j] = i+1; 00081 j++; 00082 } 00083 } 00084 // record size of array in the first element 00085 pinsup[0] = j; 00086 return pinsup; 00087 } 00088 00089 // return feedback on which pins need to be corrected 00090 // takes in current and actual char as input and returns status of each char 00091 int* buttonArray::wrongPins(char input, char actual) 00092 { 00093 int* wrong; 00094 wrong = new int[7]; 00095 char* inarr = getBraille(input); 00096 //pc.printf("input %s\n", inarr); 00097 char* actarr = getBraille(actual); 00098 //pc.printf("wrong pins"); 00099 int j = 1; 00100 for (int i = 0; i < 6; i++) { 00101 if(inarr[i] != actarr[i]) { 00102 wrong[j] = i+1; 00103 //pc.printf("%d ", wrong[j]); 00104 j++; 00105 } 00106 } 00107 // record size of array in the first element 00108 wrong[0] = j; 00109 return wrong; 00110 } 00111 00112 // release buttons 00113 void buttonArray::releaseButtons() 00114 { 00115 if (button1.getPress()) { 00116 button1.moveServoOut(); 00117 button1.setState(3); 00118 button1.setPress(0); 00119 } 00120 if (button2.getPress()) { 00121 button2.moveServoOut(); 00122 button2.setState(3); 00123 button2.setPress(0); 00124 } 00125 if (button3.getPress()) { 00126 button3.moveServoOut(); 00127 button3.setState(3); 00128 button3.setPress(0); 00129 } 00130 if (button4.getPress()) { 00131 button4.moveServoOut(); 00132 button4.setState(3); 00133 button4.setPress(0); 00134 } 00135 if (button5.getPress()) { 00136 button5.moveServoOut(); 00137 button5.setState(3); 00138 button5.setPress(0); 00139 } 00140 if (button6.getPress()) { 00141 button6.moveServoOut(); 00142 button6.setState(3); 00143 button6.setPress(0); 00144 } 00145 } 00146 00147 void buttonArray::setup() 00148 { 00149 // servos begin at 30 degrees 00150 // replace with a button setup function 00151 button1.setup(); 00152 button2.setup(); 00153 button3.setup(); 00154 button4.setup(); 00155 button5.setup(); 00156 button6.setup(); 00157 }
Generated on Thu Jul 14 2022 07:22:21 by
1.7.2
