I need to store a struct in a file and read it back to return it then.
I would try to write it to the file like this:
void lld_tpWriteCalibration(struct cal cal) {
FIL fdst; /* file objects */
UINT bw; /* File write count */
/* Create destination file on the drive 0 */
wf_open(&fdst, "0:calibration.txt", FA_CREATE_ALWAYS | FA_WRITE);
wf_write(&fdst, cal, sizeof(cal), &bw);
wf_close(&fdst);
}
Would that work?
And how can I read it back and return it from this function?
struct cal lld_tpReadCalibration(void) {
}
The struct is:
struct cal {
float xm;
float ym;
float xn;
float yn;
};
Thanks for your help.
You can retrieve your structure the same way you stored it.
But you got to be careful, you won’t be able to do this on every architecture because of endianess problem.