Pages: [1] 2   Go Down
Author Topic: Simple menu m2tklib with example.  (Read 3645 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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
Logged

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

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

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

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

Oliver
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad 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.

Logged

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

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The menu structure should be something like this:
Code:
#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.
Logged

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

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.

Code:
#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.
« Last Edit: March 25, 2013, 06:14:08 pm by olikraus » Logged

Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

There are 10 types of people. Those who understand binary, and those who don't.

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

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
Logged

Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


« Last Edit: April 09, 2013, 04:33:27 am by The_Don » Logged

There are 10 types of people. Those who understand binary, and those who don't.

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

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

Oliver
Logged

Pages: [1] 2   Go Up
Jump to: