Saving Application Settings to Flash

I just added a new entry to the Code section that demonstrates a base class that saves and restores application settings to and from Flash memory.


FlashSettings is an abstract base class that provides methods for saving and loading application settings to and from flash memory. The class is defined in such a way the it allows multiple levels of derived classes to save and restore their settings in a safe and consistent manor. Each derived class may override these methods:

InitSettings - to set initial values for their settings when the constructor is called.
GetSettings - to retrieve the “serialized” values for their settings.
SetSettings - to set their settings from “serialized” values.
ValidateSettings - to validate their own settings before they are saved to flash memory.

The example project includes these two derived classes:

AppSettings : DeviceSettings
DeviceSettings : FlashSettings

The example attempts to load settings from flash, which will fail the first time it is run.
It then tries to save invalid Device settings, invalid App settings, and then valid Device and App settings to demonstrate how validation works.

Hanks for sharing. I may use that myself :slight_smile:

Good job, this will come in handy for sure ;D

I just made a small change to the code to move the “serialization” from the GetSettings method to the SaveToFlash method, which will allow different methods of serialization in the future without changing all derived classes.

Thank you very much! :stuck_out_tongue: