I need help in converting data as simple and memory not-intensive as possible. So the data is in a string that looks like this:
4519.8081,01426.5819
4519.8081,01426.5818
4519.8082,01426.5815
4519.8083,01426.5812
I need to convert this from the string so I get two float arrays y and x. Array y should contain the values from the first column (columns are delimited with comma) Array x should contain the values from the second column.
This will be done on a microcontroller so I really need it as minimalistic as possible!
Update: I thought this was enough information just to get a function or pointers on how to do the function, my apologies.
The general objective is to log GPS data in order to get several coordinate points from which I can draw a traveled path. It will be roughly visualized on a 320x240 TFT screen. I use an ATmega32 MCU together with a GPS module, SD card reader and the mentioned screen of course.
To elaborate - I am logging GPS data in the mentioned format. The data gets written down to a txt file
4519.8081,01426.5819
4519.8081,01426.5818
4519.8082,01426.5815
4519.8083,01426.5812
Every line is one logged point with it's latitude and longitude. 4519.8081, 01426.5819 is actually 45°19.8081'. 14°26.5819'
After logging a certain number of points (haven't defined the exact number yet but it will be a limited number due to the memory constraints) to the SD card I have the data stored.
At this point I need to convert the data I have into two arrays which will serve as coordinates for plotting these points on the display and plotting a path between them.
So if I have an array X[n] and array Y[n] with the coordinates, I do something like this:
for (int i=0; i<n-1; i++){
display.drawLine(x[i], y[i], x[i+1], y[i+1])
}
This will loop through the arrays and plot the path from the coordinates.
Now, I understand that the coordinates have to be in the 320x240 range since that is the resolution of my display. That is why I can't just pass the float numbers as they are (if I can even get them!!) but I need to do some calculations on the arrays first.
But all in all, for starters, I just need to get the values from the string into float arrays, e.g.
x[] = {4519.8081, 4519.8081, 4519.8082, 4519.8083}
y[] = {1426.5819, 1426.5818, 1426.5815, 1426.5812}
If there is a better way to accomplish what I need, feel free to comment.
I hope that is enough information for my question to get unblocked. Thanks in advance!
floatdoes not have enough significance to distinguish4519.8081from4519.8082. And generally, floating point is not minimalist.fgets()., start by reading lines of input with that.