Go Down

Topic: New Arduino library: MenuSystem (Read 9 times) previous topic - next topic

jonblack

Apologies for those who left messages addressed to me. I didn't have notifications turned on, so have missed them.

@vidsondak
I'm not sure because it's been a while since I've done any arduino development. My first thought is that the library isn't in the correct folder, but the error message is odd since "menu system" is written with a space in it. Did you make a typo by any chance?

@JoarleyRodrigues
There are examples included with the library, have you tried those out?

@kipkool
You posted way, way back in March. I'm very sorry. Hopefully you've found an answer by now. If not, please raise an issue on github and I'll take a look. Why do I need a github issue? I'm away for a few weeks, and I tend to be active on github a lot, so when I return I will be reminded.



vidsondak

Hi. im learning to trying your code here. however it stop on first line.

#include <MenuSystem.h>


MenuSystem ms;
Menu mm("");
MenuItem mi_time("TIME");
MenuItem mi_date("DATE");
MenuItem mi_alarm("ALARM");
Menu mu_disp("DISP");
MenuItem mi_disp_brightness("BRTNS");

my sketch stop n show error "menu system does not name a type"

what am i missing?

JoarleyRodrigues

Have anyone a complete code with this librarie so I can better understand and use to make my menu?

Thanks!

Kipkool

Forget it I've found it.

It's un the library, cpp file:

Code: [Select]
// A menu item was selected, so reset the menu ready for when
// it's used again.
_p_curr_menu = _p_root_menu;


So I've added mreset parameter at select() function:
Code: [Select]

void MenuSystem::select(boolean mreset)
{
    MenuComponent* pComponent = _p_curr_menu->activate();

    if (pComponent != NULL)
    {
        _p_curr_menu = (Menu*) pComponent;
    }
    else
    {
       
if (mreset) {
// A menu item was selected, so reset the menu ready for when
        // it's used again.
        _p_curr_menu = _p_root_menu;
}
    }
}

Kipkool

#19
Mar 27, 2013, 03:18 pm Last Edit: Mar 27, 2013, 03:20 pm by Kipkool Reason: 1
Hello Jon

I'm bumping this old thread :)

First, thanks for your menu class, this is exactly what I needed for my project.

I'm actually building an antenna tracker to track my drones using telemetry data.

Code is here: https://code.google.com/p/ghettostation/source/browse/#git%2FGhettoStation

On the ground device, there's an LCD ( i2c lcd03) proposing at startup a menu.

Here is the menu:

Menu Root:
   - START
   - SET_HOME
   - CONFIGURATION:
                 - SERVOS:
                       - PAN:
                              - MIN_PWM
                              - MIN_ANGLE
                              - MAX_PWM
                              - MAX_ANGLE
                       - TILT:
                              - MIN_PWM
                              - MIN_ANGLE
                              - MAX_PWM
                              - MAX_ANGLE
                       - TEST
                 - BAUDRATE


Here is my init menu function:

Code: [Select]
void init_menu() {
rootMenu.add_item(&m1i1Item, &screen_tracking); //start track
rootMenu.add_item(&m1i2Item, &screen_sethome); //set home position
rootMenu.add_menu(&m1m3Menu); //configure
m1m3Menu.add_menu(&m1m3m1Menu); //config servos
m1m3m1Menu.add_menu(&m1m3m1m1Menu); //config pan
m1m3m1m1Menu.add_item(&m1m3m1m1l1Item, &configure_pan_minpwm); // pan min pwm
m1m3m1m1Menu.add_item(&m1m3m1m1l2Item, &configure_pan_minangle); // pan min angle
m1m3m1m1Menu.add_item(&m1m3m1m1l3Item, &configure_pan_maxpwm); // pan max pwm
m1m3m1m1Menu.add_item(&m1m3m1m1l4Item, &configure_pan_maxangle); // pan max angle
m1m3m1Menu.add_menu(&m1m3m1m2Menu); //config tilt
m1m3m1m2Menu.add_item(&m1m3m1m2l1Item, &configure_tilt_minpwm); // tilt min pwm
m1m3m1m2Menu.add_item(&m1m3m1m2l2Item, &configure_tilt_minangle); // tilt min angle
m1m3m1m2Menu.add_item(&m1m3m1m2l3Item, &configure_tilt_maxpwm); // tilt max pwm
m1m3m1m2Menu.add_item(&m1m3m1m2l4Item, &configure_tilt_maxangle); // tilt max angle
                       m1m3m1Menu.add_item(&m1m3m1i3Item, &configure_test_servo);
m1m3Menu.add_item(&m1m3l2Item, &configure_baudrate); //config baudrate
displaymenu.set_root_menu(&rootMenu);
}



Then in the mainloop, when current_activity == "MENU" , it calls at 10hz:

Code: [Select]
void display_menu() {
       Menu const* displaymenu_current = displaymenu.get_current_menu();
//Serial.print("current menu = ");
//Serial.println(displaymenu_current->get_cur_menu_component_num());
MenuComponent const* displaymenu_sel = displaymenu_current->get_selected();
         
       for (int n = 1; n < 5; ++n) {
         char string_buffer[21];
//
           if ( (displaymenu_current->get_num_menu_components()) >= n ) {
               
       
     
       MenuComponent const* displaymenu_comp = displaymenu_current->get_menu_component(n-1);
       String getname = displaymenu_comp->get_name();
 for ( int l = getname.length()-1 ; l<20 ; l++ ) {
getname = getname + " ";
}  

       if (displaymenu_sel == displaymenu_comp) {

      getname.setCharAt(19,'<');
       } else {
        getname.setCharAt(19, ' ');
       }
     
       getname.toCharArray(string_buffer,21);
               
           }
           else {
              empty_line.toCharArray(string_buffer,21);
           }
store_lcdline(n, string_buffer);

};

}


Then LCD screen is refreshed at 10hz on another timed loop in the main loop.

This works almost well.
When I stay inside the menu, I can go next, prev, back and select...
I use click button to select, & long_press button to go back to the parent.

The problem is when I select an item in a submenu. Imagine I've selected CONFIGURATION/TILT/MIN_PWM. My current_activity change from #MENU" to "TILT_MINPWM". ( so the display_menu function is not called anymore. )
It then call another function to display the configuration screen on the LCD & handle configuring parameters.
When I quit this screen, I change the current_status to "MENU", so it displays the menu again.
The problem is it doesn't go back to the previous menu state, it just start from the Root Menu, with the CONFIGURATION already selected.

I'd like to have it going back in menu_root/CONFIGURATION/SERVOS/TILT menu and not Root.

There's probably a mistake I've made somewhere, but I can't find it for now.

If you have a genius idea, I take it :)

Cheers.

Go Up