I can read the SD data(or buffer data) to serial output and it looks like this:
243,123
244,123
243,122
etc....
I can convert this to a string in a buffer (saved up to 400000 bytes in buffer no problems) and it looks the same on serial. What I need to do read the SD or buffer one line at a time, parse the data with a 'comma' delimiter, and then create new SDx and SDy from the string using atoi or whatever is needed. The flow seems fairly straight forward......However, I can't figure out how to do this even after reading many C++ sites regarding same. On the SD or in the buffer, x is ALWAYS the first set of caracters and will always be 3 bytes, y is the second set of characters and can be 1 to 3 bytes.
Can anyone point me in right direction?
sample bit of code where I suspect I need to create the function to handle the line by line parsing and int conversion. It's a hodgepodge right now because I'm learning about this conversion...
Code: Select all
// read from the file until there's nothing else in it:
while (myFile.available()) {
//Serial.write(myFile.read());//shows up fine
buffer = myFile.readStringUntil('\n');//shows up fine
//buffer = myFile.readStringUntil(',');//shows up split into line by line x then y, and no comma and one space where the comma was
//this is where I need to parse and convert to
//int and recreate the x/y positions from SD or buffer
//do some action here with recreated x/y for EACH line parsed
/*
char myString[sizeof(myFile)];
int myInt = atoi(myString);
Serial.println(myInt);
Serial.println(buffer); //debugging
//int SDx;
//SDx = atoi(myFile.readStringUntil(','));
//SDx = buffer;
//Serial.print("SDx: "); //debugging
//Serial.println(SDx); //debugging
//Serial.println(buffer); //debugging
int SDx;
char buffer[sizeof(buffer)];
SDx = atoi(buffer);
Serial.print(SDx); //debugging
buffer = myFile.readStringUntil('\n');
int SDy;
SDy = atoi (buffer);
Serial.println(SDy); //debugging
// Serial.println(buffer); //debugging
char str[] = "- This, a sample string.";
char * pch;
//printf ("Splitting string \"%s\" into tokens:\n", str);
pch = strtok (str, " , ");
while (pch != NULL)
{
//printf ("%s\n", pch);
pch = strtok (NULL, " , ");
}
//zoom in or out with new SDx/SDy here
// if (((SDdx > MAP_X_MIN) && (SDdx < MAP_X_MAX)) && ((SDdy > MAP_Y_MIN) && (SDdy < MAP_Y_MAX))) {
// tft.drawPixel( SDdx, SDdy, ILI9341_WHITE);
*/
}