Menu for Display

I don't think connecting the LCD to the main hardware serial port is a good idea.

I read though the last e-mails. For sure it seems to be strange, that the day number is 45, but what should be checked?

Oliver

Ok Oliver, thanks for the information,
then I can use each pins that I want for lcd ?

Changing pin for lcd it's working ...

warm regards :slight_smile:
gnux

Hi Oliver,
changing the pin 0 and 1 the menu it's working ok now (i will consider this for the future :slight_smile: ) ...

Very helpfull :slight_smile:

Good to read that you had some success :slight_smile:

Oliver

Thanks again :-), I'll let you know about the next steps :slight_smile:

Ciao Oliver :slight_smile: how are you,
so now that I've take more confidence with your menu I'd like to do a menu that when I turn on arduino put into display :
colums :
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

1°row| Arduino Welcome
2°row| Ver . 1.0
3°row| 06 - 02 - 2013
4°row| 10 : 23 : 55

and then just when I press the first time select button appears the other menu, then will be exit to all menu will return to this screen,

is possible from your point of view ? could you give me suggest ?

thanks for the support,
have nice day,
gnux

Sure, this is described in tutorial 6: Google Code Archive - Long-term storage for Google Code Project Hosting.

  • You start with an empty element: apply &m2_null_element as first element to M2tk. This will disable all menues.
  • draw your personal intro screen (as described above), by using the normal LiquidCrystal commands.
  • In the main "loop()" do the following:
  if ( m2.getRoot() == &m2_null_element ) {
      if ( m2.getKey() != M2_KEY_NONE )
        m2.setRoot(&el_my_own_top_menu);
  }

This will activate your menu once the user has pressed a key.

  • A soon as the user has finished working with your menu, use
         m2.setRoot(&m2_null_element);

to disable your menu again. Of course you need to redraw your own screen again.
More details are given in tutorial 6

Oliver

Ciao Oliver,
thanks for the information,
I try and however I'll let you know :slight_smile: and for example if i would like put in display time is better to use "normal LiquidCrystal commands" also ? and when i re-draw my screen again I call procedure after m2.setRoot(&m2_null_element); ? Is there a simply example that I can use for take confidence ?

so how do you will implement it ?

thanks 10000000 again :-),
gnnux

Is there a simply example that I can use for take confidence ?
Unfortunately i did not made an example for LiquidCrystal, but you can take over the GLCD tutorial 1:1.
In the "loop()" procedure, check for the &m2_null_element as root element and if this is true, than redraw your time screen
I hope all is written in tutorial 6

Oliver

Ciao Oliver,
I've just tried to do this simple try with a simple combo example ... below the code:

#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(&list_element, m2_es_arduino, m2_eh_2bs, m2_gh_lc);

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

void loop() {
  if ( m2.getRoot() == &m2_null_element ) {
      if ( m2.getKey() != M2_KEY_NONE )
        m2.setRoot(&list_element);
  }
}

When I push button nothing appears I've tried from serial menu also but nothing appears... so now I've a trouble ...
into the condition

m2.getRoot() == &m2_null_element

is necessary to assign "&m2_null_element" into the setup ? if yes is there particular sintax to follow ?

because looking the sketch there is no assignment for and then the condition will be never verified right ?

thanks
gnux

Hi

Instead of

M2tk m2(&list_element, m2_es_arduino, m2_eh_2bs, m2_gh_lc);

use

M2tk m2(&m2_null_element m2_es_arduino, m2_eh_2bs, m2_gh_lc);

to assign the null element at the beginning.

And then, the loop procedure MUST be expanded to this (see also the mentioned tutorial!!!)

void loop(void) {
 if ( m2.getRoot() == &m2_null_element ) {
      if ( m2.getKey() != M2_KEY_NONE )
        m2.setRoot(&list_element);
  }
  m2.checkKey();
  if ( m2.handleKey() ) {
    m2.draw();
  }
}

You must not forget to call checkKey(),

Oliver

Thanks Oliver for your precious assistance ...
this was a terrible night ... so I was wake up at 3:45 in the morning ... then I m put in front the computer for try to work ... I will go home i will try ...

Thanks 10000
Gnux

Ciao Oliver,
I've did a couple of try ...
so i don't understand why I've like into tutorial explain I've put :

M2_ROOT(el_switch_to_graphics, NULL, "Show Graphics", &m2_null_element);

and I've tried also:

if ( m2.getRoot() == &m2_null_element ) {
      if ( m2.getKey() != M2_KEY_NONE )
        m2.setRoot(&list_element);
  }
  m2.checkKey();
  if ( m2.handleKey() ) {
    m2.draw();
  }

like your suggestion seems that the condition is always verified because I've put serial debug print for see where the program pass and pass to here when I press the button:

if ( m2.getKey() != M2_KEY_NONE )
        m2.setRoot(&list_element);

... if put == 0 ...to here :

m2.getRoot() == &m2_null_element

the menu has been disappeared but when i check press the button the menu doesn't appers ... where could be the issues ? i very appreciate your support

thanks
gnux

hmm... i have some difficulties to understand your question. But maybe i should clarify the code a little bit with some comments:

  // check for manual written screen
  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();
  }

maybe you can repeat your question including a more complete code example...

Oliver

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

wow and congratulation, you found a bug in M2tklib.
Thanks for that.

As a workaround, please extend the setup procedure to this:

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

I will create an issue for this.

Thanks, Oliver

thanks to you Oliver, i ll try and i'll let you know :slight_smile:

have nice week end
gnux

Ciao Oliver,
now it's working ... :slight_smile:

Thanks 10000
Gnux

great :slight_smile:
Oliver