Fork of original senior design repo
Dependencies: SDFileSystem mbed-rtos mbed wave_player emic2
Fork of BAT_senior_design by
buttonArray.cpp
- Committer:
- aismail1997
- Date:
- 2017-11-03
- Revision:
- 21:6931917c70cd
- Parent:
- 20:c5df903f068a
- Child:
- 22:23970cf718ee
File content as of revision 21:6931917c70cd:
#include "mbed.h"
#include "buttonArray.h"
// type mode
// buttonArray constructor
buttonArray::buttonArray(button b1, button b2, button b3, button b4, button b5, button b6)
: button1(b1), button2(b2), button3(b3), button4(b4), button5(b5), button6(b6) {}
// FUNCTIONS
// map input braille to ascii
// braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII
char buttonArray::checkVal()
{
char* braille;
char val = NULL;
sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
if (strcmp(braille, "000000") == 0) val = '@';
if (strcmp(braille, "011111") == 0) val = 'A';
if (strcmp(braille, "001111") == 0) val = 'B';
if (strcmp(braille, "011011") == 0) val = 'C';
if (strcmp(braille, "011001") == 0) val = 'D';
if (strcmp(braille, "011101") == 0) val = 'E';
if (strcmp(braille, "001011") == 0) val = 'F';
if (strcmp(braille, "001001") == 0) val = 'G';
if (strcmp(braille, "001101") == 0) val = 'H';
if (strcmp(braille, "101101") == 0) val = 'I';
if (strcmp(braille, "101001") == 0) val = 'J';
/*if (strcmp(braille, "011111") == 0) val = 'K';
if (strcmp(braille, "011111") == 0) val = 'L';
if (strcmp(braille, "011111") == 0) val = 'N';
if (strcmp(braille, "011111") == 0) val = 'P';
if (strcmp(braille, "011111") == 0) val = 'Q';
if (strcmp(braille, "011111") == 0) val = 'R';
if (strcmp(braille, "011111") == 0) val = 'S';
if (strcmp(braille, "011111") == 0) val = 'T';
if (strcmp(braille, "011111") == 0) val = 'U';
if (strcmp(braille, "011111") == 0) val = 'V';
if (strcmp(braille, "011111") == 0) val = 'W';
if (strcmp(braille, "011111") == 0) val = 'X';
if (strcmp(braille, "011111") == 0) val = 'Y';
if (strcmp(braille, "011111") == 0) val = 'Z';
if (strcmp(braille, "010101") == 0) val = 'O';*/
// check if reset
if (strcmp(braille, "111111") == 0) val = '!';
return val;
}
// get braille represention of char
char* buttonArray::getBraille(char val)
{
char* braille;
if (val == NULL) braille = "000000";
if (val == 'A') braille = "011111";
if (val == 'M') braille = "010011";
if (val == 'O') braille = "010101";
// check if reset
if (val == ' ') braille = "111111";
return braille;
}
// return an array of which pins need to be up
int* buttonArray::pinsToPress(char val)
{
int* pinstopress;
char* braille = getBraille(val);
int j = 0;
for (int i = 0; i < 6; i++) {
if (braille[i] == '0') {
pinstopress[j] = i;
j++;
}
}
return pinstopress;
}
// return feedback on which pins need to be corrected
// takes in current and actual char as input and returns status of each char
int* buttonArray::wrongPins(char input, char actual)
{
if (input == NULL) return NULL;
int wrong[6];
char* inarr = getBraille(input);
char* actarr = getBraille(actual);
for (int i = 0; i < 6; i++) {
wrong[i] = (inarr[i] != actarr[i]);
}
return wrong;
}
// release buttons
void buttonArray::releaseButtons()
{
if (button1.getPress()) {
button1.moveServoOut();
button1.setState(3);
button1.setPress(0);
}
}
