Simple menu m2tklib with example.

I would suggest to use low level graphics commands to display the measurement date.
Use M2_XYLIST() go get full controll of the placement of your buttons and other M2tklib elements.
Tutorial on low level graphics: Google Code Archive - Long-term storage for Google Code Project Hosting.

Oliver

Hi Oliver,
Thanks for your help so far. I have a much better understanding now.
My next issue is the size of the compiled code.
Is there any way to reduce the size of the compiled code as I have run out of memory.
I am using your m2tk and u8g libraries but I also need SPI, Ethernet and ICMPPing libraries. Once I have included those and written a few functions to use them, the compiled code is larger the the 32kB of my Arduino board.
Is it possible to cut from the library the functions I don't use, or is the compiler doing that by only compiling the functions that I call into my code?
I am not familiar with the workings of the compiler in this area.
Would it be simpler to use an Arduino based on a chip with with more memory?

Thanks,
Don =)

Hi

If you are working with the Arduino IDE, then unused procedures and data will be removed.
Both, u8glib and m2tklib, are already optimized for size. Here are some general ideas for the users of these libs:

  • Avoid large fonts in u8glib. Use fonts with end in "r". The size of the font in bytes is always given in the overview picture.
  • Only use a small number of fonts or only one font.
  • Do not use large functions like drawLine or drawCircle
  • Restrict yourself on a subset of elements in m2tklib: Maybe only use the XYLIST container.
  • Reuse the format option string
  • Reuse complete elements: For example a cancel button can be defined once and placed on all of the sub-menues.

Oliver

Hi Oliver. I'd like to see realtime values from sensor. For example, takes an A0.
I use a code, gived me early:

#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();
  }
}

So it works but. The values updates if i only push any buttons. Is any solution to see in real time any values?
Thx.