Working read code with mode button
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_senior_design_Testnew by
buttonArray.cpp@25:23970cf718ee, 2017-11-10 (annotated)
- Committer:
- aismail1997
- Date:
- Fri Nov 10 15:59:21 2017 +0000
- Revision:
- 25:23970cf718ee
- Parent:
- 24:6931917c70cd
- Child:
- 29:b2e53ce54b3e
Integrated parsing code and tested button functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aismail1997 | 21:ceac47be2e64 | 1 | #include "mbed.h" |
aismail1997 | 21:ceac47be2e64 | 2 | #include "buttonArray.h" |
aismail1997 | 21:ceac47be2e64 | 3 | |
aismail1997 | 24:6931917c70cd | 4 | // type mode |
aismail1997 | 24:6931917c70cd | 5 | |
aismail1997 | 22:abbc12fca525 | 6 | // buttonArray constructor |
aismail1997 | 21:ceac47be2e64 | 7 | buttonArray::buttonArray(button b1, button b2, button b3, button b4, button b5, button b6) |
aismail1997 | 21:ceac47be2e64 | 8 | : button1(b1), button2(b2), button3(b3), button4(b4), button5(b5), button6(b6) {} |
aismail1997 | 23:c5df903f068a | 9 | |
aismail1997 | 22:abbc12fca525 | 10 | // FUNCTIONS |
aismail1997 | 21:ceac47be2e64 | 11 | |
aismail1997 | 22:abbc12fca525 | 12 | // map input braille to ascii |
aismail1997 | 23:c5df903f068a | 13 | // braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII |
aismail1997 | 23:c5df903f068a | 14 | char buttonArray::checkVal() |
aismail1997 | 23:c5df903f068a | 15 | { |
aismail1997 | 24:6931917c70cd | 16 | char* braille; |
aismail1997 | 23:c5df903f068a | 17 | char val = NULL; |
aismail1997 | 24:6931917c70cd | 18 | sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(), |
aismail1997 | 23:c5df903f068a | 19 | button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress()); |
aismail1997 | 24:6931917c70cd | 20 | if (strcmp(braille, "000000") == 0) val = '@'; |
aismail1997 | 24:6931917c70cd | 21 | if (strcmp(braille, "011111") == 0) val = 'A'; |
aismail1997 | 24:6931917c70cd | 22 | if (strcmp(braille, "001111") == 0) val = 'B'; |
aismail1997 | 24:6931917c70cd | 23 | if (strcmp(braille, "011011") == 0) val = 'C'; |
aismail1997 | 24:6931917c70cd | 24 | if (strcmp(braille, "011001") == 0) val = 'D'; |
aismail1997 | 24:6931917c70cd | 25 | if (strcmp(braille, "011101") == 0) val = 'E'; |
aismail1997 | 24:6931917c70cd | 26 | if (strcmp(braille, "001011") == 0) val = 'F'; |
aismail1997 | 24:6931917c70cd | 27 | if (strcmp(braille, "001001") == 0) val = 'G'; |
aismail1997 | 24:6931917c70cd | 28 | if (strcmp(braille, "001101") == 0) val = 'H'; |
aismail1997 | 24:6931917c70cd | 29 | if (strcmp(braille, "101101") == 0) val = 'I'; |
aismail1997 | 24:6931917c70cd | 30 | if (strcmp(braille, "101001") == 0) val = 'J'; |
aismail1997 | 24:6931917c70cd | 31 | /*if (strcmp(braille, "011111") == 0) val = 'K'; |
aismail1997 | 24:6931917c70cd | 32 | if (strcmp(braille, "011111") == 0) val = 'L'; |
aismail1997 | 24:6931917c70cd | 33 | if (strcmp(braille, "011111") == 0) val = 'N'; |
aismail1997 | 24:6931917c70cd | 34 | if (strcmp(braille, "011111") == 0) val = 'P'; |
aismail1997 | 24:6931917c70cd | 35 | if (strcmp(braille, "011111") == 0) val = 'Q'; |
aismail1997 | 24:6931917c70cd | 36 | if (strcmp(braille, "011111") == 0) val = 'R'; |
aismail1997 | 24:6931917c70cd | 37 | if (strcmp(braille, "011111") == 0) val = 'S'; |
aismail1997 | 24:6931917c70cd | 38 | if (strcmp(braille, "011111") == 0) val = 'T'; |
aismail1997 | 24:6931917c70cd | 39 | if (strcmp(braille, "011111") == 0) val = 'U'; |
aismail1997 | 24:6931917c70cd | 40 | if (strcmp(braille, "011111") == 0) val = 'V'; |
aismail1997 | 24:6931917c70cd | 41 | if (strcmp(braille, "011111") == 0) val = 'W'; |
aismail1997 | 24:6931917c70cd | 42 | if (strcmp(braille, "011111") == 0) val = 'X'; |
aismail1997 | 24:6931917c70cd | 43 | if (strcmp(braille, "011111") == 0) val = 'Y'; |
aismail1997 | 24:6931917c70cd | 44 | if (strcmp(braille, "011111") == 0) val = 'Z'; |
aismail1997 | 24:6931917c70cd | 45 | if (strcmp(braille, "010101") == 0) val = 'O';*/ |
aismail1997 | 23:c5df903f068a | 46 | // check if reset |
aismail1997 | 24:6931917c70cd | 47 | if (strcmp(braille, "111111") == 0) val = '!'; |
aismail1997 | 23:c5df903f068a | 48 | return val; |
aismail1997 | 23:c5df903f068a | 49 | } |
aismail1997 | 23:c5df903f068a | 50 | |
aismail1997 | 24:6931917c70cd | 51 | // get braille represention of char |
aismail1997 | 24:6931917c70cd | 52 | char* buttonArray::getBraille(char val) |
aismail1997 | 24:6931917c70cd | 53 | { |
aismail1997 | 24:6931917c70cd | 54 | char* braille; |
aismail1997 | 24:6931917c70cd | 55 | if (val == NULL) braille = "000000"; |
aismail1997 | 24:6931917c70cd | 56 | if (val == 'A') braille = "011111"; |
aismail1997 | 24:6931917c70cd | 57 | if (val == 'M') braille = "010011"; |
aismail1997 | 24:6931917c70cd | 58 | if (val == 'O') braille = "010101"; |
aismail1997 | 24:6931917c70cd | 59 | // check if reset |
aismail1997 | 24:6931917c70cd | 60 | if (val == ' ') braille = "111111"; |
aismail1997 | 24:6931917c70cd | 61 | return braille; |
aismail1997 | 24:6931917c70cd | 62 | } |
aismail1997 | 23:c5df903f068a | 63 | |
aismail1997 | 24:6931917c70cd | 64 | // return an array of which pins need to be up |
aismail1997 | 25:23970cf718ee | 65 | int* buttonArray::pinsUp(char val) |
aismail1997 | 24:6931917c70cd | 66 | { |
aismail1997 | 25:23970cf718ee | 67 | int* pinsup; |
aismail1997 | 24:6931917c70cd | 68 | char* braille = getBraille(val); |
aismail1997 | 24:6931917c70cd | 69 | int j = 0; |
aismail1997 | 24:6931917c70cd | 70 | for (int i = 0; i < 6; i++) { |
aismail1997 | 24:6931917c70cd | 71 | if (braille[i] == '0') { |
aismail1997 | 25:23970cf718ee | 72 | pinsup[j] = i+1; |
aismail1997 | 24:6931917c70cd | 73 | j++; |
aismail1997 | 24:6931917c70cd | 74 | } |
aismail1997 | 24:6931917c70cd | 75 | } |
aismail1997 | 25:23970cf718ee | 76 | return pinsup; |
aismail1997 | 24:6931917c70cd | 77 | } |
aismail1997 | 24:6931917c70cd | 78 | |
aismail1997 | 24:6931917c70cd | 79 | // return feedback on which pins need to be corrected |
aismail1997 | 24:6931917c70cd | 80 | // takes in current and actual char as input and returns status of each char |
aismail1997 | 24:6931917c70cd | 81 | int* buttonArray::wrongPins(char input, char actual) |
aismail1997 | 24:6931917c70cd | 82 | { |
aismail1997 | 24:6931917c70cd | 83 | if (input == NULL) return NULL; |
aismail1997 | 25:23970cf718ee | 84 | int* wrong; |
aismail1997 | 24:6931917c70cd | 85 | char* inarr = getBraille(input); |
aismail1997 | 24:6931917c70cd | 86 | char* actarr = getBraille(actual); |
aismail1997 | 25:23970cf718ee | 87 | int j = 0; |
aismail1997 | 24:6931917c70cd | 88 | for (int i = 0; i < 6; i++) { |
aismail1997 | 25:23970cf718ee | 89 | if(inarr[i] != actarr[i]) { |
aismail1997 | 25:23970cf718ee | 90 | wrong[j] = i+1; |
aismail1997 | 25:23970cf718ee | 91 | j++; |
aismail1997 | 25:23970cf718ee | 92 | } |
aismail1997 | 24:6931917c70cd | 93 | } |
aismail1997 | 24:6931917c70cd | 94 | return wrong; |
aismail1997 | 24:6931917c70cd | 95 | } |
aismail1997 | 23:c5df903f068a | 96 | |
aismail1997 | 23:c5df903f068a | 97 | // release buttons |
aismail1997 | 23:c5df903f068a | 98 | void buttonArray::releaseButtons() |
aismail1997 | 23:c5df903f068a | 99 | { |
aismail1997 | 23:c5df903f068a | 100 | if (button1.getPress()) { |
aismail1997 | 23:c5df903f068a | 101 | button1.moveServoOut(); |
aismail1997 | 23:c5df903f068a | 102 | button1.setState(3); |
aismail1997 | 23:c5df903f068a | 103 | button1.setPress(0); |
aismail1997 | 23:c5df903f068a | 104 | } |
aismail1997 | 23:c5df903f068a | 105 | } |