Hot!Menu Structure

Page: 12 > Showing page 1 of 2
Author
TucsonDon
Senior Member
  • Total Posts : 145
  • Reward points : 0
  • Joined: 2015/08/07 13:32:43
  • Location: Tucson AZ
  • Status: offline
2017/10/18 11:18:24 (permalink)
0

Menu Structure

I am using an 18F46K22 and trying to build a menu structure with a main menu that points to sub-menus. Using switch and enum I was trying to point (*scroll & *scroll2) to a list to scroll and display on a LCD and to point to a function based on the *scroll selection. When I display on LCD I get “(null)” and I am unable to point to the next enum list.
 

 
 volatile uint8_t *scroll,*scroll2;
 
typedef enum
{
    Time,
    Pump,
    Solar,
    Waterfall,
    Clean,
}MainModes;

 
 
 
typedef enum
{
    Timer1,
    Timer2,
    Timer3,
    Timer4,
    Timer5,
    Timer6,
    Timer7,
    Timer8,
}TimerModes;

 
 
 
void UITimerSet(void)
{
    PmpTmrSet.Set = On;
   
    TimerModes *scroll;
   
    while (ButtonStatus.Mode != On)
    {
        switch (*scroll)
        {
            case Timer1:
            {
                PmpTmrUsed.pmptmr0 = On;
                TimeSet();
                break;
            }
 
            case Timer2:
            {
                PmpTmrUsed.pmptmr1 = On;
                TimeSet();
                break;
            }
 
            case Timer3:
            {
                PmpTmrUsed.pmptmr2 = On;
                TimeSet();
                break;
            }
 
            case Timer4:
            {
                PmpTmrUsed.pmptmr3 = On;
                TimeSet();
                break;
            }
 
            case Timer5:
            {
                PmpTmrUsed.pmptmr4 = On;
                TimeSet();
                break;
            }
 
            case Timer6:
            {
                PmpTmrUsed.pmptmr5 = On;
                TimeSet();
                break;
            }
 
            case Timer7:
            {
                PmpTmrUsed.pmptmr6 = On;
                TimeSet();
                break;
            }
 
            case Timer8:
            {
                PmpTmrUsed.pmptmr7 = On;
                TimeSet();
                break;
            }
           
            default:
                if (ButtonStatus.Mode == On && ButtonStatus.Pushed == Off)
                {
                    ButtonStatus.Pushed == On;
                    return;
                }
        }
    }
}
 
void UIModeSet(void)
{
  
   
    ModeDisplay();
   
    switch(*scroll)
    {
        case Time:
        {
            UITimerSet();
        }
 
        case Pump:
        {
            UIPumpSet();
        }
 
        case Solar:
        {
            UISolarSet();
        }
 
        case Waterfall:
        {
 
        }
 
        case Clean:
        {
 
        }
    } /*end of shift()*/
 
}
 
 
 
void ModeDisplay(void)
{
    MainModes *scroll;
    extern char buff[17];
   
  
    do
    {
        *scroll2 = *scroll + 1;
        sprintf(buff, "%s", DisplayText[*scroll]);
        LineOne;         //address on lcd
        putsXLCD(buff);
        sprintf(buff, "%s", DisplayText[*scroll2]);
        LineTwo;        //address on lcd
        while(BusyXLCD());
        putsXLCD(buff);
        if (ButtonStatus.Up == On && ButtonStatus.Pushed == Off)
        {
            ButtonStatus.Pushed = On;
            *scroll++;
            if (*scroll >= 5) *scroll = 0;
            else if (*scroll2 >= 5) *scroll2 = 0;
        }
        else if (ButtonStatus.Down == On && ButtonStatus.Pushed == Off)
        {
            ButtonStatus.Pushed = On;
            *scroll--;
            if (*scroll < 0)*scroll = 4;
            else if (*scroll2 < 0)*scroll2 = 4;
        }
        else if (ButtonStatus.Enter == On && ButtonStatus.Pushed == Off)
        {
            ButtonStatus.Pushed = On;
        }
    }
 

post edited by TucsonDon - 2017/10/18 11:20:25

“Remember what may seem elementary to you may be very complex to someone else.”
#1

29 Replies Related Threads

    jtemples
    Super Member
    • Total Posts : 10682
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Menu Structure 2017/10/18 11:25:28 (permalink)
    +1 (1)
    You've got different declarations of *scroll all over the place, and I can't see where any of them are initialized.  And the uint8_t *scroll at file scope is shadowed by the other declarations.
    #2
    TucsonDon
    Senior Member
    • Total Posts : 145
    • Reward points : 0
    • Joined: 2015/08/07 13:32:43
    • Location: Tucson AZ
    • Status: offline
    Re: Menu Structure 2017/10/18 11:56:10 (permalink)
    0
    jtemples
    You've got different declarations of *scroll all over the place, and I can't see where any of them are initialized.  And the uint8_t *scroll at file scope is shadowed by the other declarations.


    How do I correct that so that I can point to the different lists? When I step through the program, the MainModes list is shown under the variable *scroll but it is not showing on the LCD

    “Remember what may seem elementary to you may be very complex to someone else.”
    #3
    jtemples
    Super Member
    • Total Posts : 10682
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Menu Structure 2017/10/18 12:30:13 (permalink)
    +1 (1)
    Is this your real code?  I don't know how it is doing anything.
        TimerModes *scroll;
        while (ButtonStatus.Mode != On)
        {
            switch (*scroll)
    What were you expecting that to do with scroll having an unknown value?  I don't see any sort of menu data structure that it should be pointing to.
    #4
    TucsonDon
    Senior Member
    • Total Posts : 145
    • Reward points : 0
    • Joined: 2015/08/07 13:32:43
    • Location: Tucson AZ
    • Status: offline
    Re: Menu Structure 2017/10/18 16:13:14 (permalink)
    0
    jtemples
    Is this your real code?  I don't know how it is doing anything.
        TimerModes *scroll;
        while (ButtonStatus.Mode != On)
        {
            switch (*scroll)
    What were you expecting that to do with scroll having an unknown value?  I don't see any sort of menu data structure that it should be pointing to.


    yes this is my code and your right it doesn't work that's why I posted it was to get help on figuring it out. I was trying to point to the TimerModes enum list.

    “Remember what may seem elementary to you may be very complex to someone else.”
    #5
    qhb
    Superb Member
    • Total Posts : 6261
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Menu Structure 2017/10/18 16:30:17 (permalink)
    +1 (1)
    Do you have a C reference book?
    You don't seem to understand the difference between a "definition" and a "declaration".
    You are using typedef to define some structures,
    and you are declaring some pointers to point at a variable of that type,
    but you are NEVER actually declaring a variable of that type for the pointer to point to.
    i.e.
    TimerModes *scroll;

    This declares a pointer to a variable of type "TimerModes", but you have not created a variable of that type anywhere. Your pointer will just be NULL.
     
    #6
    TucsonDon
    Senior Member
    • Total Posts : 145
    • Reward points : 0
    • Joined: 2015/08/07 13:32:43
    • Location: Tucson AZ
    • Status: offline
    Re: Menu Structure 2017/10/18 17:20:11 (permalink)
    0
    qhb

    You are using typedef to define some structures,
    and you are declaring some pointers to point at a variable of that type,
    but you are NEVER actually declaring a variable of that type for the pointer to point to.
     


    I thought I was when I pointed to the enum list, if not how do I do that?

    “Remember what may seem elementary to you may be very complex to someone else.”
    #7
    qhb
    Superb Member
    • Total Posts : 6261
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Menu Structure 2017/10/18 17:49:07 (permalink)
    0
    "typedef" does NOT create a variable for you.
    It creates a new "type" which can then be used to create a variable of that type. You never do that.
     
    #8
    jtemples
    Super Member
    • Total Posts : 10682
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Menu Structure 2017/10/18 18:27:48 (permalink)
    0
    I thought I was when I pointed to the enum list, if not how do I do that?

     
    You're not pointing to anything anywhere in that code, and you can't point to an enum in any event.  You have to assign a value to a pointer to make it point to something, e.g.,
    TimerModes timer_mode;
    TimerModes *timer_ptr = &timer_mode;
    But it's not clear why you would want to do that.  What do the values of TimerModes mean?  Is there an array of corresponding text to display on the LCD for each mode?
     
    #9
    jtemples
    Super Member
    • Total Posts : 10682
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Menu Structure 2017/10/18 18:52:34 (permalink)
    +1 (1)
    I think the issue is that "scroll" shouldn't be a pointer, just an enum object that you use in your switch().  But you still need to initialize it.
    #10
    TucsonDon
    Senior Member
    • Total Posts : 145
    • Reward points : 0
    • Joined: 2015/08/07 13:32:43
    • Location: Tucson AZ
    • Status: offline
    Re: Menu Structure 2017/10/19 09:03:58 (permalink)
    0
    qhb & jtemples thanks for your input, it gives me some good information to "chew on"

    “Remember what may seem elementary to you may be very complex to someone else.”
    #11
    TucsonDon
    Senior Member
    • Total Posts : 145
    • Reward points : 0
    • Joined: 2015/08/07 13:32:43
    • Location: Tucson AZ
    • Status: offline
    Re: Menu Structure 2018/01/27 09:34:52 (permalink)
    0
    So I have ben doing lot of reading and this what I have come up with

    #define MAX_TITLE 10
    #define MAX_SUBMENUS 8
     
    typedef struct MENU
    {
        char title[MAX_TITLE];
        void (*command)();
        char num_submenus;
        uint8_t idx;
        struct MENU *submenu[MAX_SUBMENUS];
    }menu;

     

    static char MainMenu [7][11] =
    {
        {"Main Menu"        },
        {"Clock"            },
        {"Pump"             },
        {"Solar"            },
        {"Valve"            },
        {"Clean"            },
        {"Info"             }
    };
     
    void navigate_menu(menu *mnu)
    {
        if(mnu->num_submenus == 0)
        {
            /* Execute the command */
            mnu->command();
            return;
        }
       
        
        menu MainMenu =
    {
       "Main Menu",
       NULL,
       4,
       0,
       MainMenu
    };
    }

     
    The issue that I have now is that I can't scroll through the remaining strings to display.

    “Remember what may seem elementary to you may be very complex to someone else.”
    #12
    jtemples
    Super Member
    • Total Posts : 10682
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Menu Structure 2018/01/27 10:19:20 (permalink)
    0
    The issue that I have now is that I can't scroll through the remaining strings to display.

     
    You haven't shown any code that could do that.  Are you asking how to do it, or have you written code that doesn't work?
    #13
    TucsonDon
    Senior Member
    • Total Posts : 145
    • Reward points : 0
    • Joined: 2015/08/07 13:32:43
    • Location: Tucson AZ
    • Status: offline
    Re: Menu Structure 2018/01/27 10:27:07 (permalink)
    0
    I am asking how to do it. I actually found this on another forum and when I step through using the simulator it loads "Main Menu" but none that follow. 

    “Remember what may seem elementary to you may be very complex to someone else.”
    #14
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2263
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Menu Structure 2018/01/27 14:49:19 (permalink)
    0
    Here is the menu structure I use:
    typedef struct{
        Clip_t          Clip;
        const char    **Items;
        void           *Background;
        bool          (*timeoutfunc)();
        int             TotalItems;
        int             DisplayableItems;
        int             FontWidth;
        int             FontHeight;
        int             Flag;
    }Menu_t;

     
    const char const *items[]={"One","Two","Three","Four","Five","Six","Seven","Eight",NULL};
     
    Always put null at the end so that your menu function can count the number of items and also get a max width size in characters or pixels.
     
    After using a menu, an index can be returned or -1 if timeout.
     
    The menu has to be opened, accessed then closed.
    post edited by Gort2015 - 2018/01/27 14:54:19

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #15
    TucsonDon
    Senior Member
    • Total Posts : 145
    • Reward points : 0
    • Joined: 2015/08/07 13:32:43
    • Location: Tucson AZ
    • Status: offline
    Re: Menu Structure 2018/01/28 07:15:59 (permalink)
    0
    Gort2015
    Here is the menu structure I use:
    typedef struct{
        Clip_t          Clip;
        const char    **Items;
        void           *Background;
        bool          (*timeoutfunc)();
        int             TotalItems;
        int             DisplayableItems;
        int             FontWidth;
        int             FontHeight;
        int             Flag;
    }Menu_t;

     
    const char const *items[]={"One","Two","Three","Four","Five","Six","Seven","Eight",NULL};


    @Gort2015 just for clarification you are using the **Items to point to *items in your structure, is that correct? Also what would you use the *Background to point at?  

    “Remember what may seem elementary to you may be very complex to someone else.”
    #16
    Sobottech
    Super Member
    • Total Posts : 231
    • Reward points : 0
    • Joined: 2015/12/02 03:32:17
    • Location: 0
    • Status: offline
    Re: Menu Structure 2018/01/28 08:01:29 (permalink)
    0
    I suggest you look at DM240313 XLP 8-Bit Development Board.
     
    There is the sourcecode of DEMO APPLICATION SOFTWARE.
    There is a Menu.
    You should modify this in no time for your needs, you see how it is made and porting it to your PIC should be done easily. There is documentation, too.
    It's for PIC18F87K22 and PIC16LF1947.
    #17
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2263
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Menu Structure 2018/01/28 08:11:58 (permalink)
    0
    Items is a pointer to an array of pointers.
     
    Background saves the background that will be occupied by the menu.
    When the menu is closed, the background is restored.
     
    The logic of moving through a menu is quite simple.
    Two variables:
    index of the current item and position on the display.
     
    Here is a part of code that moves through a menu downwards.  A grid or solid grid is drawn around the item text using exclusive or. The menu is scrolled up when the bottom of the menu is reached and the next item is drawn into the empty space.  Pixel scrolling also possible for a smooth look.
    //------------------------
                if(x&STATUS_CW){
                    if(item<Menu->TotalItems-1){
                        lcd7920_srect(2,2+position*Menu->FontHeight,Menu->Clip.Width-4,Menu->FontHeight-1,COLOR_XOR);    //off
                        item++;
                        if(position<(SHOW-1)) position++;
                        else{
                            lcd7920_vscroll(2,2,Menu->Clip.Width-4,Menu->Clip.Height-4,Menu->FontHeight,COLOR_CLR);
                            lcd7920_setcursor(2,2+(Menu->DisplayableItems-1)*Menu->FontHeight);
                            lcd7920_gputs(Menu->Items[item]);
                        }
                        lcd7920_srect(2,2+position*Menu->FontHeight,Menu->Clip.Width-4,Menu->FontHeight-1,COLOR_XOR);    //on
                    }
                }
                //------------------------


    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #18
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2263
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Menu Structure 2018/01/28 08:22:42 (permalink)
    0
    Clip_t contains dimensions.
     
    By smart programming nothing can be drawn outside of the clip, allowing Star Wars scrolling with text and graphics from any position on or off display.
     
    Like you can push sections, you can push clips.
     
    int lcd7920_vscroll(int XPos, int YPos, int Width, int Height, int Scroll, int FillColor);
     
    Vertical Scroll by pixels, can be negative or positive.
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #19
    NorthGuy
    Super Member
    • Total Posts : 4830
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Menu Structure 2018/01/28 08:26:27 (permalink)
    +1 (1)
    TucsonDon
    So I have ben doing lot of reading and this what I have come up with

     
    There are two separate types of entities - a menu item and the whole menu.
     
    The menu item structure may contain the title, the function to execute when menu is hit, some sort of information which may be passed to the execute command,  an id (if needed) etc. There is no place for submenus in this structure because submenus are entities which consist of other menu items, and not the part of the menu item. I suggest you omit submenus until your simple menu is working.
     
    The menu is some sort of ordered collection of the menu items. In the simplest form this is an array of menu item. This could also be a linked list of menu items, or a tree. Start building your menu by creating the collection, learning to iterate through items and displaying the titles correctly. This is a big work in itself. Add execution of menu items later.
     
    Don't try to design the whole struct for the menu. Start from a simple menu items which has nothing but title. Add everything else later - your struct may grow as you work. For now, it is important for you how the menu items come together, how you iterate through them, how you display them.
     
    Don't try to do everything at once. Get a tiny little piece and stay on it until it's done. Then move further.
     
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2018 APG vNext Commercial Version 4.5