Component Test's Software to work with "Universal Controller Box" - Software is an interpreter or "compiler" for programs to be done with a .txt file and read off of the SD Card

Dependencies:   BridgeDriver FrontPanelButtons MCP23017 SDFileSystem TextLCD mbed

Revision:
11:bc9cd2869f95
Parent:
9:5a0c4c6e39c7
--- a/TextFile.h	Wed Sep 24 22:54:36 2014 +0000
+++ b/TextFile.h	Wed Oct 01 18:11:38 2014 +0000
@@ -61,8 +61,7 @@
     
     //Cycle through all files listed in the directoy (strings in the vector list)
     int n = 0;
-    for(vector<string>::iterator it=filenames.begin(); it < filenames.end(); it++)  
-    {
+    for(vector<string>::iterator it=filenames.begin(); it < filenames.end(); it++){
         
         vector<string> fileName; //filename[0] = filename, filename[1] = extension
 
@@ -92,39 +91,47 @@
 
 int getNextLine(FILE *selectedFile, LineData &lineData) {
     
-    lineData.lineAddress = ftell(selectedFile);
-    
-    if (lineData.lineAddress == -1L){
-        ErrorOut("Unable to get address of line, SD Card Removed?", lineData.lineNumber + 1);
-        return -1;
-    }
-    
-    //char *newLine;
-    //getline(selectedFile, newLine);
-    char newLine[MAX_LINE_LENGTH];
-    
-    fgets(newLine, MAX_LINE_LENGTH, selectedFile);
+    int validLine = 0;
+    while (!validLine){
+            
+        lineData.lineAddress = ftell(selectedFile);
+        
+        if (lineData.lineAddress == -1L){
+            ErrorOut("Unable to get address of line, SD Card Removed?", lineData.lineNumber + 1);
+            return -1;
+        }
+        
+        //char *newLine;
+        //getline(selectedFile, newLine);
+        char newLine[MAX_LINE_LENGTH];
+        
+        fgets(newLine, MAX_LINE_LENGTH, selectedFile);
+        
+        if (newLine == NULL){
+            ErrorOut("Unable to get the next line, SD Card Removed?", lineData.lineNumber + 1);
+            return -1;
+        }
+        
+        lineData.lineNumber++; // new line successfully found, increase lineNumber      
+        
+        //pull out each individual word (separated by any white space), and place it in the vector
+        stringstream newLineStrm(newLine);    
+        istream_iterator<string> it(newLineStrm);
+        istream_iterator<string> end;
+        vector<string> results(it, end);
+        
+        //Get the size of the results vector, if it is 0 then while loop will loop again,
+        //if it has a value, then it will accept the line and end looping cycles
+        validLine = results.size();
     
-    if (newLine == NULL){
-        ErrorOut("Unable to get the next line, SD Card Removed?", lineData.lineNumber + 1);
-        return -1;
+        //copy the vector of results into the array of words
+        copy(results.begin(), results.end(), lineData.word);
+        
+        lineData.numWords = results.size(); //Record the number of words in the line
+        
+        results.erase(results.begin(), results.end()); //remove the results vector from memory
     }
     
-    lineData.lineNumber++; // new line successfully found, increase lineNumber      
-    
-    //pull out each individual word (separated by any white space), and place it in the vector
-    stringstream newLineStrm(newLine);    
-    istream_iterator<string> it(newLineStrm);
-    istream_iterator<string> end;
-    vector<string> results(it, end);
-    
-    //copy the vector of results into the array of words
-    copy(results.begin(), results.end(), lineData.word);
-    
-    lineData.numWords = results.size(); //Record the number of words in the line
-    
-    results.erase(results.begin(), results.end()); //remove the results vector from memory
-    
     //Update the Current Line Number
     lcd.setAddress(0,2);
     lcd.printf("Current Line#: %d ", lineData.lineNumber);
@@ -134,7 +141,7 @@
     lcd.printf("                    "); // Clear the Line using Spaces (Emptyness) - Note one line is 20 Characters
     lcd.setAddress(0,3);
     lcd.printf("cmd/dvc: %s", lineData.word[0]);
-    
+
     /*
     lcd.cls(); //clear the display   
     lcd.setAddress(0,0);
@@ -145,7 +152,7 @@
     lcd.printf("wrd3: %s", lineData.word[2]);
     lcd.setAddress(0,3);
     lcd.printf("wrd4: %s", lineData.word[3]);
-    wait(2);*/
+    wait(1);*/
 }