By dave | October 10, 2018

Manually creating a menu with TcMenu

In most cases, the Designer UI will generate menus for you, even creating and round tripping the boiler plate code and moving rendering classes and remote capability files into place. However, there may still be reasons to generate a menu manually. Also, if you just want to understand what’s going on under the hood, this guide is good for that too.

Before proceeding, I would recommend you try to create a couple through the Generator UI so that you understand the basics first. In addition ensure you’ve read through at least the starter guide, the main documentation and the types within this section.

Code structure on the Arduino

Firstly, as this is a menu library, you’ll need a menu structure to work with. Menu’s in this library are composed of MenuItems. There is a top level menu (root) and then submenus (menus items that can contain another menu). We compose together such items to make a full menu. I’d look in the embedded arduino tcMenu API documentation and start by looking at the MenuManager class and the documentation for file MenuItems.h.

At this point you should have a series of MenuItem’s composed together. Don’t forget that all Info items must be in PROGMEM on AVR and ESP. We can now put aside discussion around menu items and discuss rendering the menu.

Getting started

In most cases there will be a display and some kind of input on the embedded (Arduino) device. When we use the generator it allows you to pick a renderer from the plugins that the designer has available. However, when working manually, it’s best to start with one of the examples that uses the renderer that you want and build out from there. There’s an example that covers most types of input and output for tcMenu.

If you want to use the remote control capabilities, again start with one of the packaged examples that provides the functionality you want, and copy the files into your sketch directory.

Initialising the menu manager

We initialise the menu manager as shown below, where renderer is a pointer to a renderer, root is the very first menu item and then this is followed by the pin used for either switches or the rotary encoder. Remember that pinA of the encoder must be an interrupt capable pin. If you’re not using the designer, then the plugins for display and remote are available within the tcMenu code repo within the two plugin packages, or may be packaged with the embedded folder. Copy the required files into your sketch and make sure they are initialised.

menuMgr.initForEncoder(MenuRenderer* renderer, MenuItem* root, uint8_t encoderPinA, uint8_t encoderPinB, uint8_t encoderButton);
menuMgr.initForUpDownOk(MenuRenderer* renderer, MenuItem* root, uint8_t upPin, uint8_t downPin, uint8_t okPin);

A little about IoAbstraction

As this library uses the switch and task support of IoAbstraction, we need to make sure loop repeatedly calls to task manager as follows. Make sure there are no long running tasks in loop.

void loop() {
    taskManager.runLoop();
}

It’s also worth reading a little on IoAbstraction library.

And that should get you started. At this point you should be able to get a menu onto your device.

Back to tcMenu main page

Other pages within this category

comments powered by Disqus

We use cookies to analyse traffic and to personalise content. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Please see our privacy policy should you need more information or wish to adjust your settings.

Send a message
X

This message will be securely transmitted to Nutricherry LTD servers.