Thread: embedded menu system

  1. #16
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by v_dave View Post
    Thanks, I knew I had the typo's but was going more for a pseudo code look than real syntax. Which I recently saw a post on this forum where that is frowned upon so I will try to do better.
    You will see no objection from me at least, if you post pseudocode.

  2. #17
    Registered User
    Join Date
    Feb 2008
    Posts
    13
    Quote Originally Posted by brewbuck View Post
    I'm just noticing that the num_submenus element here is 3. It should be 0.

    Good luck -- let us know.
    Yup I see that. I was in a hurry to post a reply so I missed that. It took me 4 attempts to post my original reply because my login would time out before I finished putting together that long of a response. Then when I clicked submit I would get a not logged in error and everything I typed was gone. I am a slow learner so it took me 3 rewrites before remembered to make a copy before I submitted ;o)

    I will let you know.

    Thanks,
    v_dave

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I have no problem with pseudo-code as such. In this particular case, the typo bit isn't very important, but the static const, as you seem to know, is a critical part in making it shorter/smaller [since any initialized RAM variables ALSO need to go in ROM, so the code-space AND the RAM space is used, when only ROM is really needed].

    I've never programmed a real tiny system, but I have worked for about 10 years with various types of embedded systems.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Registered User
    Join Date
    Feb 2008
    Posts
    13
    Hello All,

    OK so I got a few menu's working but I have run into an issue. As I mentioned am using an 8-bit embbeded microcontroller whith limited resources. One of my limitations is 2048 BYTEs (note this is BYTE's) of RAM.

    I have approx 16 menu's with an average of 5 selections on each menu. That would be approx 80 structures that need to be defined. I have reduced each structure to as small as possible but each one uses 28 BYTE's of RAM. this totals 2240 BYTE's. A little more than I have availible.

    Well it was a good idea that would work great on a system with more resources. but now it is back to the drawing board.

    Thanks again for the help.

  5. #20
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So does your code not live in ROM? const static code should be fine in ROM, right?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #21
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Do you need all of the menus in memory at the same time? Can you piece out any items that don't require a RAM image?
    Last edited by Dave_Sinkula; 03-14-2008 at 11:28 AM. Reason: Six minutes pokey -- cripes. :(
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #22
    Registered User
    Join Date
    Feb 2008
    Posts
    13
    Here is what I implemented:

    Code:
    typedef struct MENU
    {
        char title[MAX_TITLE];
        void (*command)();
        unsigned char num_submenus;
        unsigned char idx;
        struct MENU *submenu[MAX_SUBMENUS];
    }menu;
    
    menu motor_main_menu = 
        {
            "1.Motor",
            NULL,
            1,
            0,
            {&motor_main, }
        };
    menu Info_Main_Menu =
        {
            "6.Info",
            NULL,
            0
        };
    
    menu Calib_Main_Menu =
        {
            "5.Calib",
            NULL,
            0
        };
    
    menu Move_Main_Menu =
        {
            "4.Movement",
            NULL,
            0
        };
    
    menu Valve_Main_Menu =
        {
            "3.Valve",
            NULL,
            0
        };
    
    menu Comm_Main_Menu =
        {
            "2.Comm",
            NULL,
            0
        };
    
    menu Step_Main_Menu =
        {
            "Step Mode",
            NULL,
            4
        };
    
    menu main_menu = 
        {
            "Main Menu",
            NULL,
            6,
            0,
            {&motor_main_menu, &Comm_Main_Menu, &Valve_Main_Menu, &Move_Main_Menu, &Calib_Main_Menu, &Info_Main_Menu}
        };
    
    And more....
    So umm duh, add a const in front of each structure and now they are in ROM. Sometimes its the simple stuff thats gets in the way.

  8. #23
    Registered User
    Join Date
    Feb 2008
    Posts
    13
    Quote Originally Posted by matsp View Post
    So does your code not live in ROM? const static code should be fine in ROM, right?

    --
    Mats
    My code lives in ROM (64K of ROM) so I just need to make the struct const and it is moved to ROM where it should have been all along.

  9. #24
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by v_dave View Post
    I have approx 16 menu's with an average of 5 selections on each menu. That would be approx 80 structures that need to be defined. I have reduced each structure to as small as possible but each one uses 28 BYTE's of RAM. this totals 2240 BYTE's. A little more than I have availible.
    There are a few tricks to play... But what have you done so far?

    EDIT: Nevermind, I actually scrolled down and saw it. There's more you can do.

    Instead of holding the title as a static array in the struct, you could point out to a char literal. This would avoid wasting space when the menu title is short.

    Depending on the range of values for "data" and "num_submenus," these could both be packed somehow into a single short.

    And instead of using pointers to the submenus, you could use a single char to store an offset into a global array of all submenus.

    But if you're happy just sticking it in ROM and forgetting it, then that's fine.

  10. #25
    Registered User
    Join Date
    Feb 2008
    Posts
    13
    I think sticking it in ROM will be fine. I have plenty ROM it is RAM that is limited.

    I am getting the following Warning:
    Warning : C1825: Indirection to different types ('MENU const *const ' instead of 'MENU *const ')

    LCD_Cntrl.c line 151

    When I do this
    Code:
    static const menu GR_314_Menu =
        {
            "1.3.14",
            set_gr_var,
            0,
            0
        };
    
    static const menu GR_Main_Menu =
        {
            "Gear Ratio",
            NULL,
            5,
            0,
    // This is the line that causes the warning
            {&GR_314_Menu, &GR_475_Menu, &GR_985_Menu, &GR_1491_Menu, &GR_2225_Menu }
        };
    My code still runs but I am working on removing this warning.

  11. #26
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Tell the structure that its member points to ROM?
    Code:
        const struct MENU *submenu[MAX_SUBMENUS];
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  12. #27
    Registered User
    Join Date
    Feb 2008
    Posts
    13
    Quote Originally Posted by Dave_Sinkula View Post
    Tell the structure that its member points to ROM?
    Code:
        const struct MENU *submenu[MAX_SUBMENUS];
    Perfect. This removes a number of warnings

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What I've got so far, creating a menu system:
    By Shamino in forum Game Programming
    Replies: 4
    Last Post: 06-15-2007, 03:03 AM
  2. Replies: 4
    Last Post: 06-13-2005, 09:03 AM
  3. Replies: 3
    Last Post: 06-13-2005, 07:28 AM
  4. Menu stuff
    By Shadow in forum C Programming
    Replies: 10
    Last Post: 04-28-2002, 09:05 AM
  5. quick question about C Dos text menu pgm i was doing
    By Shadow in forum C Programming
    Replies: 2
    Last Post: 09-16-2001, 10:26 AM