By dave | November 10, 2020

There are two core types of MenuItem in tcMenu that all the other items extend from. Firstly, there’s the type that directly extend the MenuItem class, they always have a reference to an AnyMenuInfo block that’s stored in program memory on devices that support it. Secondly, there’s RuntimeMenuItem documented here which don’t follow these conventions.

Items that directly extend MenuItem always reference a data block that extends from AnyMenuInfo, at an absolute minimum the core fields defined in this structure must always be provided. For storage there are two options, either store in const/FLASH, on boards that support PROGMEM this will be program memory. Otherwise they can be stored in RAM. Below we provide the definition this structure.

struct AnyMenuInfo {
    /** the name given to this menu item */ 
    char name[NAME_SIZE_T];
    /** the identifier for this menu */
    uint16_t id;
    /** eeprom address for this item or -1 if not stored */
    uint16_t eepromAddr;
    /** maximum value that this type can store */
    uint16_t maxValue;
    /** the callback function */
    MenuCallbackFn callback;

We can see that the ID, Name, EEPROM location, maximum value and callback function are all members of the structure. When you call the methods to get items on MenuItem it accesses the members of this structure. Even if the structure is in RAM, never change the ID or EEPROM address after adding the menu item to menu manager.

So after reading the above, we know that we represent items with an subclass of MenuItem, and it will contain an Info structure. This is so that some of the read only information can be stored in PROGMEM. All Info structures and their strings must be in PROGMEM on AVR and ESP. MenuItems reside in RAM as they contain state that can change. The designer does this for you automatically. There’s also items based upon RuntimeMenuItem, these work slightly differently, as described below, but again are memory efficient.

Other pages within this category

comments powered by Disqus

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.

Send a message

Please use the forum for help with UI & libraries.

This message will be securely transmitted to our servers.