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
TextFile.h
- Committer:
- mehatfie
- Date:
- 2014-09-18
- Revision:
- 2:3e7baa3e3fec
- Parent:
- 1:5731f31f96be
- Child:
- 5:e36e0538a903
File content as of revision 2:3e7baa3e3fec:
#ifndef TEXTFILE_HPP #define TEXTFILE_HPP #include "mbed.h" #include "TextLCD.h" #include "SDFileSystem.h" #include <stdio.h> #include <string> #include <stdlib.h> #include <vector> using std::string; #include <iostream> #include <istream> #include <ostream> #include <iterator> #include <sstream> //vector<string> filenames; //filenames are stored in a vector string vector<string> readFileNames(char []); int getFileNamesWithoutExt(string[], vector<string> &); string getPreviousLine(istream &); /******************************************************************************/ /*** <readFileNames> ***/ /******************************************************************************/ // read file names into vector of strings vector<string> readFileNames(char *dir) { vector<string> filenames; DIR *dp; struct dirent *dirp; dp = opendir(dir); //read all directory and file names in current directory into filename vector while((dirp = readdir(dp)) != NULL) { filenames.push_back(string(dirp->d_name)); } closedir(dp); return filenames; } /******************************************************************************/ /*** <getFileNamesWithoutExt> ***/ /******************************************************************************/ // save filename strings to array from vector using an iterator int getFileNamesWithoutExt(vector<string> &textFiles, vector<string> filenames) { //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++) { vector<string> fileName; //filename[0] = filename, filename[1] = extension stringstream ss; ss << (*it); //parse the array based on a '.' delimeter, effectively getting the file name and extension string item; while (getline(ss, item, '.')) { fileName.push_back(item); } // if the fileName vector has two items (a name and an extension) and is a .txt file, then save it to the array if (fileName.size() == 2 && fileName[1].compare("txt") == 0) { textFiles.push_back(fileName[0]); n++; } } return n; //Return the number of txt files that were found in the directory } /******************************************************************************/ /*** <getNextLine> ***/ /******************************************************************************/ // void getNextLine(FILE *selectedFile, Line &lineData) { lineData.lineAddress = ftell(selectedFile); //char *newLine; //getline(selectedFile, newLine); char newLine[MAX_LINE_LENGTH]; fgets(newLine, MAX_LINE_LENGTH, selectedFile); string tempString(newLine); //lineData.fullLine = newLine; lineData.lineNumber++; stringstream newLineStrm(newLine); //string tempWord = strtok(cpyLine, " "); istream_iterator<string> it(newLineStrm); istream_iterator<string> end; vector<string> results(it, end); 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()); /* int numWords = 0; while (tempWord != NULL){ strcpy(lineData.word[numWords], tempWord); //Record the word in the lineData array numWords++; //add the number of words first, since we've already got one word, this helps for the way the while loop works too tempWord = strtok(NULL, " "); }*/ lcd.setAddress(0,1); lcd.printf("Current Line#: %d ", lineData.lineNumber); /* lcd.cls(); //clear the display lcd.setAddress(0,0); lcd.printf("wrd1: %s", lineData.word[0]); lcd.setAddress(0,1); lcd.printf("wrd2: %s", lineData.word[1]); lcd.setAddress(0,2); lcd.printf("wrd3: %s", lineData.word[2]); lcd.setAddress(0,3); lcd.printf("wrd4: %s", lineData.word[3]); wait(5);*/ } #endif