Go Down

Topic: Menu on LCD: strings, multi-dimensional arrays? (Read 1 time) previous topic - next topic

willis

Sep 01, 2010, 05:43 am Last Edit: Sep 01, 2010, 05:44 am by willis Reason: 1
Hey guys.  I've searched around a bit before posting, but I wasn't sure what to look for, so forgive me if this has been answered.

What I'm looking to accomplish is the following:

Have a series of user-navigable menus drawn using the liquidCrystal library.

I've come up with some pseudo-code for what I want to do, but it's long enough that I'll just try and summarize what I have in mind.

I'd like to have:

  • an int corresponding to which "menu" the user is in.
  • an int corresponding to the selected "item" in that menu
  • a bool corresponding to whether they are "editing" that item's "value"
  • an array of names of "menu"s to be written to the screen for the user (id corresponds to the menu int.)
  • an array of names of "items" in each menu (again the id's would match my "selected item" int)
  • an array of values for each "item" in each "menu"  


I'd ideally build in such a way that when I'm drawing the menu I can just use these variables plugged into the same function no matter what the menu structure looks like.  This way, if I need to add items to the menu later it's no big deal -- I just adjust the lengths of the arrays and that's it.

So here are the questions I have:

  • what's the best way to structure this?  I'm thinking of a 2- or 3-dimensional array, but this starts to get complex when I try and think about how to link the values of items to their names.  Another thought was to create a new class that handles all of this data stuff, but I don't know C well enough to know if that's a good approach.
  • what's the best way to handle the large number of strings I'll be needing to keep track of?  If it makes it any easier, I know they'll all be less than a certain length, and can pad them out to be all the same length with whitespace.
  • The values of the menu items will be in a variety of formats, including some which are a list of text-based options that correspond to numeric values.  (one example being the string "1/8000" which would represent the int 125)
  • Is there a better way to be doing this?  I don't have any *real* formal training in CS, so I'm sure there are better ways to do this.



InvalidApple

(In my opinion) I think that "Linked Lists" are a good way of doing menus.

There is a section for this in the book "C: The Complete Reference" (great book)

I found something for you to look at http://cslibrary.stanford.edu/103/LinkedListBasics.pdf.  Basically, you use a "next"/"previous" approach, and I have found it to be a successful way to use XML data.  The trick is that you add another pointer called "parent"; you go through the list and print every element with that parent.

There is also a library out there somewhere if you keep digging around.

If you have lots of strings, it is best to look into PROGMEM

PaulS


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy