Letters in typing mode
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_senior_design_Test_Type by
Revision 35:ef0921d9b5bd, committed 2017-11-29
- Comitter:
- aismail1997
- Date:
- Wed Nov 29 16:26:22 2017 +0000
- Parent:
- 34:1248dfa0740b
- Commit message:
- word code added (commented out), flipped logic, added reset in the beginning
Changed in this revision
| buttonArray.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/buttonArray.cpp Wed Nov 29 15:14:26 2017 +0000
+++ b/buttonArray.cpp Wed Nov 29 16:26:22 2017 +0000
@@ -22,7 +22,7 @@
sprintf(braille, "%d%d%d%d%d%d", test, button2.getPress(),
button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());*/
//pc.printf(" %s \n", braille);
- if (strcmp(braille, "000000") == 0) val = 'X';
+ 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';
@@ -33,8 +33,8 @@
if (strcmp(braille, "001101") == 0) val = 'H';
if (strcmp(braille, "101101") == 0) val = 'I';
if (strcmp(braille, "101001") == 0) val = 'J';
- if (strcmp(braille, "101100") == 0) val = 'M';
- if (strcmp(braille, "101010") == 0) val = 'O';
+ if (strcmp(braille, "010011") == 0) val = 'M';
+ if (strcmp(braille, "010101") == 0) val = 'O';
/*if (strcmp(braille, "011111") == 0) val = 'K';
if (strcmp(braille, "011111") == 0) val = 'L';
if (strcmp(braille, "011111") == 0) val = 'N';
@@ -50,7 +50,7 @@
if (strcmp(braille, "011111") == 0) val = 'Y';
if (strcmp(braille, "011111") == 0) val = 'Z';*/
// check if reset
- if (strcmp(braille, "111111") == 0) val = 'Z';
+ if (strcmp(braille, "111111") == 0) val = '!';
//pc.printf(" %c \n", val);
return val;
}
@@ -95,8 +95,6 @@
// TODO check initial value of wrong
int* wrong;
wrong = new int[7];
- //char* inarr = getBraille(input);
- //pc.printf("input %s\n", inarr);
char* actarr = getBraille(actual);
//pc.printf("wrong pins");
int j = 1;
--- a/main.cpp Wed Nov 29 15:14:26 2017 +0000
+++ b/main.cpp Wed Nov 29 16:26:22 2017 +0000
@@ -144,10 +144,6 @@
// replace with a button setup function
buttonarr.setup();
- //led1 = 1;
- //led2 = 1;
-
-
// PARSE INPUT FILE FOR LETTERS AND WORDS
char delimiter = ',';
// TODO: fix the letters
@@ -198,70 +194,50 @@
t3.start(button3_thread);
t4.start(button4_thread);
t5.start(button5_thread);
- //t6.start(button6_thread);
-
- // start threads for reset, mode, start
- //Thread t1(start_thread);
- //pc.printf("start thread");
- //Thread t2(submit_thread);
- // setup SDcard and Speaker
-
- // when started
- //while (start == 0){}
- //Thread t3(button_thread);
- //pc.printf("button thread");
- //Thread t4(button2_thread);
- //pc.printf("button2 thread");
-
- //Thread t3(submit_thread);
// when submitted
//while (submit == 0) {}
-
// start button threads and submit thread
// if submit close button threads and submit thread
// check result
// play results on speaker
// save results
- char currletter;
- int lettersize = sizeof(letter)/sizeof(letter[0]);
- /*for (int i = 0; i < lettersize; i++) {
- currletter = letter[i][0];
- //pc.printf("currletter %c \n", currletter);
- //pc.printf("braille %s \n", buttonarr.getBraille(currletter));
- }*/
-
- /*int* pinsup = buttonarr.pinsUp('M');
- int currpress;
- // get what pins to press
- for (int i = 1; i <= pinsup[0]; i++) {
- // speaker stuff
- currpress = pinsup[i];
- }*/
-
- /*int* wrongpins = buttonarr.wrongPins('M', 'O');
- int currwrong;
- // get what pins are wrong
- for (int i = 1; i <= wrongpins[0]; i++) {
- // speaker stuff
- currwrong = wrongpins[i];
- }*/
-
-
//TEXT-TO-SPEECH LOGIC
myTTS.volume(18); //max volume
myTTS.voice(2);
myTTS.speakf("SWelcome to Bat, the Braille Assistive Teacher. This device will help you learn how to write and type braille.\r"); // Send the desired string to convert to speech
myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+
+ char* braille;
+ char userinput;
+
+ // INITIAL RESET
+ int reset = 1;
+ myTTS.speakf("SPlease setup the device by pressing down all the buttons.\r");
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+ while(reset == 1) {
+ sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
+ button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
+ userinput = buttonarr.checkVal(braille);
+ if(userinput == '!') {
+ reset = 0;
+ } else {
+ reset = 0; // TODO: remove this line
+ myTTS.speakf("SSetup failed. Please try again.\r");
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+ }
+ }
+
+ int lettersize = sizeof(letter)/sizeof(letter[0]);
+
for(int i = 0; i < lettersize; i++) { //iterate through the letter array
char currletter = letter[i][0];
//pc.printf("letter: %c \n", currletter);
int* pinsup = buttonarr.pinsUp(currletter);
int currpress;
int numpinsups = pinsup[0]; // size of array is first element of pinsup
- //string presspin;
string presspin = "STo write the letter ";
presspin = presspin + letter[i];
presspin = presspin + ", press buttons";
@@ -292,17 +268,14 @@
myTTS.speakf("%s\r",presspin);
myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
wait(1);
- //pc.printf("hello");
//WORKS UP TO HERE
- char* braille;
+
+ // PARSE LETTERS
sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
- char userinput = buttonarr.checkVal(braille);
+ userinput = buttonarr.checkVal(braille);
pc.printf(" %s ", braille);
- int test1 = button1.getPress();
- pc.printf(" %d\n", test1);
- pc.printf(" %c ", userinput);
//pc.printf("userinput: %c", userinput);
// get input
//pc.printf("Your input was: %c", userinput);
@@ -311,14 +284,10 @@
// check result
pc.printf("\n %c %c", userinput, currletter);
int* wrongpins = buttonarr.wrongPins(braille, currletter);
- //string presspin;
- //wrongpins[0] != 1
int test = 1;
while(test == 1) {
//pc.printf("In while loop");
wrongpin = "SYour answer is incorrect. Buttons";
- //wrongpin = wrongpin + letter[i];
- //wrongpin = wrongpin + ", press pins";
for (int j = 1; j < wrongpins[0]; j++) { // get what pins are wrong
currwrong = wrongpins[j];
//pc.printf("currwrong: %d", currwrong);
@@ -349,7 +318,6 @@
myTTS.speakf("%s\r",wrongpin);
myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
//UPDATE THE PINS THAT ARE WRONG BY CHECKING AGAIN BELOW
- //char* braille;
sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
userinput = buttonarr.checkVal(braille);
@@ -364,38 +332,102 @@
myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
}
}
- int reset = 1;
+ reset = 1;
myTTS.speakf("SNow reset the device by pressing down all the buttons.\r");
myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
while(reset == 1) {
-
- char* braille;
sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
userinput = buttonarr.checkVal(braille);
- if(userinput == 'Z') {
+ if(userinput == '!') {
reset = 0;
} else {
- reset = 0;
- myTTS.speakf("SNot all of the buttons were reset. Please try again.\r");
+ reset = 0; // TODO: remove this line
+ myTTS.speakf("SSetup failed. Please try again.\r");
myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
}
}
- //pc.printf("wrongpins are: %d", wrongpins[0]);
}
- //myTTS.speakf("STo write the letter %s, press pins %D\r",letter[i]);
- //myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+
+ // WORD CODE
+
+ // WORD COUNTER
+ // go through each word
+ // go through each letter in the word
+ // get user input
+ // when buttons reset - save previous letter
+ // loop until submit button is pressed
+ // compare words
+ // check what letters were wrong
+ // give wrong letters - correct spelling is...
+ /*
+ string currword;
+ int wordsize = sizeof(word)/sizeof(word[0]);
+
+ myTTS.speakf("SLet us now put these letters together to form words. Please reset buttons after each letter. Press down the submit button when done.\r"); // Send the desired string to convert to speech
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+
+ // loop through each of the words
+ for(int i = 0; i < wordsize; i++) { //iterate through the word array
+ currword = word[i];
+ presspin = "To type the word ";
+ presspin = presspin + word[i];
+ presspin = presspin + ", type letters ";
+ for (int j = 0; j < currword.length(); j++) {
+ presspin = presspin + ", "+ currword[j];
+ }
+ myTTS.speakf("S%s\r", presspin);
+ myTTS.ready();
+
+ string wordinput;
+
+ // loop through each of the letters
+ olduserinput;
+ incorrect = 1;
+ char userinput;
+ char* braille;
- //buttonarr.releaseButtons();
- //pc.printf("current braille %c \n", buttonarr.checkVal());
- //pc.printf("%c\n", buttonarr.releaseButtons());
+ // while(!submit)
+ while (incorrect) {
+ // replace for loop with submit
+ // while (!submit) {
+ for (int j = 0; j < currword.length(); j++) {
+ //currletter = currword[j];
+ // check if all buttons were pressed
+ wait(1);
+
+ char* braille;
+ char* oldbraille;
+
+ // wait for input
+ while (strcmp(braille, "000000") == 0) {}
+
+ // while buttons have not been released
+ while (strcmp(braille, "000000") != 0) {
+ oldbraille = braille;
+ sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
+ button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
+ } // at the end of this, braille contains the letter representation
+ // flip braille values
+ userinput = checkVal(braille);
+ wordinput[j] = olduserinput;
+ }
+
+ // check result of words
+ if (wordinput.compare(currword) == 0) { // input is correct
+ incorrect = 0;
+ myTTS.speakf("Good job!\r");
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+ } else {
+ incorrect = 0; // delete this line
+ myTTS.speakf("SPlease try again!.\r");
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+ }
+ }*/
+
// MAIN THREAD
while(true) {
-
- // read linear potentiometer
- //led4 = linpot;
-
Thread::wait(500); // wait till thread is done
}
}
\ No newline at end of file
