Alright, so I am having some trouble parsing data on an SD card (shocker). So the idea is that you access the a config file on an SD card and assign a few values, then add items in the body of the file to a 2D array. I can handle the 2D array and assigning values (at least I think), but I am having trouble getting past the first field in my config file. By the way, the 2D array is composed of buffers of 12 elements (ie byte example[20][12]). I know using 12 is a pain, but I have to for the given application. The buffers are shifted out to an external IC for translation. So here is my code:
#include <SD.h>
int chipSelect = 10;
int counter = 0; // Used for count the number of iterations
int currPosition = 0; // Used for keeping track of the current position (the 0 value wont be used)
boolean ignoreFlag = true; // true if you are supposed to ignore
void setup()
{
Serial.begin(9600);
pinMode(10, OUTPUT);
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.print("failed!"); // If there is an issue, tell us and quit
return;
}
Serial.print("card initialized"); // You will only be here on success
Serial.println();
// Dump the file
File comboFile = SD.open("egFile.txt"); // Open the combo file
if (comboFile) { // If the file is availble
while (comboFile.available()) {
if (comboFile.peek() == ':') { // If entering a zone
ignoreFlag = !ignoreFlag;
if (ignoreFlag) currPosition++; // When it switches to high
comboFile.read();
}
// If not in an ignore zone write the stuff
else if (!ignoreFlag) Serial.write(comboFile.read();
}
comboFile.close(); // Close the file
}
// If the file isnt open produce an error
else Serial.println("There was an error openeing the file");
}
void loop()
{
}
And here is the file it will be reading:
:field1: // This is a comment you can throw in
:field2:
// So is this
:field3:
:meter:
:101010101010,
101010101010,
101010101010,
101010101010,
101010101010
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,
101010101010,:
So ideally, the output would be
Initializing bla bla bla
field1
field2
and so on
Instead I get:
Initializing bla bla bla
field1
And thats it. So to investigate, I added a counter to the while (comboFile.available()) loop. To my surprise, this actually seems to be an infinite loop. I don't know if this is entirely unrelated, but I figured I would give you a heads up on what I have tried.
Thanks for your time, even if it is just to laugh at some egregious error =)