Design pattern resources on creating a text-based menu library!!

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello all,

 

I am looking to create a custom text based menu library for a 2 line LCD. I am trying to find resources that discuss design patterns for a menu library. I was wondering if anyone on the forum can point me in the right direction? Appvalley

 

I did find examples of a menu library called MicroMenu and MD_Menu. I also found a book called Design Patterns for Embedded C by Bruce Douglass. However, I wanted to check with the community if they have any good resources on design patterns for text based menu libraries. Tweakbox https://vlc.onl/

 

Thank you

Last Edited: Mon. Nov 4, 2019 - 02:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you remember the Atmel AVR Butterfly ?

 

It seems the Butterfly is still available and the complete source code is also available for download. It includes a comprehensive menu system using a table driven state machine. It's a fairly well written example of this design pattern and is well worth studying.

 

https://www.microchip.com/DevelopmentTools/ProductDetails/ATAVRBFLY

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A normal 2 lines LCD can only have 8 custom characters.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wrote a menu system that uses strings & it worked out great people all around me started writing menus, even my boss who did no programming... the strings themselves completely form the menus...no programming needed, other than coding any actions in action states  (axx).  This is fairly memory efficient---good for small micros.

 

example:

 

"s03n05r27EATING A /HOT DOG/APPLE/COOKIE\ FOR LUNCH="        MENU STATE 3, NEXT MENU WILL BE 5, Current setting is RECALLED & DISPLAYED & UPDATED IN CONFIG recall REGISTER 27   

"s05PAYING BY /PAYPALa47/CASHb40a48/BITCOINa49\ FOR MY LUNCH="                   MENU 5, three DIFFERENT  POSSIBLE ACTIONS TAKEN, depending upon selection made... word CASH will bllnk at rate 4.0 times/second  (b40)

 

"s07n12r21SET PORT TO /300/1200/2400/9600/ABORTkn10\ BAUD="     menu 7, next menu will be 12, except abort will be menu 10, the current setting will be shown & updated in config register 21, aborting  will keep (k)  the current setting  

 

"s13n27PLEASE WEAR A /SUIT/SWEATER/MASK\ AND /TIE/JEANSn28/TAKE AN AXE\ TO THE MEETING="

     

     choices are:  PLEASE WEAR A SUIT AND TIE TO THE MEETING

                        PLEASE WEAR A SWEATER AND JEANS TO THE MEETING     ...IF JEANS SELECTED WILL GO TO A DIFFERENT MENU 28

                        PLEASE WEAR A MASK AND TAKE AN AXE TO THE MEETING 

 

"s34n35w10a50JEANS MUST BE GREEN="         MENU 34 alternates back & forth between messages (s34 & s35) (waiting 1.0 sec & 1.5 sec each) until button is pushed, then goes to action  state 50 (a50)

"s35n34w15a50TO BE ALLOWED IN !!="

  

"s12n18r15kAUNT /LAURA/BERTHAb15/MONICA/ROBIN/CONNIE\ IS LOOKING FOR YOUR r16k/TAXES/MONEYb20/KEYS/SHOES/PHONEb20\ RIGHT NOW!="    USES TWO SETTINGS (r15, r16) TO FORM MESSAGE.  Keep current option "k" in both main fields (not selections fields) means no updates will be recorded...this is display only (no selections)    BERTHA, MONEY, and PHONE will blink  

 

     if recall setting bank r15 is 3 & r16 is 2, will show: AUNT MONICA IS LOOKING FOR YOUR MONEY RIGHT NOW!

       note r15 & r16 do NOT mean AVR registers r15 & r16, "r" means recall option register

 

This gives the general idea....I've left many details out & it has been a few years...you can use your imagination. 

 

PS.

Oh, I forgot...there is also the "c"  option to clear the current display, otherwise the new stuff is appended to what is already on-screen.  So some more complex choices & messages can be built up in parts.

There were also some options to control placement:  l=line= 1 or 2    p=1-32 to set position (default start at column 1)  there was an hxx (h30) to temporarily hold a message on-screen as well.

there was wxx=wait, txx=timer, bxx=button  I probably need to dig out my list!

 

 

  

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Mon. Nov 4, 2019 - 12:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

A normal 2 lines LCD can only have 8 custom characters.

 Different ones shown at one time....the 8 customs chars can be redefined on the fly, as needed 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sun. Nov 3, 2019 - 07:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

redefined on the fly

How do you keep the fly still long enough to redefine it? cheeky

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

All this talk about the 8 user-defined characters got me thinking WTF. Until I relaised some have read the question differently to myself.

 

Using parentheses to indicate the adjective-noun association, some have read the question as:

I am looking to create a (custom text) based menu library for a 2 line LCD

 

Whereas I read it as:

I am looking to create a custom (text based menu) library for a 2 line LCD

 

Then again; the word "custom" is probably irellevant here, because aren't all menus custom ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This discussion has nothing to do with creating custom characters

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I presume the "MicroMenu" you refer to in #1 is Dean Camera's one? That is:

 

https://github.com/abcminiuser/micromenu-v2/blob/master/example/Example.c

 

?

 

As you can see the definition of the menu items in this becomes as simple as:

MENU_ITEM(Menu_1, Menu_2, Menu_3, NULL_MENU, Menu_1_1 , Level1Item1_Select, Level1Item1_Enter, "1");
MENU_ITEM(Menu_2, Menu_3, Menu_1, NULL_MENU, NULL_MENU, NULL              , NULL             , "2");
MENU_ITEM(Menu_3, Menu_1, Menu_2, NULL_MENU, NULL_MENU, NULL              , NULL             , "3");

But this was written for Atmel Butterfly which has a four direction "joystick" which is read as up/down/left/right buttons so the core of his main() in the example looks like:

		/* Example usage of MicroMenu - here you can create your custom menu navigation system; you may wish to perform
		 * other tasks while detecting key presses, enter sleep mode while waiting for user input, etc.
		 */
		switch (GetButtonPress())
		{
			case BUTTON_UP:
				Menu_Navigate(MENU_PREVIOUS);
				break;
			case BUTTON_DOWN:
				Menu_Navigate(MENU_NEXT);
				break;
			case BUTTON_LEFT:
				Menu_Navigate(MENU_PARENT);
				break;
			case BUTTON_RIGHT:
				Menu_Navigate(MENU_CHILD);
				break;
			case BUTTON_ENTER:
				Menu_EnterCurrentItem();
				break;
			default:
				break;
		}

And in the MENU_ITEM()s, after first giving a new menu item number there are then the states that these can lead to. That is:

#define MENU_ITEM(Name, Next, Previous, Parent, Child, SelectFunc, EnterFunc, Text) \

So it kind of depends how many buttons you have available for menu navigation.

 

Oh and his system has:

static void (*MenuWriteFunc)(const char* Text) = NULL;

So this is a callback you need to assign a value to with the address of your string printing routine (which is obviously going to be different for different kinds of displays). Again his example has:

int main(void)
{
	/* Set up the default menu text write callback, and navigate to an absolute menu item entry. */
	Menu_SetGenericWriteCallback(Generic_Write);
	Menu_Navigate(&Menu_1);

where "Generic_Write" is:

static void Generic_Write(const char* Text)
{
	if (Text)
		puts_P(Text);
}

but this would need to be varied for a different display or when a puts() output stream has not been assigned.

 

As with all Dean's code it is slick and elegant.