Fork of original senior design repo
Dependencies: SDFileSystem mbed-rtos mbed wave_player emic2
Fork of BAT_senior_design by
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "wave_player.h" 00004 #include "SDFileSystem.h" 00005 #include "button.h" 00006 #include "buttonArray.h" 00007 #include <string> 00008 #include <iostream> 00009 #include "emic2.h" 00010 00011 using namespace std; 00012 00013 // DEFINE I/O 00014 PwmOut myservo(p21); 00015 DigitalIn pb1 (p20); 00016 PwmOut myservo2(p22); 00017 DigitalIn pb2 (p19); 00018 PwmOut myservo3(p23); 00019 DigitalIn pb3 (p18); 00020 PwmOut myservo4(p24); 00021 DigitalIn pb4 (p17); 00022 PwmOut myservo5(p25); 00023 DigitalIn pb5 (p16); 00024 PwmOut myservo6(p26); 00025 DigitalIn pb6 (p15); 00026 00027 //DigitalOut led1(LED1); 00028 //DigitalOut led3(LED3); 00029 //DigitalOut led4(LED4); 00030 00031 DigitalIn linpot(p9); 00032 //Serial pc(USBTX, USBRX); 00033 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card 00034 //AnalogOut DACout(p26); 00035 //wave_player waver(&DACout); 00036 //button button1(myservo, pb1, linpot); 00037 button button1(myservo, pb1, 1); 00038 button button2(myservo2, pb2, 2); 00039 button button3(myservo3, pb3, 3); 00040 button button4(myservo4, pb4, 4); 00041 button button5(myservo5, pb5, 5); 00042 button button6(myservo6, pb6, 6); 00043 00044 buttonArray buttonarr(button1, button2, button3, button4, button5, button6); 00045 00046 emic2 myTTS(p28, p27); //serial RX,TX pins to emic 00047 00048 // INITIALIZE VARIABLES 00049 // add mode, reset buttons 00050 int start = 0; 00051 int submit = 0; 00052 // Buttons begins in up state 00053 int state = 0; 00054 int state2 = 0; 00055 int state3 = 0; 00056 int state4 = 0; 00057 int state5 = 0; 00058 int state6 = 0; 00059 int count = 0; 00060 00061 // THREADS 00062 00063 void button_thread() 00064 { 00065 while(true) { 00066 state = button1.updateState(); 00067 //led4 = button1.getLp(); 00068 Thread::wait(100); // wait till thread is done 00069 } 00070 } 00071 00072 void button2_thread() 00073 { 00074 while(true) { 00075 state2 = button2.updateState(); 00076 Thread::wait(100); // wait till thread is done 00077 } 00078 } 00079 00080 // thread for the custom button 00081 void button3_thread() 00082 { 00083 while(true) { 00084 state3 = button3.updateState(); 00085 Thread::wait(100); // wait till thread is done 00086 } 00087 } 00088 00089 // thread for the custom button 00090 void button4_thread() 00091 { 00092 while(true) { 00093 state4 = button4.updateState(); 00094 Thread::wait(100); // wait till thread is done 00095 } 00096 } 00097 00098 // thread for the custom button 00099 void button5_thread() 00100 { 00101 while(true) { 00102 state5 = button5.updateState(); 00103 Thread::wait(100); // wait till thread is done 00104 } 00105 } 00106 00107 // thread for the custom button 00108 void button6_thread() 00109 { 00110 while(true) { 00111 state6 = button6.updateState(); 00112 Thread::wait(100); // wait till thread is done 00113 } 00114 } 00115 00116 void submit_thread() 00117 { 00118 Thread::wait(500); // wait till thread is done 00119 } 00120 00121 void start_thread() 00122 { 00123 // read pb_start 00124 // if 1 00125 start = 1; 00126 //pc.printf("start %d ", start); 00127 // else 0 00128 Thread::wait(500); // wait till thread is done 00129 } 00130 00131 00132 int main() 00133 { 00134 00135 00136 // SETUP 00137 // pull up the pushbutton to prevent bouncing 00138 pb1.mode(PullUp); 00139 pb2.mode(PullUp); 00140 pb3.mode(PullUp); 00141 pb4.mode(PullUp); 00142 pb5.mode(PullUp); 00143 pb6.mode(PullUp); 00144 wait(.001); 00145 00146 // servos begin at 30 degrees 00147 // replace with a button setup function 00148 //buttonarr.setup(); 00149 00150 //led1 = 1; 00151 //led2 = 1; 00152 Thread t1(button_thread); 00153 //Thread t2(button2_thread); 00154 Thread t3(button3_thread); 00155 Thread t4(button4_thread); 00156 Thread t5(button5_thread); 00157 //Thread t6(button6_thread); 00158 t1.start(button_thread); 00159 //t2.start(button2_thread); 00160 t3.start(button3_thread); 00161 t4.start(button4_thread); 00162 t5.start(button5_thread); 00163 //t6.start(button6_thread); 00164 00165 // PARSE INPUT FILE FOR LETTERS AND WORDS 00166 char delimiter = ','; 00167 // TODO: fix the letters 00168 string letter[2]; 00169 string word[2]; 00170 char check; 00171 string temp; 00172 string tempword = ""; 00173 int counter = 0; 00174 FILE *fp = fopen("/sd/plan.txt", "r"); //create file 00175 if(fp == NULL) { 00176 //pc.printf("Could not open file for write\n"); 00177 } 00178 check = fgetc(fp); //grabs a char from file 00179 while(check != '\n') { //while not at the end of line for letters 00180 if((check == delimiter) && (temp.length() == 1)) { //at a comma and have a letter stored 00181 letter[counter] = temp; //write letter 00182 //pc.printf("Letter: %s \n", letter[counter]); 00183 counter = counter + 1; //increment counter 00184 } else { 00185 temp = check; //store letter 00186 } 00187 check = fgetc(fp); //grabs next char 00188 } 00189 counter = 0; //reset counter 00190 check = fgetc(fp); //grabs next char 00191 while(!feof(fp)) { //while not at the end of line for words 00192 if(check == delimiter) { //when at the comma at the end of a word 00193 word[counter] = tempword; //write word 00194 //pc.printf("Word: %s \n", word[counter]); 00195 tempword = ""; 00196 counter = counter + 1; //increment counter 00197 } else { 00198 tempword = tempword + check; //concatenate letters to build word 00199 } 00200 check = fgetc(fp); //grabs next char 00201 } 00202 fclose(fp); //close file 00203 00204 // start threads for reset, mode, start 00205 //Thread t1(start_thread); 00206 //pc.printf("start thread"); 00207 //Thread t2(submit_thread); 00208 // setup SDcard and Speaker 00209 00210 // when started 00211 //while (start == 0){} 00212 //Thread t3(button_thread); 00213 //pc.printf("button thread"); 00214 //Thread t4(button2_thread); 00215 //pc.printf("button2 thread"); 00216 00217 //Thread t3(submit_thread); 00218 00219 // when submitted 00220 //while (submit == 0) {} 00221 00222 // start button threads and submit thread 00223 // if submit close button threads and submit thread 00224 // check result 00225 // play results on speaker 00226 // save results 00227 00228 char currletter; 00229 int lettersize = sizeof(letter)/sizeof(letter[0]); 00230 for (int i = 0; i < lettersize; i++) { 00231 currletter = letter[i][0]; 00232 //pc.printf("currletter %c \n", currletter); 00233 //pc.printf("braille %s \n", buttonarr.getBraille(currletter)); 00234 } 00235 00236 /*int* pinsup = buttonarr.pinsUp('M'); 00237 int currpress; 00238 // get what pins to press 00239 for (int i = 1; i <= pinsup[0]; i++) { 00240 // speaker stuff 00241 currpress = pinsup[i]; 00242 }*/ 00243 00244 /*int* wrongpins = buttonarr.wrongPins('M', 'O'); 00245 int currwrong; 00246 // get what pins are wrong 00247 for (int i = 1; i <= wrongpins[0]; i++) { 00248 // speaker stuff 00249 currwrong = wrongpins[i]; 00250 }*/ 00251 00252 //TEXT-TO-SPEECH LOGIC 00253 myTTS.volume(18); //max volume 00254 string repeat = "Please try again."; 00255 00256 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 00257 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response 00258 for(int i = 0; i < lettersize; i++) { //iterate through the letter array 00259 char currletter = letter[i][0]; 00260 //pc.printf("letter: %c \n", currletter); 00261 int* pinsup = buttonarr.pinsUp(currletter); 00262 int currpress; 00263 int numpinsups = pinsup[0]; // size of array is first element of pinsup 00264 //string presspin; 00265 string presspin = "STo write the letter "; 00266 presspin = presspin + letter[i]; 00267 presspin = presspin + ", press pins"; 00268 00269 for (int j = 1; j < numpinsups; j++) { // get what pins to press 00270 currpress = pinsup[j]; 00271 switch (currpress) { 00272 case 1: 00273 presspin = presspin + " 1,"; 00274 break; 00275 case 2: 00276 presspin = presspin + " 2,"; 00277 break; 00278 case 3: 00279 presspin = presspin + " 3,"; 00280 break; 00281 case 4: 00282 presspin = presspin + " 4,"; 00283 break; 00284 case 5: 00285 presspin = presspin + " 5,"; 00286 break; 00287 case 6: 00288 presspin = presspin + " 6,"; 00289 break; 00290 } 00291 } 00292 myTTS.speakf("%s\r",presspin); 00293 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response 00294 wait(1); 00295 00296 char userinput = buttonarr.checkVal(); 00297 // get input 00298 //pc.printf("Your input was: %c", userinput); 00299 00300 // check result 00301 int* wrongpins = buttonarr.wrongPins(userinput, currletter); 00302 00303 //pc.printf("wrongpins are: %d", wrongpins[0]); 00304 } 00305 //myTTS.speakf("STo write the letter %s, press pins %D\r",letter[i]); 00306 //myTTS.ready(); //ready waits for speech to finish from last command with a ":" response 00307 00308 00309 //pc.printf("current braille %c \n", buttonarr.checkVal()); 00310 //pc.printf("%c\n", buttonarr.releaseButtons()); 00311 00312 // MAIN THREAD 00313 while(true) { 00314 00315 // read linear potentiometer 00316 //led4 = linpot; 00317 00318 Thread::wait(500); // wait till thread is done 00319 } 00320 }
Generated on Thu Jul 14 2022 07:22:21 by
1.7.2
