Skip to main content

Setting Initialization

Loading...

As you already know, settings are stored in the EEPROM. They are used to keep the operating parameters of your application. Settings retain their values even if your device is powered down or rebooted. Thus, there is no such thing as routinely initializing the settings at boot -- something that always happens to regular variables.

So, when do settings get initialized (restored to their defaults)? Ordinarily, this happens only when the user chooses to do so.

There are several methods of initializing settings. One way is to use the Initialize Settings button on the web interface page.

settingsinit_web

Another way is to offer your users a "button-based" way to cause a setting init. This application shows how the TPS' MD button could be used to trigger the setting init safely. "Safe" here means that the procedure is intricate enough that it is unlikely to happen by accident.

Your TPS' MD button was introduced in the Hello, World project.

Here is how the initialization process is triggered:

  • Press and hold the MD button for at least five seconds. The green status LED will be on during this time.
  • Once the 5-second interval elapses, both green and red status LEDs turn on, and the Initialize Settings block is executed.
  • After the initialization, the green status LED starts blinking fast.
  • Releases the MD button -- the On Button Released event block is called. If the setting init has already happened, the Reboot block will execute.
  • If you release the MD button before the 5-second interval expires, the process is aborted and has to be restarted.

Apart from demonstrating a suitable setting initialization sequence, this project also showcases the use of (one-shot) timers, On Button Pressed and On Button Released events, device rebooting with the Reboot block, as well as various LED patterns.

There is a condition when the settings are initialized automatically. It happens after the so-called "schema change." A schema change occurs when you run an application on a device, then edit the list and properties of settings, and upload the application to run again. At this point, the layout of data stored in the EEPROM may not match the updated "setting schema." After the schema change, your application will check the validity of each setting at boot. Any settings found to be invalid will be initialized to their default factory values. Valid settings will be left untouched.