Words in Typing mode

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_Type_word by Azra Ismail

Revision:
23:23970cf718ee
Parent:
22:6931917c70cd
Child:
24:4b2940eec275
Child:
27:b2e53ce54b3e
--- 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