Well, there's a little good news... while the PACK.CFG file reader is not functioning properly, my LED.CFG file is being read properly now. Here is the code for that:
// LED config scan function.
// index, scale, speed
int scanLED(char* line, int& i, float& f1, float& f2) {
char result_i[7];
char result_f1[10];
char result_f2[10];
if (sscanf(line, " %6s %9s %9s", result_i, result_f1, result_f2) == 3) {
i = atoi(result_i);
f1 = atof(result_f1);
f2 = atof(result_f2);
return 3;
}
}
void readLEDConfig() {
char line[256]; // Next line of text in file.
int index = 1, lastIndex;
float scale = 1.0, lastScale;
float speed = -1.0, lastSpeed;
if (!file.open(root, "LED.CFG")) { Serial1.println(F("Failed to open LED.CFG!")); halt(7); } // Error if file does not exist.
while (file.fgets(line, sizeof(line))) { // Read lines from the file until we hit the end.
if (line[0] == '#') continue; // Check first character on line. If comment, skip to next line.
// Store last set of values read from the file before reading new ones:
lastIndex = index;
lastScale = scale;
lastSpeed = speed;
if (scanLED(line, index, scale, speed) == 3) { // Scan line. If all parameters accounted for, store them, then execute code below.
// Loop through all LEDs up to this point and fill them with previously read values. Do not update the LED we just read parameters for yet.
for (int i = lastIndex; i < index; i++) { // Loop through and set all LEDs up to, but not including, the one we just read from the file.
led::setscale(i, lastScale);
led::speed[i-1] = lastSpeed; // LEDs are 1-indexed but LED arrays are 0-indexed so we subtract 1 here.
}
} else {
// Line may be blank, or contain a few whiespace characters. Or it may be improperly formatted.
//Serial1.println(F("Improperly formatted line in LED.CFG!"));
//halt(7);
}
}
for (int i = lastIndex; i <= leds; i++) { // Loop through remaining LEDs and set their values, starting from last one read.
led::setscale(i, scale);
led::speed[i-1] = speed;
}
// No need to bother closing file if we're not writing to it.
}
This tells me fgets is working. So the issue must be something else.