Hello,
I am quite new to programing, especialy in C and C++. I am struggling to find solution to next problem. I am building system that measures force in my home project. Every measurement is stored to SD card that can be than transfered to computer for later use. System is normally powered by wall power, but in case of power loss I have to recover the data so the system can proceed from last point. Battery is not an option.
I have build struct that stores 2 values at the moment (it will have more in the future). I would like to read lasn N measurements/lines and store those measurements in separate array of the file so I can use last N measurements for moving average. Data is stored as binary. I know I could build array variable in to the struct but I feel that is waste of space and resources.
Can someone help me out?
That is my struct:
struct springDataStruct
{
int32_t cycles;
int32_t measurement;
}springData;
That is how I am able to read last line of the file and store it to struct.
void readSpringDataFile()
{
springDataFile = SD.open(springDataFileName, FILE_READ);
springDataFile.seek(springDataFile.size() - sizeof(springDataStruct));
springDataFile.read((uint8_t *)&springData, sizeof(springData));
springDataFile.close();
}
I could loop over last N lines with that but opening and closing file is a waste of time and I think that there is a better option out there.