Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/02/10 15:37
Read: times


 
#177066 - State machine can be small.
Responding to: ???'s previous message
I often have a little state machine for multi-level menues.

Instead I use some form of pointer mechanism (could be real pointers or indices) to keep track of where I am.

Each menu has a "back" entry. If NULL, then I'm on the root menu level.
Each menu item has a flag telling if it is a terminal menu choice or starts a new menu.
If it starts a new menu, then the entry gives a reference to the new menu.
If it is a command, then it may store a function pointer (for some processors) or a command identifier.

For an 8051, I would try to keep down the number of real menues and instead do all references as integers. And I would use command identifiers and have a large switch statement converting from a command identifier to calling the actual function. Having a switch statement with 170 case statements - each having a single function call - may not be elegant, but this makes sure that the Keil compiler/linker will see the full span of the call tree.

The state machine need not be so large since it basically only need to care about four buttons - back (escape) forward (enter) up (prev) down (next).

Note that the full menu tree can be designed and stored as a one-dimensional array of menu choices, by having each menu choice point to either:
from parent menu choice: identifier of top entry of the sub-menu.
from leaf menu choice: command identifier selecting what cmd function to call.

The back pointers can be dynamically stored in a small array (a menu shouldn't be more than 4-5 levels deep anyway) so whenever the user makes a select of a non-leaf menu choice, the current "back" pointer (array index of top entry of (sub)menu is pushed, and then the top index of the current menu is remembered as back index. Then the forward index of the selected entry is remembered as new first entry of current menu.

List of 29 messages in thread
TopicAuthorDate
Uart user menu via switch/case state machine            01/01/70 00:00      
   State machine can be small.            01/01/70 00:00      
   My take....            01/01/70 00:00      
   asked and answered            01/01/70 00:00      
      Broken and Fixed            01/01/70 00:00      
         excellent            01/01/70 00:00      
            My experience as well....            01/01/70 00:00      
               My experience as well....            01/01/70 00:00      
               But you're the writer...            01/01/70 00:00      
                  out of context            01/01/70 00:00      
                     Yes, Chances are no one else will see your code            01/01/70 00:00      
                        male cow manure            01/01/70 00:00      
                           Don't be too over confident            01/01/70 00:00      
                  Just Concepts            01/01/70 00:00      
                     Don't think own code is the best            01/01/70 00:00      
                     exactly            01/01/70 00:00      
                        what I have done a lot of lately is            01/01/70 00:00      
   Protothreads???            01/01/70 00:00      
   A case for a CASE tool?            01/01/70 00:00      
      Using a tool like that........            01/01/70 00:00      
         Thanks Michael...            01/01/70 00:00      
            Pencil and paper            01/01/70 00:00      
      Pros and Cons            01/01/70 00:00      
         Analysis/Design            01/01/70 00:00      
            Enterprise Architect            01/01/70 00:00      
               RE: Enterprise Architect            01/01/70 00:00      
                  Reverse State Tables            01/01/70 00:00      
                     RE: "Reverse-engineering"            01/01/70 00:00      
                        php and html when documenting            01/01/70 00:00      

Back to Subject List