olikraus:
You assign a menu with
void M2tk::setHome(my_toplevel_menu);
The HOME button will always automatically jump to that menu once the HOME button is pressed. Nothing else needs to be done.
However, you may need to use the six button handler.
Of course you could assign the last menu at any time with setHome()
Oliver
Thanks! With your help I managed to achieve what I wanted. Now the home button serves as "back" button.
m2_rom_void_p getParent(m2_rom_void_p root)
{
if (root == &top_el_main_menu)
return &m2_null_element;
else if (root == &top_el_mellody_menu)
return &top_el_main_menu;
else if (root == &top_el_ring_menu)
return &top_el_main_menu;
else if (root == &top_el_manual_strike_menu)
return &top_el_main_menu;
return &m2_null_element;
}
void root_change_cb(m2_rom_void_p new_root, m2_rom_void_p old_root, uint8_t change_value)
{
m2.setHome(getParent(new_root));
}
void setupUI()
{
// Setup pins
pinMode(uiKeyUpPin, INPUT_PULLUP);
pinMode(uiKeyDownPin, INPUT_PULLUP);
pinMode(uiKeySelectPin, INPUT_PULLUP);
pinMode(uiKeyHomePin, INPUT_PULLUP);
// Connect u8glib with m2tklib
m2_SetU8g(u8g.getU8g(), m2_u8g_box_icon);
// Assign u8g font to index 0
m2.setFont(0, u8g_font_6x13r);
// Setup keys
m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
m2.setPin(M2_KEY_PREV, uiKeyUpPin);
m2.setPin(M2_KEY_NEXT, uiKeyDownPin);
m2.setPin(M2_KEY_HOME, uiKeyHomePin);
// Set menu for the HOME key
m2.setHome(&m2_null_element);
// Register a root change callback procedure
m2.setRootChangeCallback(root_change_cb);
}
There's just one more thing that's giving me trouble. I can't make it to default to the null root at start (the graphics page). I tried
M2tk m2(&m2_null_element, m2_es_arduino, m2_eh_4bs, m2_gh_u8g_fb);
but it still showed me the menu first. Then I tried
void setupUI()
{
...
m2.setRoot(&m2_null_element);
}
and still, didn't work. Am I missing something?
Quite frankly I don't completely understand the importance of
M2_EXTERN_ALIGN(top_el_main_menu);
Does this have to be used on the top element?