Quote:
Originally Posted by FalconFour
- need to generate a wide variety of displays within a "function tree" of various display modes and sub-modes, such as (main) -> switched to options menu -> selected clock settings -> entered clock settings menu. There should be dedicated code for most screens, but the screen handler needs to be flexible enough to avoid "reinventing the wheel" inside each function, and each function can re-use a basic library of functions.
|
All figured out and implemented in my code. There's what amounts to an array of display-page-functions with a variable that selects which one is active and controlling the screen at a given time. It's really an array of function address pointers, but dealing with referencers and dereferencers makes me confuse myself, so it's easier to just say it's an array of functions.
There's a similar 2D array of button functions. For the MPGuino hardware, it would be 4 elements wide (3 for button-pressed functions, 1 for idle state), and as long as you have display-page-functions. When a button gets pressed, a snippet of code looks up the button column and current-page-number row, and executes the associated function. That way you can have simple button press functions that are unique to a page, or shared by many pages.
For instance, a next page button would just be currentPage++;.
Or, if you want a button to jump to a non-sequential page, currentPage = (pageNumber);.
A menu system is then just a matter of giving a group of pages button functions that pass around control in an orderly manner.
You could create a page that is only visible so long as you're holding a button by giving the button idle state a function that sends control back to the previous page. Pressing the button makes the page show up, releasing it goes back.