Simple menu m2tklib with example.

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.

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:

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

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 :

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

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

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

Yes, GLCD lib. Mega2560 board.
Also i think to buy a DUE with 7' TFT display, and i am waiting for, when you build a m2tk lib for this things.
Look please:
http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=111008432389
PS. i downloaded the prerelease, great thanks.
If you don't mind, i will ask about other troubles with my project.

Nice, but currently for M2tklib there is no low level graphics driver for the SSD1963

Oliver

Dear Oliver, could you give me please the working example code? I tried to understand functions that you gave, but i see only a lot of warning :frowning: It takes for you 5 minutes, and i can move next step of my project. I will be glad to see the example based on menu2L, or something like this.
Thank you.

Hi

To write some code i need a more detailed specification. Let us start with the temperature. Do you want to display "in" and "out" temperature? Or do you need to edit and enter some target temperature?
Do you have some specific menu layout in mind?

Another question: Did you manage to compile an run other examples from m2tklib?

Oliver

The menu structure should be something like this:

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

uint8_t uiKeySelectPin = 53;
uint8_t uiKeyDownPin = 45;
uint8_t uiKeyUpPin = 47;
uint8_t uiKeyExitPin = 51;


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

uint8_t el_space_u8 = 0;

void FP_v(m2_el_fnarg_p fnarg) {
 // show screen with my A0 pin value
}

void FFP_r(m2_el_fnarg_p fnarg) {
 // show screen with my A1 pin value
}

void Temp(m2_el_fnarg_p fnarg) {
  // show screen with my A5 pin value
}

// other voids that show any values 



//M2_SPACECB(el_space_cb_zero, NULL, FFP_v);
//M2_SPACECB(el_space_cb_inc, NULL, FFP_r);
//M2_SPACECB(el_space_cb_dec, NULL, Temp);

// 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[] = 
{
  { "FFP", NULL },
  { ". volt", &top_el_spacecb_menu },
  { ". res", &top_el_spacecb_menu},
  { "Temp",    &top_el_spacecb_menu },
 // etc..
  { 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_spacecb_menu, "-1|1W64H64", &el_hlist);

// m2 object and constructor
M2tk m2(&top_el_spacecb_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();
  }
}

By now, i don't need to input any values. Perhaps in the future.

So, could you please correct the code to show, how can i call my voids.
Thank you.

ok, here is my solution. Not tested (my hardware is not available at the moment), but it compiles without error.

Basic idea is, that the values are polled within the main "loop()". Local menu screens with display the values to the user. M2_ROOT implement a button to jump back to the top level menu.

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

uint8_t uiKeySelectPin = 53;
uint8_t uiKeyDownPin = 45;
uint8_t uiKeyUpPin = 47;
uint8_t uiKeyExitPin = 51;


//=================================================
uint32_t value_from_A0;
uint32_t value_from_A1;
uint32_t value_from_A5;

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


// show screen with my A0 pin value
M2_LABEL(el_a0_label, NULL, "A0");
M2_U32NUM(el_a0_u32, "c4r1", &value_from_A0);
M2_ROOT(el_a0_ok, NULL, " ok ", &top_el_menu);
M2_LIST(list_a0) = { &el_a0_label, &el_a0_u32, &el_a0_ok };
M2_VLIST(el_a0_vlist, NULL, list_a0);
M2_ALIGN(top_el_a0, "-1|1W64H64", &el_a0_vlist);


// show screen with my A1 pin value
M2_LABEL(el_a1_label, NULL, "A1");
M2_U32NUM(el_a1_u32, "c4r1", &value_from_A1);
M2_ROOT(el_a1_ok, NULL, " ok ", &top_el_menu);
M2_LIST(list_a1) = { &el_a1_label, &el_a1_u32, &el_a1_ok };
M2_VLIST(el_a1_vlist, NULL, list_a1);
M2_ALIGN(top_el_a1, "-1|1W64H64", &el_a1_vlist);


// show screen with my A5 pin value
M2_LABEL(el_temperature_label, NULL, "Temperature");
M2_U32NUM(el_temperature_u32, "c4r1", &value_from_A5);
M2_ROOT(el_temperature_ok, NULL, " ok ", &top_el_menu);
M2_LIST(list_temperature) = { &el_temperature_label, &el_temperature_u32, &el_temperature_ok };
M2_VLIST(el_temperature_vlist, NULL, list_temperature);
M2_ALIGN(top_el_temperature, "-1|1W64H64", &el_temperature_vlist);


// other voids that show any values 



// 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[] = 
{
  { "FFP", NULL },
  { ". volt", &top_el_a0 },
  { ". res", &top_el_a1},
  { "Temp",    &top_el_temperature },
 // etc..
  { 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_menu, "-1|1W64H64", &el_hlist);

// m2 object and constructor
M2tk m2(&top_el_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() {
  
  value_from_A0 = analogRead(A0);
  value_from_A1 = analogRead(A1);
  value_from_A5 = analogRead(A5);
  
  m2.checkKey();
  if ( m2.handleKey() ) {
      m2.draw();
  }
}

Oliver

Edit: Added "r1" to make the U32 fields read only.

Hi,
I am pretty new to C++ and Arduino (steep learning curve at the moment) and am trying unsuccessfully to adapt this code to use the u8g library.
I am using a Nokia 3310 display (PCD8544) which I have used with the u8g library and successfully run the 'Hello World' example.
If you could show me how to modify the example code from this thread I would much appreciate it.
I am using Pins A0 to A5 as input pins (Up, Down, Left, Right, Enter) with pull down resistors, (HIGH is button press).

Thanks,
Don =)

Hi

I think the first thing to do is to run one of the M2tklib examples (Ensure to use M2tklib for U8glib).
Use the same U8glib constructor call as for the U8glib Hello World example.
Then add pin numbers to M2tklib.

Oliver

Hi Oliver,
Thanks for the prompt reply.
I successfully ran the 'Hello World' example and got 'Hello World' on the bottom line of the display.
However when I run the 'User Input' tutorial my buttons initially did not work as expected. I can see the '1234' on the display but could not alter the numbers with the buttons.
I have since read further and found that the inputs respond to being pulled LOW. I rewired the buttons and they are now working OK.
I am now looking at the code to display menus and dialog boxes on a 84X48 display.

Great, let me know, if you have run into any other problems.

Oliver

Hi Oliver,

When I digg through the manual and code I start to feel very dumb. There are some things I just don't get.

// show screen with my A0 pin value
M2_LABEL(el_a0_label, NULL, "A0");
M2_U32NUM(el_a0_u32, "c4r1", &value_from_A0);
M2_ROOT(el_a0_ok, NULL, " ok ", &top_el_menu);
M2_LIST(list_a0) = { &el_a0_label, &el_a0_u32, &el_a0_ok };
M2_VLIST(el_a0_vlist, NULL, list_a0);
M2_ALIGN(top_el_a0, "-1|1W64H64", &el_a0_vlist);

in M2_LABEL(el_a0_Label...
what is this el_a0_Label? It has not been declared. Maybe it is one of those c++ things I did not yet figure out.
Then my application does receive navtex messages and does measure air pressure and temprature. The menustructure is to navigate setup pages and to display the measurement data. So I was figuring that the menu would at some point execute a loop to keep filling the display wit the mesurement data. Exept for the callback function in the MenuX2L example I have not found a way to do that yet. Is the callback the best way or is there a better way to execute code that is not part of the menu?
Then I would like a status bar on top of the display. It wil show waht tle last received navtex message type is and should be visible in all menus. Is there a way to do that?

Cheers,

Jelbert

Hi

All good questions. Let me try to explain some of these m2tklib things.

I decided to let users define a static menu structure, which is located in flash-rom area at startup. Basically the menues are just global variables. To hide the complexity of these data structures, I invented macros (usually called elements in m2tklib).
Such a global variable is:

M2_LABEL(el_a0_label, NULL, "A0");

This macro gets expanded and will look like this:

label_strcture el_a0_label = { magic_argument, NULL, "A0" } PROGMEM_BLABLA;

So, el_a0_label is a variable name (in fact it is a structure). It will represent an element within m2tklib, which just displays a text ("A0" in this example). Usually you will need the address of this "element". In fact all other procedures or elements just expect the address:

M2_LIST(list_a0) = { &el_a0_label, &el_a0_u32, &el_a0_ok };

This defines a group of three elements (the label is the first element of that group) and calls this group "list_a0". So list_a0 is another variable name.

Conclusion: The first argument to any of the M2_xxx macros is a variable name.
For elements like M2_LABEL, use &, for M2_LIST variables just use the name without "&".

Please also have look here: Google Code Archive - Long-term storage for Google Code Project Hosting.

So I was figuring that the menu would at some point execute a loop to keep filling the display wit the mesurement data.

You can let m2tklib display the content of a global variable. Whenever you refresh the menu (m2.draw()), then m2tklib will take the value from that global variable. It is really like connecting your menu with some outside data: Whenever the value somewhere in the memory changes, m2tlib will display the current value (once updated with m2.draw())

Let us have a look at your example:

M2_U32NUM(el_a0_u32, "c4r1", &value_from_A0);

The menu will display the value of variable "value_from_A0". "value_from_A0" is a global variable. Whenever you put data into it, it will get displayed. For example like this:

void loop(void)
{
  value_from_A0 = get_adc_value_from_a0();
  m2.draw(); 
}

Whatever is measured via ADC gets shown in the menu.

Exept for the callback function in the MenuX2L example I have not found a way to do that yet. Is the callback the best way or is there a better way to execute code that is not part of the menu?

Another good question and i do not know the answer. It depends on your personal preference. There are two ways to display measured data:

  • global variables (as discussed above)
  • callback procedures

MenuX2L is not the only element which provides callback procedures. For example also all elements ending with M2_...FN() get their values from callback procedures. But also other elements like M2_COMBO expect a callback procedure. Let us solve the same problem from above with a callback procedure. We need to use M2_U32NUMFN (Google Code Archive - Long-term storage for Google Code Project Hosting.). It expects a callback procedure:

uint32_t u32numcb(m2_rom_void_p element, uint8_t msg, uint32_t val) {
  if ( msg == M2_U32_MSG_GET_VALUE )
   return get_adc_value_from_a0();
  return 0;
}
M2_U32NUM(el_a0_u32, "c4r1", u32numcb);

And the main loop will look like this:

void loop(void)
{
  m2.draw(); 
}

Might look simpler, but there is a drawback with the callback procedure: They might get called more than once during one call to "m2.draw()". For that reason i would suggest to start with the "global variable" approach.

Conclusion: There are two ways to display data in a menu:

  • connected global variables (prefered method)
  • values returned from global variables (optional, if you accept the drawbacks)

Then I would like a status bar on top of the display. It wil show waht tle last received navtex message type is and should be visible in all menus. Is there a way to do that?

No, there is not only one way but probably a many ways to do this :wink:

  1. Method: M2_COMBO
    M2_COMBO will display a string, given by an index number from a list of strings (here: navtex messages types). Mark this element as read-only ("r1" format option)
    Place this element at the beginning of each menu. Please note that you can reuse elements. Define it once , use it oftern.
    Also note, that you usuallly will need a "container" element like XYLIST. XYLIST will allow you to place M2_COMBO at specific xy position on the screen.

  2. Method: M2_LABELPTR
    Similar to M2_COMBO, but you have to copy the type name into a string buffer. M2_LABELPTR is already read-only, so "r1" is not required.

  3. Method: GLCD low level graphics commands
    You can always draw a string directly to the screen. Just ensure that menu and your low level output do not overlap. In this case you would use the GLCD string draw procedure to output the navtex message type. A tutorial on this topic is here: Google Code Archive - Long-term storage for Google Code Project Hosting.

  4. Method: M2_X2LMENU
    Thinkable, if you intend to build all menus just with X2LMENU (but this will restrict you a lot). In this case, just make the toplevel menu line of X2LMENU a callback procedure which returns a string with the name of the message type.

So, i will finish for now and I hope that i was able to clarify things a little bit.

Oliver

Hi Oliver,
I am making progress. I have got a menu on my display and can navigate with my buttons OK.
I am struggling how to figure out how to use the menu to display some buttons to perform some functions.
I want 1 button to increase a value and one to decrease it.
I have tried the following code...

#include "U8glib.h"
#include "M2tk.h"
#include "utility/m2ghu8g.h"

U8GLIB_PCD8544 u8g(7, 6, 4, 5, 3);  // SPI Com: SCK = 7, MOSI = 6, CS = 4, A0 = 5, Reset = 3

int bl = 9, blValue = 31;

uint8_t uiKeySelectPin = A4;
uint8_t uiKeyDownPin = A1;
uint8_t uiKeyUpPin = A2;
uint8_t uiKeyExitPin = A0;


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


// m2 object and constructor
M2tk m2(&top_el_menu, m2_es_arduino, m2_eh_4bs, m2_gh_u8g_bf);
//M2tk m2(&top_el_expandable_menu, m2_es_arduino_rotary_encoder, m2_eh_4bs, m2_gh_u8g_ffs);
//M2tk m2(&top_el_expandable_menu, m2_es_arduino, m2_eh_4bs, m2_gh_arduino_serial);


// 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[] = 
{
  { "Show IP", NULL },
  { ". Address etc", &top_el_menu },
  { ". Internet", &top_el_menu },
  { "Ping", &top_el_menu },
  { ". x.x.x.1", &top_el_menu },
  { ". x.x.x.254", &top_el_menu },
  { ". Enter IP", &top_el_menu },
  { "Set IP", NULL },
  { ". DHCP", &top_el_menu },
  { ". Manual", &top_el_menu },
  { "Display", NULL },
  { ". Backlight", &el_backlight_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,"l6F3e14W56",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,65,102,'\0');
M2_SPACE(el_space, "W1h1");
//M2_VSB(el_vsb, "l6W2r1", &m2_2lmenu_first, &m2_2lmenu_cnt);
M2_LIST(list_2lmenu) = { &el_2lmenu, &el_space };
M2_HLIST(el_hlist, NULL, list_2lmenu);
M2_ALIGN(top_el_menu, "-1|2W64H64", &el_hlist);




void fn_bl_up(m2_el_fnarg_p fnarg) {
  blValue = blValue + 32;
  analogWrite(9, blValue);
}
void fn_bl_down(m2_el_fnarg_p fnarg) {
  blValue = blValue - 32;
  analogWrite(9, blValue);
}

void fn_goto_main_menu(m2_el_fnarg_p fnarg)
{
  m2.setRoot(&top_el_menu);
}

void fn_goto_pwm_menu(m2_el_fnarg_p fnarg)
{
  //m2.setRoot(&el_backlight_menu);
}



M2_BUTTON(el_btn_bl_up, "x1y1", "+", fn_bl_up);
M2_BUTTON(el_btn_bl_down, "x15y1", "-", fn_bl_down);
M2_BUTTON(el_btn_ok, "x30y1", "OK", fn_goto_main_menu);
M2_LIST(list) = { &el_btn_bl_up, &el_btn_bl_down, &el_btn_ok };
M2_XYLIST(list_element, NULL, list);
M2_ALIGN(el_backlight_menu, "-1|2W64H64", &list_element);
//M2tk m2(&list_element, m2_es_arduino, m2_eh_2bs, m2_gh_u8g_bf);


//=================================================
// Draw procedure, Arduino Setup & Loop


void draw(void) {
  m2.draw();
}

void setup(void) {
  // Connect u8glib with m2tklib
  pinMode(bl, OUTPUT);
  analogWrite(bl, blValue); //turns on backlight   
  m2_SetU8g(u8g.getU8g(), m2_u8g_box_icon);

  // Assign u8g font to index 0
  m2.setFont(0, u8g_font_5x7r);
  //m2.setFont(0, u8g_font_04b_03r);
  // Assign icon font to index 3
  m2.setFont(3, u8g_font_m2icon_7);

  // Setup keys
  m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
  m2.setPin(M2_KEY_PREV, uiKeyUpPin);
  m2.setPin(M2_KEY_NEXT, uiKeyDownPin);
  m2.setPin(M2_KEY_EXIT, uiKeyExitPin);    
   
  /*
  m2.setPin(M2_KEY_SELECT, 7);
  m2.setPin(M2_KEY_ROT_ENC_A, 3);
  m2.setPin(M2_KEY_ROT_ENC_B, 4);
  */
}


void loop() {
  // menu management
  m2.checkKey();
  if ( m2.handleKey() != 0 ) {
    u8g.firstPage();  
    do {
      m2.checkKey();
      draw();
    } while( u8g.nextPage() );
  }
}

When I compile I get an error :
m2tk_menu_list:41: error: 'el_backlight_menu' was not declared in this scope
Could you please point out where I have gone wrong?

Thanks,
Don

'el_backlight_menu' is used before it is defined. This is a common problem in C and C++. Use a forward declaration and place the command
M2_EXTERN_ALIGN(el_backlight_menu);
next to
M2_EXTERN_ALIGN(top_el_menu);

See also: Google Code Archive - Long-term storage for Google Code Project Hosting.

Oliver

Hi Oliver,

Yes you clarified alot :slight_smile:

The data that I want to display on the screen is not just a global but it is a graph of measurement data. I could make this graph in a bitmap and then display it within the menu structure or, as what I was planning to do, draw it on the display with lowlevel commands.
As what I read about the menu this would maybe not work.
What do you think is the best aproach?

Cheers,

Jelbert