pulls data from SD and parses 1 line
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed
main.cpp
- Committer:
- nlougen33
- Date:
- 2016-11-10
- Revision:
- 0:956fa5e51717
File content as of revision 0:956fa5e51717:
//SD Import from scratch #include "mbed.h" #include "SDFileSystem.h" #include "uLCD_4DGL.h" uLCD_4DGL uLCD(p28,p27,p29); SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board const int MAX_CHARS_PER_LINE = 17; const int MAX_TOKENS_PER_LINE = 4; const char* const DELIMITER = " "; int main() { // file reading object FILE *fp = fopen("/sd/mydir/sdtest.txt", "r"); char mytext[15]; // fread(mytext, 15, 1, fp); // uLCD.printf("%s", mytext); char buf[MAX_CHARS_PER_LINE]; // read each line of file //while (!feof(fp)) // while not end of file while (fgets(buf, sizeof(buf), fp)) { // read an entire line into memory //fgets(buf,MAX_CHARS_PER_LINE,fp); //need to check this out //parse line into blank-delimited tokens int n=0; // for-loop index // array to store memory addresses of the tokens in buf const char* token[MAX_TOKENS_PER_LINE] = {}; // initialize to 0 char * pch; //printf ("Splitting string \"%s\" into tokens:\n",str); uLCD.printf("original buf: %s\n", buf); pch = strtok (buf," "); while (pch != NULL) { uLCD.printf("%s\n",pch); pch = strtok (NULL, " "); } // parse line /* token[0]=strtok(buf,DELIMITER); //reminder token { for (n = 1; n < MAX_TOKENS_PER_LINE; n++) { token[n] = strtok(, DELIMITER); // subsequent tokens if (!token[n]) break; // no more tokens } }*/ // process the tokens /* for (int i = 0; i < n; i++) // n = #of tokens uLCD.printf("%s",token[i]); */ fclose(fp); } } // memcpy( hour, &arr_time[0], 2 ); // memcpy( min, &arr_time[3], 2 ); // arrival_hour = atoi(hour); // arrival_min = atoi(min); //uLCD.printf("\narrival hour is %d\n",arrival_hour); //uLCD.printf("arrival min is %d\n",arrival_min); //ready_time = atoi(r_time); //uLCD.printf("\nString ready time is %s",r_time); // uLCD.printf("Ready Time is %d\n",ready_time); //uLCD.printf("start address is %s\n", start_add); //uLCD.printf("dest address is %s\n", dest_add);