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