Menu for Display

Good Morning Oliver, sorry if i didn't answer to you yestarday evening but I was completed boiled ... :*
So for example this below reported is a simple Combo Example Simple Sketch where Im trying to:

  • at the start show nothing
  • then when I press key show my combo menu

So from Theoretically stand point I've understand and I'm ok what you mean :slight_smile: at least :-), but trying to use the code below reported is not working ... So with the normal example everything is working, display, button are ok ... So maybe I did a error in some other part but I don't where to be honest because is a simple example and I've just change the condition and null element and put the condition ...

#include <LiquidCrystal.h>
#include "M2tk.h"
#include "utility/m2ghlc.h"

LiquidCrystal lcd(10, 9, 3, 2, 1, 0);

uint8_t uiKeySelectPin = 22;
uint8_t uiKeyNextPin = 26;

uint8_t select_color = 0;
uint8_t select_priority = 0;

void fn_ok(m2_el_fnarg_p fnarg) {
  /* accept selection */
}

void fn_cancel(m2_el_fnarg_p fnarg) {
  /* discard selection */
}

const char *fn_idx_to_color(uint8_t idx)
{
  if ( idx == 0 )
    return "red";
  else if (idx == 1 )
    return "green";
  return "blue";
}

const char *fn_idx_to_priority(uint8_t idx)
{
  switch(idx)
  {
    case 0: return "lowest";
    case 1: return "low";
    case 2: return "medium";
    case 3: return "high";
    case 4: return "highest";
  }
  return "";
}


M2_LABEL(el_label1, NULL, "Color:");
M2_COMBO(el_combo1, NULL, &select_color, 3, fn_idx_to_color);

M2_LABEL(el_label2, NULL, "Prio.: ");
M2_COMBO(el_combo2, "v1", &select_priority, 5, fn_idx_to_priority);

M2_BUTTON(el_cancel, NULL, "cancel", fn_cancel);
M2_BUTTON(el_ok, NULL, " ok ", fn_ok);

M2_LIST(list) = { 
    &el_label1, &el_combo1, 
    &el_label2, &el_combo2,  
    &el_cancel, &el_ok 
};
M2_GRIDLIST(list_element, "c2",list);

M2tk m2(&m2_null_element, m2_es_arduino, m2_eh_2bs, m2_gh_lc);
M2_ROOT(el_switch_to_graphics, NULL, "Show Graphics", &m2_null_element);

void setup() {
  // Serial.begin(9600);
  m2_SetLiquidCrystal(&lcd, 20, 4);
  m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
  m2.setPin(M2_KEY_NEXT, uiKeyNextPin);
}


void loop(void) {
if ( m2.getRoot() == &m2_null_element ) 
  {
     // yes, it is our manual written screen
     // place your manual commands here
     lcd.print("...");
     // check if the user has pressed a key while manual screen is active
      if ( m2.getKey() != M2_KEY_NONE )
        m2.setRoot(&list_element);   // refer to a suitable menu
  }

  // do normal menu display  
  m2.checkKey();
  if ( m2.handleKey() ) {
    m2.draw();
  }
}

So what I've note is this :

putting a simple like "debug print" for example:

void loop(void) {
    
if ( m2.getRoot() == &m2_null_element ) 
  {
     // yes, it is our manual written screen
     // place your manual commands here
    lcd.setCursor(0, 0); 
    lcd.print("Condition");
    delay(1000);
//     // check if the user has pressed a key while manual screen is active
       if ( m2.getKey() != M2_KEY_NONE  ) {
            lcd.setCursor(0, 4); 
            lcd.print("Verificata");
            lcd.setCursor(0, 4); 
            lcd.print("          ");
          m2.setRoot(&list_element);  // refer to a suitable menu
        }  
      lcd.setCursor(0, 0); 
      lcd.print("            ");
      delay(1000);
        
     m2.checkKey();   
}

}

The Condition is verified this ( m2.getRoot() == &m2_null_element ) one times ...then if enable also the second part

    m2.checkKey();
    if ( m2.handleKey() ) {
     m2.draw();
     }

execute at one times the first one part and then the if ( m2.handleKey() is verified to but for sure i didn't press but ... also because when appear a menu is stopped on the right element ...

Thanks
Gnux