Words in Typing mode FINAL
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_Type_word by
Revision 23:23970cf718ee, committed 2017-11-10
- Comitter:
- aismail1997
- Date:
- Fri Nov 10 15:59:21 2017 +0000
- Parent:
- 22:6931917c70cd
- Child:
- 24:4b2940eec275
- Child:
- 27:b2e53ce54b3e
- Commit message:
- Integrated parsing code and tested button functions
Changed in this revision
--- a/button.cpp Fri Nov 03 18:56:01 2017 +0000 +++ b/button.cpp Fri Nov 10 15:59:21 2017 +0000 @@ -2,7 +2,7 @@ #include "button.h" #include "emic2.h" -emic2 myTTS(p28, p27); //serial RX,TX pins to emic +//emic2 myTTS(p28, p27); //serial RX,TX pins to emic //DigitalOut led4(LED4); // button constructor
--- a/buttonArray.cpp Fri Nov 03 18:56:01 2017 +0000
+++ b/buttonArray.cpp Fri Nov 10 15:59:21 2017 +0000
@@ -62,18 +62,18 @@
}
// return an array of which pins need to be up
-int* buttonArray::pinsToPress(char val)
+int* buttonArray::pinsUp(char val)
{
- int* pinstopress;
+ int* pinsup;
char* braille = getBraille(val);
int j = 0;
for (int i = 0; i < 6; i++) {
if (braille[i] == '0') {
- pinstopress[j] = i;
+ pinsup[j] = i+1;
j++;
}
}
- return pinstopress;
+ return pinsup;
}
// return feedback on which pins need to be corrected
@@ -81,11 +81,15 @@
int* buttonArray::wrongPins(char input, char actual)
{
if (input == NULL) return NULL;
- int wrong[6];
+ int* wrong;
char* inarr = getBraille(input);
char* actarr = getBraille(actual);
+ int j = 0;
for (int i = 0; i < 6; i++) {
- wrong[i] = (inarr[i] != actarr[i]);
+ if(inarr[i] != actarr[i]) {
+ wrong[j] = i+1;
+ j++;
+ }
}
return wrong;
}
--- a/buttonArray.h Fri Nov 03 18:56:01 2017 +0000
+++ b/buttonArray.h Fri Nov 10 15:59:21 2017 +0000
@@ -23,6 +23,6 @@
int* wrongPins(char input, char actual);
char checkVal(); // return buttons ascii representation
void releaseButtons();// release all buttons;
- int* pinsToPress(char val);
+ int* pinsUp(char val);
char* getBraille(char val);
};
\ No newline at end of file
--- a/main.cpp Fri Nov 03 18:56:01 2017 +0000
+++ b/main.cpp Fri Nov 10 15:59:21 2017 +0000
@@ -4,6 +4,10 @@
#include "SDFileSystem.h"
#include "button.h"
#include "buttonArray.h"
+#include <string>
+#include <iostream>
+
+using namespace std;
// DEFINE I/O
PwmOut myservo(p21);
@@ -24,8 +28,8 @@
//DigitalOut led4(LED4);
DigitalIn linpot(p9);
-//Serial pc(USBTX, USBRX);
-//SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
+Serial pc(USBTX, USBRX);
+SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
//AnalogOut DACout(p26);
//wave_player waver(&DACout);
//button button1(myservo, pb1, linpot);
@@ -51,21 +55,8 @@
int state6 = 0;
int count = 0;
-// FUNCTIONS
-// play a file on the speaker
-/*void playSound(wave_player waver)
-{
- FILE *wave_file;
- wave_file=fopen("/sd/lesson.wav","r");
- waver.play(wave_file);
- fclose(wave_file);
-}*/
-
// THREADS
-// thread for the custom button
-//int count = 0;
-
void button_thread()
{
while(true) {
@@ -137,6 +128,7 @@
int main()
{
+ /*
// SETUP
// pull up the pushbutton to prevent bouncing
pb1.mode(PullUp);
@@ -176,11 +168,11 @@
for(int i=0; i<=3; i++) {
myservo6 = i/100.0;
wait(0.01);
- }
+ }*/
//led1 = 1;
//led2 = 1;
- Thread t1(button_thread);
+ /*Thread t1(button_thread);
Thread t2(button2_thread);
Thread t3(button3_thread);
Thread t4(button4_thread);
@@ -191,7 +183,45 @@
t3.start(button3_thread);
t4.start(button4_thread);
t5.start(button5_thread);
- t6.start(button6_thread);
+ t6.start(button6_thread);*/
+
+ // PARSE INPUT FILE FOR LETTERS AND WORDS
+ char delimiter = ',';
+ string letter[2];
+ string word[2];
+ char check;
+ string temp;
+ string tempword = "";
+ int counter = 0;
+ FILE *fp = fopen("/sd/plan.txt", "r"); //create file
+ if(fp == NULL) {
+ pc.printf("Could not open file for write\n");
+ }
+ check = fgetc(fp); //grabs a char from file
+ while(check != '\n') { //while not at the end of line for letters
+ if((check == delimiter) && (temp.length() == 1)) { //at a comma and have a letter stored
+ letter[counter] = temp; //write letter
+ pc.printf("Letter: %s \n", letter[counter]);
+ counter = counter + 1; //increment counter
+ } else {
+ temp = check; //store letter
+ }
+ check = fgetc(fp); //grabs next char
+ }
+ counter = 0; //reset counter
+ check = fgetc(fp); //grabs next char
+ while(!feof(fp)) { //while not at the end of line for words
+ if(check == delimiter) { //when at the comma at the end of a word
+ word[counter] = tempword; //write word
+ pc.printf("Word: %s \n", word[counter]);
+ tempword = "";
+ counter = counter + 1; //increment counter
+ } else {
+ tempword = tempword + check; //concatenate letters to build word
+ }
+ check = fgetc(fp); //grabs next char
+ }
+ fclose(fp); //close file
// start threads for reset, mode, start
//Thread t1(start_thread);
@@ -216,11 +246,21 @@
// check result
// play results on speaker
// save results
-
- //pc.printf("%c\n", buttonarr.checkVal()); // check input
- //pc.printf("%s\n", buttonarr.getBraille('A')); // check mapping
- //pc.printf("%d\n", buttonarr.pinsToPress('A'));
- //pc.printf("%d\n", buttonarr.wrongPins('M', 'O'));
+ 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');
+ pc.printf("pins up M: %d \n", pinsup[0]);
+ pc.printf("pins up M: %d \n", pinsup[1]);
+ pc.printf("pins up M: %d \n", pinsup[2]);
+ int* wrongpins = buttonarr.wrongPins('M', 'O');
+ pc.printf("wrong pins M & O %d \n", wrongpins[0]);
+ pc.printf("wrong pins M & O %d \n", wrongpins[1]);
+ //pc.printf("current braille %c \n", buttonarr.checkVal());
//pc.printf("%c\n", buttonarr.releaseButtons());
// MAIN THREAD
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plan.txt Fri Nov 10 15:59:21 2017 +0000 @@ -0,0 +1,2 @@ +M,O, +Mom, \ No newline at end of file
