[New Feature] store calibration values

User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

[New Feature] store calibration values

Post by Tectu »

Morning Folks,

I made a quick implementation which allows to store the touchpad calibration data when calling tpCalibrate(). This way, you don't need to do tpCalibrate() after each reset.
The interface is similar to the GPIO abstraction for the LCD module itself. The user can decide where and how he wants to store the data. Someone may want to use an external I²C EEprom, another wants to use the SD card, maybe another uses the MCU's internal storage.

When you want to store the calibration data, you have to add #define TOUCHPAD_STORE_CALIBRATION TRUE in your halconf.h and then provide these two functions somewhere in your project (for example in main.c):

Code: Select all

void lld_tpWriteCalibration(struct cal cal) {

}

struct cal lld_tpReadCalibration(void) {

}


What you do in these two functions is up to you. You just have to make sure that you return the same struct which you receive. If you like, you can store two values on your EEprom and two on your SD card, just reassemble it the right way ;-)

This is the calibration struct:

Code: Select all

struct cal {
    float xm;
    float ym;
    float xn;
    float yn;
};



I couldn't test it yet. I would be thankful if someone could try this out and write a small review.

I am open for any critism or improvements.


~ Tectu
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: store calibration values

Post by Badger »

Nice idea, I will try when I get some time. We should provide an implementation for a BaseBlockDevice, that abstracts MMC over spi, SDC and other block devices. (I use this in the mass storage driver)
User avatar
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

Post by Giovanni »

We could also think to some kind of "persistent storage" abstraction, it could then be implemented over EEPROM, backup RAM, Flash etc.
It would also be a chance to use that Files Interface :)

Giovanni
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: store calibration values

Post by Abhishek »

I agree with you Giovanni on this point. Something like a Hash Table which can be used to access data via key / value pair would be a better option than just serializing the calibration values.

Maybe something like:

In the main function:
loadSettings(&EEPROM1); or loadSettings(&SDCARD1("chibi.cfg"));

It would cache all the settings in memory, to speed up things.

The program would then write:

writePropertyFloat("X1", value);

and later on:

xcal=readPropertyFloat("X1");

Is it good for a start?

Best Regards
User avatar
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

Post by Giovanni »

So you want the Windows Registry :)

I would create two layers, this "persistent storage" that handles persistent files, and this registry-like component that would retrieve/store key/value pairs using the persistent storage.

Giovanni
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: store calibration values

Post by Abhishek »

This registry would really be a cool add-on to the RTOS project. How do we go about doing it?

I guess starting with a 24C64 external EEPROM for the persistent storage would be a good option. Though I have seen minINI being ported to FatFS and STM32 systems.

Best Regards
Abhishek
User avatar
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

Post by Giovanni »

I will define the interface of the persistent storage (an abstract file system basically) and will create a FatFS wrapper, then we will discuss about this registry. Cannot promise times, I am very busy of late.

Giovanni
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: store calibration values

Post by mobyfab »

Why not SQlite then?
It could be use for a lots of things, like if you want to plot some data without storing it in the memory.

We would need to port it first of course.
http://www.sqlite.org/custombuild.html
Last edited by mobyfab on Wed Sep 26, 2012 10:28 am, edited 1 time in total.
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: store calibration values

Post by Tectu »

Not sure why we need a new FatFS wrapper? Do you want something completley different than mabl's wrapper, or are you just going to implement it into the RTOS?


~ Tectu
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: store calibration values

Post by Abhishek »

@ Mobyfab, Nice idea, however I am not sure about the implications.

How much memory space (heap) would it require?

BTW, just found this: https://github.com/mabl/mininiChibios. Looks good.

EDIT: @Tectu, the wrapper is actually a connector for the registry architecture proposed.
Locked