jonblack / arduino-menusystem

Arduino library for implementing a menu system
MIT License
194 stars 85 forks source link

Menu item reuse #71

Open pserotta opened 7 years ago

pserotta commented 7 years ago

Hello, First, I would like to thank you for the menu system it seems well thought out. But I have a few questions.

  1. In my use case I will be re-using menu items in multiple menus. I think this is possible but I am having some confusion. Here is an example, this is for a sprinkler controller if it helps.

The Menu would like like this:

Manual ---Valve 1 ------Set Minutes Program ---Valve 1 ------Set Minutes

Code snippet:

// Define menus and menu items Menu mu1("Manual"); Menu v1("Valve 1"); MenuItem setmin("Set Minutes",&on_setMinutes_selected); Menu mu2("Program"); Menu mu3("Valve Run Time");

// Build Menu ms.get_root_menu().add_menu(&mu1); // Add "Manual" to root menu mu1.add_menu(&v1); // Add "Valve 1" menu under "Manual" v1.add_item(&setmin); // Add "Set Minutes" under "Valve 1" ms.get_root_menu().add_menu(&mu2); // Add "Program" to root menu mu2.add_menu(&mu3); // Add "Valve Run Time" menu under "Program" mu3.add_menu(&v1); // Add "Valve 1" (and "Set Minutes") under "Valve Run Time"

My question is in the callback function on_setMinutes_selected, I need to know if the menu path started at "Program" or "Manual". Is there a way to keep track of the menu path taken to a given callback. It would be a bit wasteful if different MenuItems were needed for each endpoint callback.

  1. I see that support for NumericMenuItem but I am not understanding its purpose. Can you elaborate with a small sample?

Thank you!

jonblack commented 6 years ago

In your example I think they are two different menu items: one in the "manual" context and the other in the "program" context. If you really want code reuse, have two callback functions call a common setMinutes function.

As for actually reusing a menu item, this isn't possible I'm afraid. You could hack it by adding path information to the menu name, but I doubt you want that.

For NumericMenuItem check out the serial_nav example. In short, the NumericMenuItem is a concrete MenuItem that holds a numeric value that can be incremented or decremented.