Using classes for LCD keypad menu.

PaulS:

What you say makes no sense.

At the top of the IDE is a menu. It has several items in the menu - File, Edit, Sketch, Tools, and Help. That looks like a list to me.

A node (an instance of a struct) could have a name (“File”, “Edit”, etc.) and a list of nodes that are the sub-menu items.

The node whose name is “File” would contain a pointer to the node whose name is “Edit”, which would contain a pointer to the node whose name is "Sketch.

The node whose name is “File” would ALSO contain a pointer to a node whose name is “New”. The “New” node would point to the “Open” node AND to NULL (since New has no child menu).

That’s why I keep harping on linked lists. But, you keep rejecting that idea. I don’t know what else to say.

Isnt that what I did? EC_PH points to PH but it “also” points to EC, and PH points to setmin and setmax. What is the disdvantage of using an array to store the pointers?

A menu for setting the time and date would need 6 pointers for example. Since the LCD is 2x16, the navigation I explained would let each member have a 2 dimensional index array[2][max] so pressing the down button on the third item will move you from array[0][2] to array[1][2], from the minutes to the year for example:

6:5>8< to 6:5:8
11/2/14 11/2>14<

Selection isnt a linear left/right since it seems to make logical sense when laying out the nagivation to make use of the screen instead of a linear menu bar/dropdown menu. But I see now how you can have submenu’s linearly with your anology.

I have looked at some examples and some of them used templates (thats why I thought I needed them). Wikipedia referred to binary trees which sounds more like what you are describing.

It seems to me though that either way though, each “item” needs a pointer to it whether it be linearly or not. What is the disadvantage to grouping the pointers together in one member?

A menu for setting the time and date would need 6 pointers for example.

No. There might be a menu item "Set date" with a child item of "Set time".

"Set date" would have a sub-menu of "Set month", "Set day", and "Set year". None of them have sub-menus. "Set time" would have a sub-menu of "Set hour", "Set minutes" and "Set seconds". None of them have sub-menus.

If you want, each item could have a lower limit and an upper limit. Each item could have a function pointer, pointing to a function that was to be called when the enter key was pressed to complete defining the value. That function would take three values - the lower limit, the upper limit, and the entered value, and return a bool (value accepted or value rejected).

I think you are far better off using the entire LCD for the menu than in trying to restrict where to diddle with the display as part of the menu structure. Make that V2.

What is the disadvantage to grouping the pointers together in one member?

None. But, trying to include a variable sized array of pointers in each node is a recipe for disaster.

I have a new question, I want the top layer of my menu to cycle through its contents, lets say it only has two items EC_PH and AIR_CO2. If I do this:

menu *current_menu=&EC_PH;

void setup(){
  EC_PH.previous_menu=&AIR_CO2;
  AIR_CO2.previous_menu=&EC_PH;
}

void loop(){
  current_menu=&(current_menu->(*previous_menu));
delay(1000);
}

What is the correct syntax for current_menu=&(current_menu->(*previous_menu)); ? I'm trying to set the current_menu, to the previous_menu contained by the menu member pointed to by current_menu.

I'm trying to set the current_menu, to the previous_menu contained by the menu member pointed to by current_menu.

Perhaps they could help you at http://snippets-r-us.com.

How exactly is that supposed to help? What a useless website provides only recycled anal-admin information and nothing useful at all. I thought at least it actually had some code snippets, but now I see it is ment as an insult.

By the way, I have followed the insulting guidelines all over your page so why are you directing me to it? Why would I bother posting my whole code, when it is not my whole code I have a problem with? Im sorry that while intelligent, you obviously lack the basic logic skills to determine that previous_menu, like the mentioned and initialised current_menu, is a pointer to a member of the menu class, which I have posted all over this thread.

Now ill ask my perfectly valid question AGAIN.

menu *current_menu=&EC_PH;

void setup(){
  EC_PH.previous_menu=&AIR_CO2;
  AIR_CO2.previous_menu=&EC_PH;
}

void loop(){
  current_menu=&(current_menu->(*previous_menu));
delay(1000);
}

What is wrong with the pointer: current_menu=&(current_menu->(*previous_menu));

I'm done with this thread. Good luck.