Go Down

Topic: Menu for Display (Read 20682 times) previous topic - next topic

olikraus

Good to read that you had some success :-)

Oliver

gnusso

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

gnusso

Ciao Oliver :-) 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

olikraus

Sure, this is described in tutorial 6: http://code.google.com/p/m2tklib/wiki/t06u8g

- 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:
Code: [Select]
  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
Code: [Select]
         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

gnusso

#79
Feb 07, 2013, 12:47 pm Last Edit: Feb 07, 2013, 12:59 pm by gnusso Reason: 1
Ciao Oliver,
thanks for the information,
I try and however I'll let you know :-) 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

olikraus

> 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

gnusso

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

#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
Code: [Select]

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


olikraus

Hi

Instead of
Code: [Select]
M2tk m2(&list_element, m2_es_arduino, m2_eh_2bs, m2_gh_lc);
use
Code: [Select]
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!!!)
Code: [Select]

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

gnusso

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

gnusso

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

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

and I've tried also:

Code: [Select]

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:

Code: [Select]
if ( m2.getKey() != M2_KEY_NONE )
        m2.setRoot(&list_element);




... if put == 0 ...to here :
Code: [Select]

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


olikraus

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

Code: [Select]

  // 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

gnusso

#86
Feb 09, 2013, 08:14 am Last Edit: Feb 09, 2013, 08:53 am by gnusso Reason: 1
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 :-) 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 ...

Code: [Select]

#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:

Code: [Select]

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
Code: [Select]

   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

olikraus

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

As a workaround, please extend the setup procedure to this:
Code: [Select]

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


gnusso

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

have nice week end
gnux

gnusso

Ciao Oliver,
now it's working ... :-)

Thanks 10000
Gnux

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy