Working read code with mode button

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Testnew by BAT

Committer:
aismail1997
Date:
Wed Nov 29 15:14:26 2017 +0000
Revision:
36:1248dfa0740b
Parent:
35:3090ec93b4aa
Child:
37:ef0921d9b5bd
Child:
38:593bae6b342b
Button logic works;

Who changed what in which revision?

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