Go Down

Topic: Simple menu m2tklib with example. (Read 3 times) previous topic - next topic

AVR_BY

Hi all. Could someone give me working example how to use lib m2tk for my non commercial own project?
I tried write to the author of the M2tklib by email, but he didn't answer. Perhaps he will read this topic and help here.
So my trouble is, im trying use an example Menu2L.pde to create simple menu to drive my voids.

I made own menu:

Temperature
Tachometer
Voltmeter
etc

So, when i choose Temperature, should starts the void with my code where i read DS1820 sensor and draw by GLCD lib. functions any  beautiful screen. After that i choose Esc or Exit button and now see the menu.
When chose Tacho-  see the screen with RPM from inductive sensor and can push Exit to back main menu.
The same with Voltmter and ect "meters."
All my codes work by self, but i really want build helpful device "all-in-one", and all i need - an example based on  2LMenu.pde or another one with implementation my codes.

for example
Choose Volmeter ---- "volmeter screen bla-bla-bla" ----- Exit---- main menu
Chose Temp-----primitive screen -bla-bla-bla and etc.----Exit---- main menu

Thanks.
PS sorry for mistakes, got a flue and 38t.

olikraus

Hi

Your e-mail was placed in the spam folder by gmail. Not sure why this has happend. I am sorry for that.

Use M2_ROOT() element to create a menu. Each M2_ROOT can jump to one sub menu.
Have a look at "Rapunzel" example:

Code: [Select]

M2_LABEL(el_goto_title, NULL, "Rapunzel");
M2_ROOT(el_goto_part1, NULL, "Part 1", &el_part1);
M2_ROOT(el_goto_part2, NULL, "Part 2", &el_part2);
M2_LIST(list_menu) = {&el_goto_title, &el_goto_part1, &el_goto_part2};
M2_VLIST(el_menu_vlist, NULL, list_menu);
M2_ALIGN(el_top, "W64H64", &el_menu_vlist);


The two M2_ROOT elements are form a menu, where each of the M2_ROOT elements refer to different sub-menues.

Oliver



AVR_BY

Thank you for the answer, but i mean a bit another thing.
I don't know how to mix your example Menu2L.pde with mine voids :

Code: [Select]
#include <glcd.h> // inform Arduino IDE that we will use GLCD library
#include "M2tk.h"
#include "utility/m2ghglcd.h"

uint8_t uiKeySelectPin = 3;
uint8_t uiKeyDownPin = 2;
uint8_t uiKeyUpPin = 1;
uint8_t uiKeyExitPin = 0;


//=================================================
// Forward declaration of the toplevel element
M2_EXTERN_ALIGN(top_el_expandable_menu);

// Left entry: Menu name. Submenus must have a '.' at the beginning
// Right entry: Reference to the target dialog box (In this example all menus call the toplevel element again
m2_menu_entry m2_2lmenu_data[] =
{
  { "Temp", NULL },
  { ". Temp in", &top_el_expandable_menu },
  { ". Temp out", &top_el_expandable_menu },
  { "Voltmeter", &top_el_expandable_menu },
  { "Tahometer", NULL },
  { ". 2 cyl", &top_el_expandable_menu },
  { ". 4 cyl", &top_el_expandable_menu },
  { "Lights", &top_el_expandable_menu },
   { NULL, NULL },
};

// The first visible line and the total number of visible lines.
// Both values are written by M2_2LMENU and read by M2_VSB
uint8_t m2_2lmenu_first;
uint8_t m2_2lmenu_cnt;

// M2_2LMENU definition
// Option l4 = four visible lines
// Option e15 = first column has a width of 15 pixel
// Option W43 = second column has a width of 43/64 of the display width

M2_2LMENU(el_2lmenu,"l4e15W43",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0');
M2_SPACE(el_space, "W1h1");
M2_VSB(el_vsb, "l4W2r1", &m2_2lmenu_first, &m2_2lmenu_cnt);
M2_LIST(list_2lmenu) = { &el_2lmenu, &el_space, &el_vsb };
M2_HLIST(el_hlist, NULL, list_2lmenu);
M2_ALIGN(top_el_expandable_menu, "-1|1W64H64", &el_hlist);

// m2 object and constructor
M2tk m2(&top_el_expandable_menu, m2_es_arduino, m2_eh_4bs, m2_gh_glcd_ffs);

void setup() {
  m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
  m2.setPin(M2_KEY_NEXT, uiKeyDownPin);
  m2.setPin(M2_KEY_PREV, uiKeyUpPin);
  m2.setPin(M2_KEY_EXIT, uiKeyExitPin); 
}

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


void tempIn () {
  //my code shows the temp on the display by GLCD lib
}

void tempOut () {
  //my code shows the temp on the display by GLCD lib
}

void volts() {
  //my code show volts
}

void tach2cyl () {
   // my code
}

void tach4cyl (){
   // my code
}


Help pls and i promise to learn the tutorial for m2tk lib :))))

olikraus

Hi

Ok, i think i got your point. 2LMenu never was designed to switch things on and off. Instead it was designed to jump to sub menues. However you can use M2_SPACECB to call your void procedures. See the second example here:
http://code.google.com/p/m2tklib/wiki/elref#SPACECB

Another option is to use http://code.google.com/p/m2tklib/wiki/elref#X2LMENU. It will have a call back procedure so you can directly assign your procedures.

Both options will be available with 1.10, which has not yet been releases. I can upload a prerelease, but i need to know which variant is required for your project (u8glib? GLCD?)

Oliver

olikraus

Another option in your case is to use M2_TOGGLE for the temperature and perhaps M2_BUTTON for other function calls.
I assume (from your example) you need the GLCD variant... i will upload it u8glib download area.

Oliver

Go Up