IoAbstraction EEPROM support can be integrated into your menu application, it can be used to load and store menu item values, authentication and also choice menu items that are using EEPROM storage. Menu Manager makes it very easy to save values to EEPROM between runs. Each menu item can optionally have a storage point in the EEPROM area (-1 / 0xffff means not stored). Any items that have a valid EEPROM address will be persisted upon calling the
save function on menuMgr, and similarly, will be read back by calling
void menuMgr.load(magicKey = 0xfade, firstRunCallback = NULL); void menuMgr.save(magicKey = 0xfade);
load() the menu item callbacks are NOT run, this leads to instability because
load is often called long before the application is fully initialised. We recommend your app should not rely on this behaviour. However, should you wish to run the callbacks, you do so manually once your application is fully loaded, and the examples show how to do this.
From version 2.2 onwards EEPROM support can be added to you project by the designer UI. To change the EEPROM type used by your project, open the code generator and choose the “Change EEPROM” button highlighted in the image below.
Once you click on the above button, the following dialog will appear, where you can configure the type of EEPROM required:
EEPROMclass that some boards support, you must call
setupMenu. This is generally the best option for ESP boards.
Wire.begin()which should be done before calling
Any EEPROM selected by this method will be registered with menuMgr automatically during the
It’s usually best to use the inbuilt support in TcMenu Designer as described above. However, you can also manually add the support too. In order to use any EEPROM functions, or to use EEPROM based choice menu items, you need to set up an EepromAbstraction and provide a pointer to
setEepromRef. For details of how to create an EepromAbstraction see AVR and Arduino EEPROM example and I2C AT24 EEPROM example.
// before making any call to load or save, or before using ChoiceMenuItems menuMgr.setEepromRef(eepromPtr);
Should you need to use EEPROM functions before initialisation, you can set the root menu item before initialise for this special case. In this case, should need to use the menuMgr load function, as you must either set the EEPROM reference yourself as above, or call the overload of the load function that takes a pointer to an EepromAbstraction.
A frequent question that is asked is ‘how should I call save to ensure that all menu item state is stored’. The best way to do this is to use a power loss detection circuit and call save in that call back. The second best is to have a timed function (maybe once every 10 minutes) along with a commit handler that detects changes. Never call save in the menu item callback, if using a rotary encoder that would break your EEPROM in days.