cancel
Showing results for 
Search instead for 
Did you mean: 

What's the best location for request read from EEPROM for init

nico23
Senior III

I would like to read some data from the EEPROM on initialization to use in the TouchGFX application.

I currently have an API that can request read/write operations from TouchGFX to the backend.

At the moment, I've implemented it in the Model.hpp

    void bind(ModelListener* listener)
    {
        modelListener = listener;

        if (!storageInitialized) {
            initializeFromStorage();
            storageInitialized = true;
        }
    }

with

void Model::initializeFromStorage()
{
    #ifndef SIMULATOR
    StorageResponse_t wr = Storage_Request(STORAGE_CMD_READ,
                                            EEPROM_ADDR_STRUCT_2,
                                            &struct2,
                                            sizeof(struct2));
    
    wr = Storage_Request(STORAGE_CMD_READ,
                            EEPROM_ADDR_STRUCT_1,
                            &struct1,
                            sizeof(struct1));
    #endif
}

but I'm not sure if it's the correct location.

I just want to send the read EEPROM command on the first load of TouchGFX and never again

1 ACCEPTED SOLUTION

Accepted Solutions
Osman SOYKURT
ST Employee

Hello @nico23 ,

Are you trying to read purely GUI-related data, such as variables to be stored in the model later? If so, using the bind method seems appropriate. However, if the data pertains to TouchGFX initialization—like determining which screen to start with—you may need to call initializeFromStorage() beforehand.

Osman SOYKURT
ST Software Developer | TouchGFX

View solution in original post

3 REPLIES 3
Osman SOYKURT
ST Employee

Hello @nico23 ,

Are you trying to read purely GUI-related data, such as variables to be stored in the model later? If so, using the bind method seems appropriate. However, if the data pertains to TouchGFX initialization—like determining which screen to start with—you may need to call initializeFromStorage() beforehand.

Osman SOYKURT
ST Software Developer | TouchGFX
nico23
Senior III

Hi @Osman SOYKURT 

Yes, they are data purely stored in the model and used only for the GUI to display (or not) certain things when moving to the various views.

Out of curiosity, what's the location in case I want to run initializeFromStorage() beforehand?

Thanks

Osman SOYKURT
ST Employee

Ok actually the example I took (determining which screen to start with) might not be the the best because you could also handle this in the model easily. I think everything that is related to your TouchGFX application can be handled inside of it. 

Osman SOYKURT
ST Software Developer | TouchGFX