[New Feature] store calibration values
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: store calibration values
The idea is to create an abstract interface for file system, Mabl's wrapper could (and probably will if Mabl agrees) be used as part of the implementation.
Giovanni
Giovanni
Re: store calibration values
Giovanni wrote:The idea is to create an abstract interface for file system, Mabl's wrapper could (and probably will if Mabl agrees) be used as part of the implementation.
Sure, feel free to use the code.
In my own projects I use an abstraction based on minini ( http://code.google.com/p/minini/ ) - works great.
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: store calibration values
This minini is exactly what is needed IMO. I will proceed with the FS abstraction layer then we will discuss about implementations and upper layers.
Giovanni
Giovanni
Re: [New Feature] store calibration values
At this point, I'd like to publisha few lines of code, how I store the calibration struct on an SD card. The code is pretty basic and not that professional. It simply creates a new file «calibration» and stores the 16 bytes of the struct in it.
~ Tectu
Code: Select all
void lld_tpWriteCalibration(struct cal cal) {
FRESULT ferr;
FIL fi;
UINT wr;
ferr = f_open(&fi, "calibration", FA_CREATE_ALWAYS | FA_WRITE);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpWriteCalibration(): could't open file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
return;
#endif
}
ferr = f_write(&fi, &cal, sizeof(struct cal), &wr);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpWriteCalibration(): could't write file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
return;
#endif
}
ferr = f_close(&fi);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpWriteCalibration(): could't close file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
return;
#endif
}
}
struct cal lld_tpReadCalibration(void) {
FRESULT ferr;
FIL fi;
UINT br;
uint8_t i;
struct cal cal = { 1, 1, 0, 0 };
ferr = f_open(&fi, "calibration", FA_READ);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpReadCalibration(): couldn't open file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
#endif
return cal;
}
ferr = f_read(&fi, &cal, sizeof(struct cal), &br);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpReadCalibration(): couldn't read file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
#endif
return cal;
}
ferr = f_close(&fi);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpReadCalibration(): couldn't close file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
#endif
return cal;
}
#if DEBUG
if(cal.xm != 1 && cal.ym != 1 && cal.xn != 0 && cal.yn != 0) // check if default or different values
chprintf(DEBUG_SERIAL, "calibration restored from SD card\r\n");
#endif
return cal;
}
~ Tectu
Re: [New Feature] store calibration values
I could finally implement the first version of a usable storage interface, without using streams yet: http://chibios-gfx.com/documentation/to ... alibration
~ Tectu
~ Tectu
Re: [New Feature] store calibration values
I'm interested in some static storage too, i would use the EEMUL approach but abstracting the storage media would for sure the best option.
About Tectu code: shouldn't you free the allocated memory and return NULL instead of doing cal = NULL and returning cal? (BTW I would definitively allocate the memory outside that function and pass the pointer)
About Tectu code: shouldn't you free the allocated memory and return NULL instead of doing cal = NULL and returning cal? (BTW I would definitively allocate the memory outside that function and pass the pointer)
Re: [New Feature] store calibration values
Hello tinito,
Please note that the storage calibration interface has changed. THe new one is working with pointers
Her you can find the new one: http://chibios-gfx.com/documentation/touchpad/calibration
~ Tectu
Please note that the storage calibration interface has changed. THe new one is working with pointers
Her you can find the new one: http://chibios-gfx.com/documentation/touchpad/calibration
~ Tectu
Re: [New Feature] store calibration values
Hi Tectu,
I was looking to the same version, and I think this code
should be something like
and the same for every error condition, to free the unused memory.
I was looking to the same version, and I think this code
Code: Select all
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
ferr = wf_open(&fi, "calib", FA_READ);
if(ferr != FR_OK) {
cal = NULL;
return cal;
}
should be something like
Code: Select all
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
ferr = wf_open(&fi, "calib", FA_READ);
if(ferr != FR_OK) {
chHeapFree(cal);
return NULL;
}
and the same for every error condition, to free the unused memory.