Working read code with mode button
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_senior_design_Testnew by
buttonArray.cpp@42:44a898adef26, 2017-12-04 (annotated)
- Committer:
- nnguyen45
- Date:
- Mon Dec 04 23:25:38 2017 +0000
- Revision:
- 42:44a898adef26
- Parent:
- 1:f3d363ca2343
- Child:
- 43:82d67fb53e61
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nnguyen45 | 0:5887cb744114 | 1 | #include "mbed.h" |
nnguyen45 | 0:5887cb744114 | 2 | #include "buttonArray.h" |
nnguyen45 | 0:5887cb744114 | 3 | |
nnguyen45 | 0:5887cb744114 | 4 | // buttonArray constructor |
nnguyen45 | 0:5887cb744114 | 5 | buttonArray::buttonArray(button b1, button b2, button b3, button b4, button b5, button b6) |
nnguyen45 | 0:5887cb744114 | 6 | : button1(b1), button2(b2), button3(b3), button4(b4), button5(b5), button6(b6) {} |
nnguyen45 | 0:5887cb744114 | 7 | |
nnguyen45 | 0:5887cb744114 | 8 | // FUNCTIONS |
nnguyen45 | 0:5887cb744114 | 9 | |
nnguyen45 | 0:5887cb744114 | 10 | // map input braille to ascii |
nnguyen45 | 0:5887cb744114 | 11 | // braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII |
nnguyen45 | 0:5887cb744114 | 12 | char buttonArray::checkVal(char* braille) |
nnguyen45 | 0:5887cb744114 | 13 | { |
nnguyen45 | 0:5887cb744114 | 14 | char val = 'K'; |
nnguyen45 | 0:5887cb744114 | 15 | if (strcmp(braille, "000000") == 0) val = 'X'; |
nnguyen45 | 0:5887cb744114 | 16 | if (strcmp(braille, "011111") == 0) val = 'A'; |
nnguyen45 | 0:5887cb744114 | 17 | if (strcmp(braille, "001111") == 0) val = 'B'; |
nnguyen45 | 0:5887cb744114 | 18 | if (strcmp(braille, "011011") == 0) val = 'C'; |
nnguyen45 | 0:5887cb744114 | 19 | if (strcmp(braille, "011001") == 0) val = 'D'; |
nnguyen45 | 0:5887cb744114 | 20 | if (strcmp(braille, "011101") == 0) val = 'E'; |
nnguyen45 | 0:5887cb744114 | 21 | if (strcmp(braille, "001011") == 0) val = 'F'; |
nnguyen45 | 0:5887cb744114 | 22 | if (strcmp(braille, "001001") == 0) val = 'G'; |
nnguyen45 | 0:5887cb744114 | 23 | if (strcmp(braille, "001101") == 0) val = 'H'; |
nnguyen45 | 1:f3d363ca2343 | 24 | if (strcmp(braille, "101011") == 0) val = 'I'; |
nnguyen45 | 0:5887cb744114 | 25 | if (strcmp(braille, "101001") == 0) val = 'J'; |
nnguyen45 | 1:f3d363ca2343 | 26 | //if (strcmp(braille, "011111") == 0) val = 'K'; |
nnguyen45 | 1:f3d363ca2343 | 27 | if (strcmp(braille, "000111") == 0) val = 'L'; |
nnguyen45 | 0:5887cb744114 | 28 | if (strcmp(braille, "010011") == 0) val = 'M'; |
nnguyen45 | 1:f3d363ca2343 | 29 | if (strcmp(braille, "010001") == 0) val = 'N'; |
nnguyen45 | 0:5887cb744114 | 30 | if (strcmp(braille, "010101") == 0) val = 'O'; |
nnguyen45 | 1:f3d363ca2343 | 31 | if (strcmp(braille, "000011") == 0) val = 'P'; |
nnguyen45 | 1:f3d363ca2343 | 32 | if (strcmp(braille, "000001") == 0) val = 'Q'; |
nnguyen45 | 1:f3d363ca2343 | 33 | if (strcmp(braille, "000101") == 0) val = 'R'; |
nnguyen45 | 1:f3d363ca2343 | 34 | if (strcmp(braille, "100011") == 0) val = 'S'; |
nnguyen45 | 1:f3d363ca2343 | 35 | if (strcmp(braille, "100001") == 0) val = 'T'; |
nnguyen45 | 1:f3d363ca2343 | 36 | if (strcmp(braille, "010110") == 0) val = 'U'; |
nnguyen45 | 1:f3d363ca2343 | 37 | if (strcmp(braille, "000110") == 0) val = 'V'; |
nnguyen45 | 1:f3d363ca2343 | 38 | if (strcmp(braille, "101000") == 0) val = 'W'; |
nnguyen45 | 1:f3d363ca2343 | 39 | //if (strcmp(braille, "010010") == 0) val = 'X'; |
nnguyen45 | 1:f3d363ca2343 | 40 | if (strcmp(braille, "010000") == 0) val = 'Y'; |
nnguyen45 | 1:f3d363ca2343 | 41 | //if (strcmp(braille, "010100") == 0) val = 'Z'; |
nnguyen45 | 0:5887cb744114 | 42 | // check if reset |
nnguyen45 | 0:5887cb744114 | 43 | if (strcmp(braille, "111111") == 0) val = 'Z'; |
nnguyen45 | 0:5887cb744114 | 44 | return val; |
nnguyen45 | 0:5887cb744114 | 45 | } |
nnguyen45 | 0:5887cb744114 | 46 | |
nnguyen45 | 0:5887cb744114 | 47 | // get braille represention of char |
nnguyen45 | 0:5887cb744114 | 48 | char* buttonArray::getBraille(char val) |
nnguyen45 | 0:5887cb744114 | 49 | { |
nnguyen45 | 0:5887cb744114 | 50 | char* braille; |
nnguyen45 | 0:5887cb744114 | 51 | if (val == 'A') braille = "011111"; |
nnguyen45 | 42:44a898adef26 | 52 | if (val == 'B') braille = "001111"; |
nnguyen45 | 42:44a898adef26 | 53 | if (val == 'C') braille = "011011"; |
nnguyen45 | 42:44a898adef26 | 54 | if (val == 'D') braille = "011001"; |
nnguyen45 | 42:44a898adef26 | 55 | if (val == 'E') braille = "011101"; |
nnguyen45 | 42:44a898adef26 | 56 | if (val == 'F') braille = "001011"; |
nnguyen45 | 42:44a898adef26 | 57 | if (val == 'G') braille = "001001"; |
nnguyen45 | 42:44a898adef26 | 58 | if (val == 'H') braille = "001101"; |
nnguyen45 | 42:44a898adef26 | 59 | if (val == 'I') braille = "101011"; |
nnguyen45 | 42:44a898adef26 | 60 | if (val == 'J') braille = "101001"; |
nnguyen45 | 42:44a898adef26 | 61 | //if (val == 'K') braille = "010111"; |
nnguyen45 | 42:44a898adef26 | 62 | if (val == 'L') braille = "000111"; |
nnguyen45 | 0:5887cb744114 | 63 | if (val == 'M') braille = "010011"; |
nnguyen45 | 42:44a898adef26 | 64 | if (val == 'N') braille = "010001"; |
nnguyen45 | 0:5887cb744114 | 65 | if (val == 'O') braille = "010101"; |
nnguyen45 | 42:44a898adef26 | 66 | if (val == 'P') braille = "000011"; |
nnguyen45 | 42:44a898adef26 | 67 | if (val == 'Q') braille = "000001"; |
nnguyen45 | 42:44a898adef26 | 68 | if (val == 'R') braille = "000101"; |
nnguyen45 | 42:44a898adef26 | 69 | if (val == 'S') braille = "100011"; |
nnguyen45 | 42:44a898adef26 | 70 | if (val == 'T') braille = "100001"; |
nnguyen45 | 42:44a898adef26 | 71 | if (val == 'U') braille = "010110"; |
nnguyen45 | 42:44a898adef26 | 72 | if (val == 'V') braille = "000110"; |
nnguyen45 | 42:44a898adef26 | 73 | if (val == 'W') braille = "101000"; |
nnguyen45 | 42:44a898adef26 | 74 | //if (val == 'X') braille = "010010"; |
nnguyen45 | 42:44a898adef26 | 75 | if (val == 'Y') braille = "010000"; |
nnguyen45 | 42:44a898adef26 | 76 | //if (val == 'Z') braille = "010100"; |
nnguyen45 | 0:5887cb744114 | 77 | // check if reset |
nnguyen45 | 0:5887cb744114 | 78 | if (val == ' ') braille = "111111"; |
nnguyen45 | 0:5887cb744114 | 79 | return braille; |
nnguyen45 | 0:5887cb744114 | 80 | } |
nnguyen45 | 0:5887cb744114 | 81 | |
nnguyen45 | 0:5887cb744114 | 82 | // return an array of which pins need to be up |
nnguyen45 | 0:5887cb744114 | 83 | int* buttonArray::pinsUp(char val) |
nnguyen45 | 0:5887cb744114 | 84 | { |
nnguyen45 | 0:5887cb744114 | 85 | int* pinsup; |
nnguyen45 | 0:5887cb744114 | 86 | char* braille = getBraille(val); |
nnguyen45 | 0:5887cb744114 | 87 | int j = 1; |
nnguyen45 | 0:5887cb744114 | 88 | for (int i = 0; i < 6; i++) { |
nnguyen45 | 0:5887cb744114 | 89 | if (braille[i] == '0') { |
nnguyen45 | 0:5887cb744114 | 90 | pinsup[j] = i+1; |
nnguyen45 | 0:5887cb744114 | 91 | j++; |
nnguyen45 | 0:5887cb744114 | 92 | } |
nnguyen45 | 0:5887cb744114 | 93 | } |
nnguyen45 | 0:5887cb744114 | 94 | // record size of array in the first element |
nnguyen45 | 0:5887cb744114 | 95 | pinsup[0] = j; |
nnguyen45 | 0:5887cb744114 | 96 | return pinsup; |
nnguyen45 | 0:5887cb744114 | 97 | } |
nnguyen45 | 0:5887cb744114 | 98 | |
nnguyen45 | 0:5887cb744114 | 99 | // return feedback on which pins need to be corrected |
nnguyen45 | 0:5887cb744114 | 100 | // takes in current and actual char as input and returns status of each char |
nnguyen45 | 0:5887cb744114 | 101 | int* buttonArray::wrongPins(char* inarr, char actual) |
nnguyen45 | 0:5887cb744114 | 102 | { |
nnguyen45 | 0:5887cb744114 | 103 | int* wrong; |
nnguyen45 | 0:5887cb744114 | 104 | wrong = new int[7]; |
nnguyen45 | 0:5887cb744114 | 105 | char* actarr = getBraille(actual); |
nnguyen45 | 0:5887cb744114 | 106 | int j = 1; |
nnguyen45 | 0:5887cb744114 | 107 | for (int i = 0; i < 6; i++) { |
nnguyen45 | 0:5887cb744114 | 108 | if(inarr[i] != actarr[i]) { |
nnguyen45 | 0:5887cb744114 | 109 | wrong[j] = i+1; |
nnguyen45 | 0:5887cb744114 | 110 | j++; |
nnguyen45 | 0:5887cb744114 | 111 | } |
nnguyen45 | 0:5887cb744114 | 112 | } |
nnguyen45 | 0:5887cb744114 | 113 | // record size of array in the first element |
nnguyen45 | 0:5887cb744114 | 114 | wrong[0] = j; |
nnguyen45 | 0:5887cb744114 | 115 | return wrong; |
nnguyen45 | 0:5887cb744114 | 116 | } |
nnguyen45 | 0:5887cb744114 | 117 | |
nnguyen45 | 0:5887cb744114 | 118 | // release buttons |
nnguyen45 | 0:5887cb744114 | 119 | void buttonArray::releaseButtons() |
nnguyen45 | 0:5887cb744114 | 120 | { |
nnguyen45 | 0:5887cb744114 | 121 | if (button1.getPress()) { |
nnguyen45 | 0:5887cb744114 | 122 | button1.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 123 | button1.setState(3); |
nnguyen45 | 0:5887cb744114 | 124 | button1.setPress(0); |
nnguyen45 | 0:5887cb744114 | 125 | } |
nnguyen45 | 0:5887cb744114 | 126 | if (button2.getPress()) { |
nnguyen45 | 0:5887cb744114 | 127 | button2.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 128 | button2.setState(3); |
nnguyen45 | 0:5887cb744114 | 129 | button2.setPress(0); |
nnguyen45 | 0:5887cb744114 | 130 | } |
nnguyen45 | 0:5887cb744114 | 131 | if (button3.getPress()) { |
nnguyen45 | 0:5887cb744114 | 132 | button3.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 133 | button3.setState(3); |
nnguyen45 | 0:5887cb744114 | 134 | button3.setPress(0); |
nnguyen45 | 0:5887cb744114 | 135 | } |
nnguyen45 | 0:5887cb744114 | 136 | if (button4.getPress()) { |
nnguyen45 | 0:5887cb744114 | 137 | button4.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 138 | button4.setState(3); |
nnguyen45 | 0:5887cb744114 | 139 | button4.setPress(0); |
nnguyen45 | 0:5887cb744114 | 140 | } |
nnguyen45 | 0:5887cb744114 | 141 | if (button5.getPress()) { |
nnguyen45 | 0:5887cb744114 | 142 | button5.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 143 | button5.setState(3); |
nnguyen45 | 0:5887cb744114 | 144 | button5.setPress(0); |
nnguyen45 | 0:5887cb744114 | 145 | } |
nnguyen45 | 0:5887cb744114 | 146 | if (button6.getPress()) { |
nnguyen45 | 0:5887cb744114 | 147 | button6.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 148 | button6.setState(3); |
nnguyen45 | 0:5887cb744114 | 149 | button6.setPress(0); |
nnguyen45 | 0:5887cb744114 | 150 | } |
nnguyen45 | 0:5887cb744114 | 151 | } |
nnguyen45 | 0:5887cb744114 | 152 | |
nnguyen45 | 0:5887cb744114 | 153 | void buttonArray::setup() |
nnguyen45 | 0:5887cb744114 | 154 | { |
nnguyen45 | 1:f3d363ca2343 | 155 | // servo setup function; servos begin at 30 degrees |
nnguyen45 | 0:5887cb744114 | 156 | button1.setup(); |
nnguyen45 | 0:5887cb744114 | 157 | button2.setup(); |
nnguyen45 | 0:5887cb744114 | 158 | button3.setup(); |
nnguyen45 | 0:5887cb744114 | 159 | button4.setup(); |
nnguyen45 | 0:5887cb744114 | 160 | button5.setup(); |
nnguyen45 | 0:5887cb744114 | 161 | button6.setup(); |
nnguyen45 | 0:5887cb744114 | 162 | } |