Pages: 1 ... 4 5 [6] 7 8 ... 14   Go Down
Author Topic: Menu for Display  (Read 12744 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Edison Member
*
Karma: 130
Posts: 1438
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good to read that you had some success :-)

Oliver
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 426
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Sr. Member
****
Karma: 2
Posts: 426
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Germany
Offline Offline
Edison Member
*
Karma: 130
Posts: 1438
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Sr. Member
****
Karma: 2
Posts: 426
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: February 07, 2013, 06:59:39 am by gnusso » Logged

Germany
Offline Offline
Edison Member
*
Karma: 130
Posts: 1438
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Sr. Member
****
Karma: 2
Posts: 426
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ciao Oliver,
I've just tried to do this simple try with a simple combo example ... below the code:
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
Code:
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

Logged

Germany
Offline Offline
Edison Member
*
Karma: 130
Posts: 1438
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

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

Offline Offline
Sr. Member
****
Karma: 2
Posts: 426
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 426
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
M2_ROOT(el_switch_to_graphics, NULL, "Show Graphics", &m2_null_element);
and I've tried also:

Code:
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:
if ( m2.getKey() != M2_KEY_NONE )
        m2.setRoot(&list_element);



... if put == 0 ...to here :
Code:
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

Logged

Germany
Offline Offline
Edison Member
*
Karma: 130
Posts: 1438
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
  // 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
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 426
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good Morning Oliver, sorry if i didn't answer to you yestarday evening but I was completed boiled ...  smiley-kiss
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:
#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:
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:
   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
« Last Edit: February 09, 2013, 02:53:02 am by gnusso » Logged

Germany
Offline Offline
Edison Member
*
Karma: 130
Posts: 1438
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

As a workaround, please extend the setup procedure to this:
Code:
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

Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 426
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

have nice week end
gnux
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 426
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thanks 10000
Gnux
Logged

Pages: 1 ... 4 5 [6] 7 8 ... 14   Go Up
Jump to: