1

Topic: Save app data

Hi,
I believe it would be great if the app could optionally save the state of input elements, especially edit fields between sessions.

2

Re: Save app data

The board saves the state of input elements. When reconnecting, the state of the input elements is transmitted to the phone from board. If your board has been reset, you can save the states to non-volatile memory and then restore.

3

Re: Save app data

mic wrote:

Hi,
I believe it would be great if the app could optionally save the state of input elements, especially edit fields between sessions.

Generally, you will be needing to use real, or simulated EEPROM.

The EEPROM library contains all that you will need.

I always put data that I want stored between sessions into a user-defined structure, it makes life really simple ...

// Create the EEPROM data structure
struct udt_eeData {
int16_t   runaway_time;     // seconds
int16_t   gassing_time;     // seconds
uint8_t   id;               // this is last to catch structure changes
};

then you have to create an "instance" data of that declared structure ...

//Create the EEPROM data of type udt_eeData
udt_eeData eeData;

Read your data using EEPROM.get(eeData) reads the whole of the data you declared.

In the example above, the saved "gassing_time" is addressed as "eeData.gassing time".

I use the "id" member of the user-defined structure to detect structure changes, or i can force a change in my code by changing it before compilation, sort of like a "build" number. Use it to assert "default" values.

  // initialise eeData if NOT already present
  // THIS SHOULD ONLY OCCUR IF BUILD has changed !!
  if (eeData.id != build_no) 
    {
    eeData.runaway_time = 30;
    eeData.gassing_time = 3;  
    eeData.id = build_no;
    EEPROM.put(eeAddress, eeData);
    EEPROM.commit(); // only needed for virtual EEPROM
    }

Write data to the EEPROM using EEPROM.put(eeData).  This function only writes to the EEPROM any bytes that have changed, prolonging the EEPROM write-cycle lifetime.

Any questions ? Please ask... I've used this technique on several projects, with huge success .....

2B, or not 2B, that is the pencil ...