Germany
Offline
God Member
Karma: 69
Posts: 840
If you believe something is right, you won't see what's wrong (David Straker).
|
 |
« Reply #15 on: January 18, 2013, 01:46:44 pm » |
Hi M2tklib requires at least 2 buttons. Make sure that you use the correct event handler. With two buttons, the "2bs" handler. Existing event handler are described here http://code.google.com/p/m2tklib/wiki/fnref#M2tk. With M2tklib you can describe a dialog / user entry form. Such a form is composed of several elements. These elements have a hierarchie, including one element, which is the root element. In tutorial 2 ( http://code.google.com/p/m2tklib/wiki/t03) you see the following user entry form: void fn_ok(m2_el_fnarg_p fnarg) { /* do something with the number */ } M2_LABEL(el_label, NULL, "Num: "); M2_U32NUM(el_num, "a1c4", &number); M2_BUTTON(el_ok, "", " ok ", fn_ok); M2_LIST(list) = { &el_label, &el_num, &el_ok }; M2_HLIST(top_el_hlist, NULL, list);
The root element is "top_el_hlist", it contains "list" and list contains "el_label", "el_num" and "el_ok". So, basically it looks like this: HLIST - LABEL - U32NUM - BUTTON The toplevel element "top_el_hlist" is the most important element. If you want to display this complete dialog box, you must make the toplevel element "top_el_hlist" the so called "root" element. Making a toplevel element as a root element is just like jumping to this dialog box. There are several ways to make an element the root element: M2_ROOT or m2.setRoot() are two common options. The 2L-Menu element is another option to make other elements the root element. Just add the root element next to the menu title (including &). See the example pde. Oliver
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
God Member
Karma: 69
Posts: 840
If you believe something is right, you won't see what's wrong (David Straker).
|
 |
« Reply #16 on: January 18, 2013, 02:11:04 pm » |
Here is an example for a date entry dialog box: /*=========================================================================*/ /* edit date dialog */
uint8_t dt_day; uint8_t dt_month; uint8_t dt_year;
void dt_get_from_RTC(void) { RTC.getTime(); dt_day = RTC.day; dt_month = RTC.month; dt_year = (RTC.year-2000); }
void dt_put_to_RTC(void) { RTC.getTime(); RTC.fillByYMD(dt_year+2000, dt_month, dt_day); RTC.setTime(); RTC.startClock(); }
void dt_ok_fn(m2_el_fnarg_p fnarg) { dt_put_to_RTC(); m2.setRoot(&el_top); }
M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day); M2_LABEL(el_dt_sep1, NULL, "."); M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month); M2_LABEL(el_dt_sep2, NULL, "."); M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year);
M2_LIST(list_date) = { &el_dt_day, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_year }; M2_HLIST(el_date, NULL, list_date);
M2_ROOT(el_dt_cancel, NULL, "cancel", &el_top) M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_fn); M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok }; M2_HLIST(el_dt_buttons, NULL, list_dt_buttons);
M2_LIST(list_dt) = {&el_date, &el_dt_buttons }; M2_VLIST(el_top_dt, NULL, list_dt);
The "dt_put_to_RTC" procedure will be different for your, but the element hierarchy might be the same. The top level element is "el_top_dt". This means that your data for the 2L-Menu might look like this: m2_menu_entry m2_2lmenu_data[] = { { "Date/Time 1", NULL }, { ". Set Date 1-1", &el_top_dt }, ... { NULL, NULL }, };
The 2L-Menu is another element hierarchy. For example: M2_2LMENU(el_2lmenu,"l4F3e15W43",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,65,102,'\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);
The toplevel (root) element is "top_el_expandable_menu". Oliver
|
|
|
|
« Last Edit: January 18, 2013, 02:14:07 pm by olikraus »
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 363
|
 |
« Reply #17 on: January 19, 2013, 08:50:12 am » |
Hi Oliver, thanks now I try to do something and then i'll let you know :-)
gnux
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 363
|
 |
« Reply #18 on: January 19, 2013, 09:39:38 am » |
Ciao Oliver, I'm put all my self for try to manage at the best everything related to the menu ... at least im trying with effort :-) ... it pretty new for me ... So, from the theory stand-point I've understand the logical is a first step :-) at list i think/hope ... So what I've understood right now is: - That i can compose a form did with several elements - Each Elements have a hierarchy, including the root elements - The "Root Elements" contain other object --> List and list contain another 2 object: el_label,el_num so should be like this if I not understood bad: "top_el_hlist" --> list --> el_label --> el_num --> el_ok and in order to have a complete menu top_el_hlist must be at the TOP LEVEL. Now I've tried to play a little bit with the sketch below reported :-) I've just modify the menu with my label but I cannot call the event that I want ... and inside it put a code that I want ... So, playing with the sketch I've understand that in the last element of the menu that i choose I can set the value or do something if not understand bad ... So starting from this sketch, Could you kindly clean up the code in order to have only one menu with only one sub menu ... maybe the code will be more clear after :-) What do you think about that ? #include <LiquidCrystal.h> // ensure that the include path is set #include "M2tk.h"
//================================================= // Forward declaration of the toplevel element M2_EXTERN_HLIST(top_el_expandable_menu);
/*======================================================================*/ /* number entry */
uint8_t u8num = 0; uint32_t u32num = 0;
void fn_num_zero(m2_el_fnarg_p fnarg) { u8num = 0; u32num = 0; }
M2_LABEL(el_num_label1, NULL, "U8:"); M2_U8NUM(el_num_1, NULL, 0, 255, &u8num);
M2_LABEL(el_num_label2, NULL, "U32:"); M2_U32NUM(el_num_2, "c5", &u32num);
M2_BUTTON(el_num_zero, "f4", " zero ", fn_num_zero); M2_ROOT(el_num_goto_top, "f4", " back ", &top_el_expandable_menu);
M2_LIST(num_list) = { &el_num_label1, &el_num_1, &el_num_label2, &el_num_2, &el_num_zero, &el_num_goto_top };
M2_GRIDLIST(el_num_menu, "c2", num_list);
/*=========================================================================*/ /* edit date dialog */
uint8_t dt_day = 1; uint8_t dt_month = 1; uint8_t dt_year = 12;
void dt_ok_fn(m2_el_fnarg_p fnarg) { m2_SetRoot(&top_el_expandable_menu); }
M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year); M2_LABEL(el_dt_sep1, "b1", "-"); M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month); M2_LABEL(el_dt_sep2, "b1", "-"); M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day);
M2_LIST(list_date) = { &el_dt_year, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_day }; M2_HLIST(el_date, NULL, list_date);
M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu); M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_fn); M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok }; M2_HLIST(el_dt_buttons, NULL, list_dt_buttons);
M2_LIST(list_dt) = {&el_date, &el_dt_buttons }; M2_VLIST(el_top_dt, NULL, list_dt);
/*=========================================================================*/ /* radio */
uint8_t select_color = 0;
void fn_radio_ok(m2_el_fnarg_p fnarg) { /* accept selection */ m2_SetRoot(&top_el_expandable_menu); }
void fn_radio_cancel(m2_el_fnarg_p fnarg) { /* discard selection */ m2_SetRoot(&top_el_expandable_menu); }
M2_LABEL(el_radio_label1, NULL, "red"); M2_RADIO(el_radio_radio1, "v0", &select_color);
M2_LABEL(el_radio_label2, NULL, "green"); M2_RADIO(el_radio_radio2, "v1", &select_color);
M2_LABEL(el_radio_label3, NULL, "blue"); M2_RADIO(el_radio_radio3, "v2", &select_color);
M2_BUTTON(el_radio_cancel, NULL, "cancel", fn_radio_cancel); M2_BUTTON(el_radio_ok, NULL, "ok", fn_radio_ok);
M2_LIST(list_radio) = { &el_radio_label1, &el_radio_radio1, &el_radio_label2, &el_radio_radio2, &el_radio_label3, &el_radio_radio3, &el_radio_cancel, &el_radio_ok }; M2_GRIDLIST(top_el_radio, "c2",list_radio);
/*=========================================================================*/ /* combo */
uint8_t select_priority = 0;
void fn_combo_ok(m2_el_fnarg_p fnarg) { /* accept selection */ m2_SetRoot(&top_el_expandable_menu); }
void fn_combo_cancel(m2_el_fnarg_p fnarg) { /* discard selection */ m2_SetRoot(&top_el_expandable_menu); }
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_combo_label1, NULL, "Color:"); M2_COMBO(el_combo_combo1, NULL, &select_color, 3, fn_idx_to_color);
M2_LABEL(el_combo_label2, NULL, "Prio.: "); M2_COMBO(el_combo_combo2, "v1", &select_priority, 5, fn_idx_to_priority);
M2_BUTTON(el_combo_cancel, NULL, "cancel", fn_combo_cancel); M2_BUTTON(el_combo_ok, NULL, " ok ", fn_combo_ok);
M2_LIST(list_combo) = { &el_combo_label1, &el_combo_combo1, &el_combo_label2, &el_combo_combo2, &el_combo_cancel, &el_combo_ok }; M2_GRIDLIST(top_el_combo, "c2",list_combo);
/*=========================================================================*/ /* main 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[] = { { "Date/Time 1", NULL }, { ". Set Date 1-1", &el_num_menu }, { ". Set Time 1-2", &el_top_dt }, { ". View Date 1-3", &el_top_dt }, { ". View Time 1-4", &el_top_dt }, { "Radio", &top_el_radio }, { "Combo", &top_el_combo }, { 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 e1 = first column has a width of 1 char // Option w12 = second column has a width of 12 chars
M2_2LMENU(el_2lmenu,"l4e1w12",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0'); M2_VSB(el_vsb, "l4w1r1", &m2_2lmenu_first, &m2_2lmenu_cnt); M2_LIST(list_2lmenu) = { &el_2lmenu, &el_vsb }; M2_HLIST(top_el_expandable_menu, NULL, list_2lmenu);
// m2 object and constructor M2tk m2(&top_el_expandable_menu, m2_es_arduino_serial, m2_eh_4bs, m2_gh_arduino_serial);
void setup() { }
void loop() { m2.checkKey(); m2.checkKey(); if ( m2.handleKey() ) m2.draw(); m2.checkKey(); } thanks 10000 for the support !!! I very appreciate it Gnux
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
God Member
Karma: 69
Posts: 840
If you believe something is right, you won't see what's wrong (David Straker).
|
 |
« Reply #19 on: January 19, 2013, 10:20:32 am » |
Your menu is working great. Here is a log file with your menu and my key strokes ('s' and 'n'): m2tklib serial (press 'h' for help)
m2tklib LCD simulator
[+Date/Time 1 ] Radio Combo s [-Date/Time 1 ] Set Date 1-1 Set Time 1-2 View Date 1-3 n -Date/Time 1 [ Set Date 1-1 Set Time 1-2 View Date 1-3 n -Date/Time 1 Set Date 1-1 [ Set Time 1-2 View Date 1-3 s [12]- 01 - 01 cancel ok n 12 -[01]- 01 cancel ok s 12 -[02]- 01 cancel ok s 12 -[03]- 01 cancel ok n 12 - 03 -[01] cancel ok n 12 - 03 - 01 [cancel] ok n 12 - 03 - 01 cancel [ok] s [-Date/Time 1 ] Set Date 1-1 Set Time 1-2 View Date 1-3
Could you kindly clean up the code in order to have only one menu with only one sub menu ... Not sure if i understood you correctly, but you could simply remove most of the lines from the m2_menu_entry array: Instead of m2_menu_entry m2_2lmenu_data[] = { { "Date/Time 1", NULL }, { ". Set Date 1-1", &el_num_menu }, { ". Set Time 1-2", &el_top_dt }, { ". View Date 1-3", &el_top_dt }, { ". View Time 1-4", &el_top_dt }, { "Radio", &top_el_radio }, { "Combo", &top_el_combo }, { NULL, NULL }, }; use m2_menu_entry m2_2lmenu_data[] = { { "Date/Time 1", NULL }, { ". Set Date 1-1", &el_num_menu }, { NULL, NULL }, }; Of course you probably want to call the date entry if you pess the "set date" menu: m2_menu_entry m2_2lmenu_data[] = { { "Date/Time 1", NULL }, { ". Set Date 1-1", &el_top_dt }, { NULL, NULL }, }; Does this answer your question? Oliver
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 363
|
 |
« Reply #20 on: January 19, 2013, 10:49:53 am » |
So now im doing this Im checking the menu into serial monitor ...and in the meantime I'm see the part of the code for the sketch: for example: looking the standard example "Serial" the part "edit date dialog" there is this code: uint8_t dt_day = 1; uint8_t dt_month = 1; uint8_t dt_year = 12;
void dt_ok_fn(m2_el_fnarg_p fnarg) { m2_SetRoot(&top_el_expandable_menu); }
M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year); M2_LABEL(el_dt_sep1, "b1", "-"); M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month); M2_LABEL(el_dt_sep2, "b1", "-"); M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day);
M2_LIST(list_date) = { &el_dt_year, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_day }; M2_HLIST(el_date, NULL, list_date);
M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu); M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_fn); M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok }; M2_HLIST(el_dt_buttons, NULL, list_dt_buttons);
M2_LIST(list_dt) = {&el_date, &el_dt_buttons }; M2_VLIST(el_top_dt, NULL, list_dt);
with this output: in attachment . well starting from declaration uint8_t dt_day = 1; uint8_t dt_month = 1; uint8_t dt_year = 12; are ok initialize the date, no problem void dt_ok_fn(m2_el_fnarg_p fnarg) { m2_SetRoot(&top_el_expandable_menu); } is a function that want a variable "fnarg" declared ad "m2_el_fnarg_p" - Where is defined the type variable "m2_el_fnarg_p" ? Then this function call "m2_SetRoot" with "&top_el_expandable_menu" - Where are defined "m2_SetRoot"" and "&top_el_expandable_menu" ? Then after there is a sort of initialization, where do you set the separator date,how many years (0-99),how many months(1-12),how many day(1-31).So also here I don't know where are defined in which library i mean :-): Please correct me if i wrong because Im trying to understand :-) M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year); // M2_U8NUM where is defined ?el_dt_year ?, "C2" what means,0-99 is the range, &dt_year is the variable by ref . the same for the rest ... M2_LABEL(el_dt_sep1, "b1", "-"); M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month); M2_LABEL(el_dt_sep2, "b1", "-"); M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day); Next piece of code: M2_LIST(list_date) = { &el_dt_year, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_day }; M2_HLIST(el_date, NULL, list_date); M2_LIST(list_date) --> should be the function that display the current date set but also here you know which will be the question :-) M2_HLIST(el_date, NULL, list_date); --> should be the root for this menu ? which is the scope :-) next piece of code: M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu); --> Call something that bring you to the root ? M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_fn); --> Call something that confirm the date and bring you to root ? next piece of code: M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok }; M2_HLIST(el_dt_buttons, NULL, list_dt_buttons); M2_LIST(list_dt) = {&el_date, &el_dt_buttons }; M2_VLIST(el_top_dt, NULL, list_dt); So I think that my difficult is know the correct event to use and where use ... So thanks again for teaching me :-) it's important for me ... usually we I develop with .net is more simple because is graphically and you can search the function etc etc :-) thanks gnux
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
God Member
Karma: 69
Posts: 840
If you believe something is right, you won't see what's wrong (David Straker).
|
 |
« Reply #21 on: January 19, 2013, 12:22:59 pm » |
Hi Well, ".net". You have unlimited memory for data and code. But here on the Arduino... everything has to fit into a very small amount of RAM and ROM. In fact, M2tklib puts all of the elements into PROGMEM to save RAM area. This makes the menu definition look a little bit strange. void dt_ok_fn(m2_el_fnarg_p fnarg) { m2_SetRoot(&top_el_expandable_menu); } "m2_el_fnarg_p fnarg" can be ignored. But it is importent to have a proper function definition for the BUTTON callback, so for the BUTTON callback it must be there. There are some m2tklib procedures, which might get use of the fnarg pointer. This callback is described here: http://code.google.com/p/m2tklib/wiki/elref#BUTTON"m2_SetRoot(&top_el_expandable_menu);" is the C interface. It is fully equivalent to m2.setRoot(&top_el_expandable_menu). The set root procedure is described here: http://code.google.com/p/m2tklib/wiki/fnref#setRootM2_U8NUM(el_dt_year, "c2", 0,99,&dt_year); "c2" is the so called format string. It is described here: http://code.google.com/p/m2tklib/wiki/elref#Element_Format_StringThe format option "c", which is used here depends on the actual element. Overview is given here: http://code.google.com/p/m2tklib/wiki/elref#Overview. But in this case we have a unsigned 8 bit data entry field, which is described (along with the "c2" format option) here: http://code.google.com/p/m2tklib/wiki/elref#U8NUM. Especially the last link explains "c2": It tells the element to display two digits. "0,99" is the range (also described in the wiki) "&dt_year" is a reference to the variable, so that m2tklib can modify the variable directly. Any user input is directly written into this variable. M2_LIST(list_date) = { &el_dt_year, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_day }; M2_HLIST(el_date, NULL, list_date); M2_LIST is not an element. It defines a list for a container element. M2_HLIST is a container element. Elements refered in the corresponding list, are shown from left to right in a row. Again full description to gether with example is here: http://code.google.com/p/m2tklib/wiki/elref#HLISTM2_LIST and all other elements are macros (no function calls). They have all file local scope, but can be made global visible with the extern macro: M2_EXTERN_HLIST BTW: Is the documentation clearly enough? Or do you see some optimization? For sure there is some optimization possible, but probably i need some advice how to improve the documentation. M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu); --> Call something that bring you to the root ?
M2_ROOT appears as a push button. Once selected by the user it assignes the provided root element to the display. This makes top_el_expandable_menu visible to the user. M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_fn); --> Call something that confirm the date and bring you to root ? Same as M2_ROOT, but calls a procedure once selected. This is more flexible than M2_ROOT. Hope this clarifies things a little bit Oliver
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 363
|
 |
« Reply #22 on: January 20, 2013, 03:39:15 am » |
Hi Oliver :-) ,
smiling serenely because you are a very good teacher ... so I'm starting to entry into the mechanism :-) now it's more clear then before ... now I will try to modify the sketch in order to see if I have understood correctly and then I'll you know :-) ... so with your explanation it's more clear now ... the wiki and tutorial one time that you have take the confidence it's pratical :-) ... So, like my example ... before i need to understand the logical stand point and then one times that i have understood at least a little bit the logical stand point , i can start to play with a code :-) ... Then you're more able like a teacher ...
So now I try and i'll replay back :-)
regards, Gnux
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 363
|
 |
« Reply #23 on: January 20, 2013, 04:26:53 am » |
Good Morning Oliver again, so I've tried to do my first menu starting from the example. In attachment the screen shot of serial monitor. Iniside "SetDate 1-1" sub menu into button ok function I've put my function that call the root element if not understood bad and also call my function ... So, I cannot test RTC Function because I didn't install RTC again but seems correct ...What do you think ? here the code: #include <LiquidCrystal.h> // ensure that the include path is set #include "M2tk.h" #include <VirtualWire.h> #include <Wire.h>
// Forward declaration of the toplevel element M2_EXTERN_HLIST(top_el_expandable_menu);
/* edit date dialog */ uint8_t dt_day = 1; uint8_t dt_month = 1; uint8_t dt_year = 12; void SetDate() { Wire.beginTransmission(0x68); //1°st byte where i set registry write Wire.write((byte)0x00); //set date byte DayOfMonth = dt_day; //Wire.write((byte)0x01); //4° byte day of month Wire.write((byte)(DayOfMonth)); //5° byte GIORNO del mese da 0x00 a 0x31 byte Month = dt_month; Wire.write((byte)(Month)); //6° byte month between 0x00 and 0x12 byte Year = dt_year; Wire.write((byte)(Year)); //7° byte year between 0x00 a 0x99 Wire.endTransmission(); } void dt_ok_date(m2_el_fnarg_p fnarg) { m2_SetRoot(&top_el_expandable_menu); SetDate(); }
M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year); M2_LABEL(el_dt_sep1, "b1", "-"); M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month); M2_LABEL(el_dt_sep2, "b1", "-"); M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day);
M2_LIST(list_date) = { &el_dt_year, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_day }; M2_HLIST(el_date, NULL, list_date);
M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu); M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_date); M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok }; M2_HLIST(el_dt_buttons, NULL, list_dt_buttons);
M2_LIST(list_dt) = {&el_date, &el_dt_buttons }; M2_VLIST(el_top_dt, NULL, list_dt);
/* main menu */ m2_menu_entry m2_2lmenu_data[] = { { "Date/Time 1", NULL }, { ". SetDate 1-1", &el_top_dt }, { NULL, NULL }, };
uint8_t m2_2lmenu_first; uint8_t m2_2lmenu_cnt;
M2_2LMENU(el_2lmenu,"l4e1w12",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0'); M2_VSB(el_vsb, "l4w1r1", &m2_2lmenu_first, &m2_2lmenu_cnt); M2_LIST(list_2lmenu) = { &el_2lmenu, &el_vsb }; M2_HLIST(top_el_expandable_menu, NULL, list_2lmenu);
// m2 object and constructor M2tk m2(&top_el_expandable_menu, m2_es_arduino_serial, m2_eh_2bs, m2_gh_arduino_serial);
void setup() { Wire.begin(); }
void loop() { m2.checkKey(); m2.checkKey(); if ( m2.handleKey() ) m2.draw(); m2.checkKey(); }
So now the question is, how I can add another sub menu : ". SetTime 1-2 " ? So I've insight that now I think is necessary to proceed to define ... M2_LIST(list_time) and M2_HLIST(el_time, NULL, list_time); could be ? I hope to be a good students ... regards, gnux
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
God Member
Karma: 69
Posts: 840
If you believe something is right, you won't see what's wrong (David Straker).
|
 |
« Reply #24 on: January 20, 2013, 05:10:38 am » |
Hi So far your code seems quite ok. The callback procedure will store the date into the RTC once the ok button is pressed. For the time menu, you probably need to consider which elements are needed on your menu. If you need only hour and minutes than two U8NUM elements will do the job (similar to the data entry, but different ranges) Of course you will need again a cancel and an ok button. You can takeover the date code and transform it like this: M2_U8NUM(el_dt_hour, "c2", 0,23,&dt_hour); M2_LABEL(el_dt_c, "b1", ":"); M2_U8NUM(el_dt_min, "c2", 0,59,&dt_min);
M2_LIST(list_time) = { &el_dt_hour, &el_dt_c, &el_dt_min}; The rest should be almost identical to the date menu. Of course element and procedure names need to be renamend. Oliver Edit: Hour and Minute ranges
|
|
|
|
« Last Edit: January 20, 2013, 05:15:30 am by olikraus »
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 363
|
 |
« Reply #25 on: January 20, 2013, 06:36:15 am » |
Hi Oliver, so now I've tried to add the hours also, but I don't understand why doesn't store the hours ... should be correct from the code stand - point for you ? #include <LiquidCrystal.h> // ensure that the include path is set #include "M2tk.h" #include <VirtualWire.h> #include <Wire.h> #include <DS1307.h> #if defined(ARDUINO) && ARDUINO >= 100 #include "Arduino.h" #else #include "WProgram.h" #endif
// Forward declaration of the toplevel element M2_EXTERN_HLIST(top_el_expandable_menu);
/* edit date dialog */ uint8_t dt_day = 1; uint8_t dt_month = 1; uint8_t dt_year = 12; uint8_t dt_min = 1; uint8_t dt_hour = 1;
void dt_current() { Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true Serial.print(":"); Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false) Serial.print(":"); Serial.print(RTC.get(DS1307_SEC,false));//read seconds Serial.print(" "); // some space for a more happy life Serial.print(RTC.get(DS1307_DATE,false));//read date Serial.print("/"); Serial.print(RTC.get(DS1307_MTH,false));//read month Serial.print("/"); Serial.print(RTC.get(DS1307_YR,false)); //read year Serial.println(); }
void dt_get_from_RTC(void) { dt_day = RTC.get(DS1307_DATE,false); dt_month = RTC.get(DS1307_MTH,false); dt_year = (RTC.get(DS1307_YR,false)-2000); dt_min = RTC.get(DS1307_MIN,false); dt_hour = RTC.get(DS1307_HR,true); }
void dt_put_to_RTC(void) { RTC.set(DS1307_DATE,dt_day); RTC.set(DS1307_MTH,dt_month); RTC.set(DS1307_YR,dt_year); RTC.start(); }
void time_put_to_RTC(void) { RTC.set(DS1307_HR,dt_hour); RTC.set(DS1307_MIN,dt_min); RTC.start(); } void dt_ok_date(m2_el_fnarg_p fnarg) { dt_put_to_RTC(); m2_SetRoot(&top_el_expandable_menu); dt_current(); }
void dt_ok_time(m2_el_fnarg_p fnarg) { time_put_to_RTC(); m2_SetRoot(&top_el_expandable_menu); dt_current(); }
M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year); M2_LABEL(el_dt_sep1, "b1", "-"); M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month); M2_LABEL(el_dt_sep2, "b1", "-"); M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day);
M2_LIST(list_date) = { &el_dt_year, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_day }; M2_HLIST(el_date, NULL, list_date);
M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu); M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_date); M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok }; M2_HLIST(el_dt_buttons, NULL, list_dt_buttons);
M2_LIST(list_dt) = {&el_date, &el_dt_buttons }; M2_VLIST(el_top_dt, NULL, list_dt);
/* edit time */
M2_U8NUM(el_dt_hour, "c2", 0,23,&dt_hour); M2_LABEL(el_dt_c, "b1", ":"); M2_U8NUM(el_dt_min, "c2", 0,59,&dt_min);
M2_LIST(list_time) = { &el_dt_hour, &el_dt_c, &el_dt_min,&el_dt_cancel, &el_dt_ok}; M2_VLIST(el_top_time, NULL, list_time);
M2_BUTTON(el_dt_ok_tim, NULL, "ok", dt_ok_time);
/* main menu */ m2_menu_entry m2_2lmenu_data[] = { { "Date/Time 1", NULL }, { ". SetDate 1-1", &el_top_dt }, { ". SetTime 1-2", &el_top_time}, { NULL, NULL }, };
uint8_t m2_2lmenu_first; uint8_t m2_2lmenu_cnt;
M2_2LMENU(el_2lmenu,"l4e1w12",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0'); M2_VSB(el_vsb, "l4w1r1", &m2_2lmenu_first, &m2_2lmenu_cnt); M2_LIST(list_2lmenu) = { &el_2lmenu, &el_vsb }; M2_HLIST(top_el_expandable_menu, NULL, list_2lmenu);
// m2 object and constructor M2tk m2(&top_el_expandable_menu, m2_es_arduino_serial, m2_eh_2bs, m2_gh_arduino_serial);
void setup() { Wire.begin(); }
void loop() { m2.checkKey(); m2.checkKey(); if ( m2.handleKey() ) m2.draw(); m2.checkKey(); }
thx gnux
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 363
|
 |
« Reply #26 on: January 20, 2013, 06:48:08 am » |
Hi Oliver, so i was found a little issues inside a code ... now should be better but i still to have a issues ... i don't know why i cannot store the h: and minutes... and also on the menu appears only one element ... could you help kindly me ? #include <LiquidCrystal.h> // ensure that the include path is set #include "M2tk.h" #include <VirtualWire.h> #include <Wire.h> #include <DS1307.h> #if defined(ARDUINO) && ARDUINO >= 100 #include "Arduino.h" #else #include "WProgram.h" #endif
// Forward declaration of the toplevel element M2_EXTERN_HLIST(top_el_expandable_menu);
/* edit date dialog */ uint8_t dt_day = 1; uint8_t dt_month = 1; uint8_t dt_year = 12; uint8_t dt_min = 1; uint8_t dt_hour = 1;
void dt_current() { Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true Serial.print(":"); Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false) Serial.print(":"); Serial.print(RTC.get(DS1307_SEC,false));//read seconds Serial.print(" "); // some space for a more happy life Serial.print(RTC.get(DS1307_DATE,false));//read date Serial.print("/"); Serial.print(RTC.get(DS1307_MTH,false));//read month Serial.print("/"); Serial.print(RTC.get(DS1307_YR,false)); //read year Serial.println(); }
void dt_get_from_RTC(void) { dt_day = RTC.get(DS1307_DATE,false); dt_month = RTC.get(DS1307_MTH,false); dt_year = (RTC.get(DS1307_YR,false)-2000); dt_min = RTC.get(DS1307_MIN,false); dt_hour = RTC.get(DS1307_HR,true); }
void dt_put_to_RTC(void) { RTC.set(DS1307_DATE,dt_day); RTC.set(DS1307_MTH,dt_month); RTC.set(DS1307_YR,dt_year); RTC.start(); }
void time_put_to_RTC(void) { RTC.set(DS1307_HR,dt_hour); RTC.set(DS1307_MIN,dt_min); RTC.start(); } void dt_ok_date(m2_el_fnarg_p fnarg) { dt_put_to_RTC(); m2_SetRoot(&top_el_expandable_menu); dt_current(); }
void dt_ok_time(m2_el_fnarg_p fnarg) { time_put_to_RTC(); m2_SetRoot(&top_el_expandable_menu); dt_current(); }
M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year); M2_LABEL(el_dt_sep1, "b1", "-"); M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month); M2_LABEL(el_dt_sep2, "b1", "-"); M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day);
M2_LIST(list_date) = { &el_dt_year, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_day }; M2_HLIST(el_date, NULL, list_date);
M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu); M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_date); M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok }; M2_HLIST(el_dt_buttons, NULL, list_dt_buttons);
M2_LIST(list_dt) = {&el_date, &el_dt_buttons }; M2_VLIST(el_top_dt, NULL, list_dt);
/* edit time */
M2_U8NUM(el_dt_hour, "c2", 0,23,&dt_hour); M2_LABEL(el_dt_c, "b1", ":"); M2_U8NUM(el_dt_min, "c2", 0,59,&dt_min);
M2_BUTTON(el_dt_ok_time, NULL, "ok", dt_ok_time);
M2_LIST(list_time) = { &el_dt_hour, &el_dt_c, &el_dt_min,&el_dt_cancel, &el_dt_ok_time}; M2_VLIST(el_top_time, NULL, list_time);
/* main menu */ m2_menu_entry m2_2lmenu_data[] = { { "Date/Time 1", NULL }, { ". SetDate 1-1", &el_top_dt }, { ". SetTime 1-2", &el_top_time}, { NULL, NULL }, };
uint8_t m2_2lmenu_first; uint8_t m2_2lmenu_cnt;
M2_2LMENU(el_2lmenu,"l4e1w12",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0'); M2_VSB(el_vsb, "l4w1r1", &m2_2lmenu_first, &m2_2lmenu_cnt); M2_LIST(list_2lmenu) = { &el_2lmenu, &el_vsb }; M2_HLIST(top_el_expandable_menu, NULL, list_2lmenu);
// m2 object and constructor M2tk m2(&top_el_expandable_menu, m2_es_arduino_serial, m2_eh_2bs, m2_gh_arduino_serial);
void setup() { Wire.begin(); }
void loop() { m2.checkKey(); m2.checkKey(); if ( m2.handleKey() ) m2.draw(); m2.checkKey(); }
So now i go for a launch because i pass 5 hours in front off the pc ... So I've forget you to tell that i've connect RTC clock in the meantime :-) regards, Andrea
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
God Member
Karma: 69
Posts: 840
If you believe something is right, you won't see what's wrong (David Straker).
|
 |
« Reply #27 on: January 20, 2013, 07:26:22 am » |
The hierarchie for the date input is like this: VLIST HLIST U8NUM - year LABEL U8NUM - month LABEL U8NUM - day HLIST ROOT - cancel button BUTTON - ok button +-VLIST---------------------------------+ | | | +-HLIST----------------------------+ | | YYYY-MM-DD | | | +----------------------------------+ | | | +-HLIST----------------------------+ | | cancel ok | | | +----------------------------------+ | | +---------------------------------------+
The hierarchie is important. Nested lists are used to get the layout done. For the time dialog this is almost the same, but the upper HLIST needs to be exchanged (from a layout perspective). What you did is this: VLIST U8NUM - hour LABEL U8NUM - minutes ROOT - cancel BUTTON - ok The VLIST element renders everything from top to down. All in all the VLIST has a height of 5 rows, the upper most disapearing, because the LCD simulator only uses 4 rows (like your display also). You need the same structure with two horizontal lists like in the date dialog. Oliver
|
|
|
|
« Last Edit: January 20, 2013, 07:32:40 am by olikraus »
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 363
|
 |
« Reply #28 on: January 20, 2013, 09:28:14 am » |
Hi Oliver, I've adjust the code like your suggestion and now i think it's ... I've understand what you mean I thinks ... below reported the code ... I'll you know about the further develop ... #include <LiquidCrystal.h> // ensure that the include path is set #include "M2tk.h" #include <VirtualWire.h> #include <Wire.h> #include <DS1307.h> #if defined(ARDUINO) && ARDUINO >= 100 #include "Arduino.h" #else #include "WProgram.h" #endif
// Forward declaration of the toplevel element M2_EXTERN_HLIST(top_el_expandable_menu);
/* edit date dialog */ uint8_t dt_day = 1; uint8_t dt_month = 1; uint8_t dt_year = 12; uint8_t dt_min = 1; uint8_t dt_hour = 1;
void dt_current() { Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true Serial.print(":"); Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false) Serial.print(":"); Serial.print(RTC.get(DS1307_SEC,false));//read seconds Serial.print(" "); // some space for a more happy life Serial.print(RTC.get(DS1307_DATE,false));//read date Serial.print("/"); Serial.print(RTC.get(DS1307_MTH,false));//read month Serial.print("/"); Serial.print(RTC.get(DS1307_YR,false)); //read year Serial.println(); }
void dt_get_from_RTC(void) { dt_day = RTC.get(DS1307_DATE,false); dt_month = RTC.get(DS1307_MTH,false); dt_year = (RTC.get(DS1307_YR,false)-2000); dt_min = RTC.get(DS1307_MIN,false); dt_hour = RTC.get(DS1307_HR,true); }
void dt_put_to_RTC(void) { RTC.set(DS1307_DATE,dt_day); RTC.set(DS1307_MTH,dt_month); RTC.set(DS1307_YR,dt_year); RTC.start(); }
void time_put_to_RTC(void) { RTC.set(DS1307_HR,dt_hour); RTC.set(DS1307_MIN,dt_min); RTC.start(); } void dt_ok_date(m2_el_fnarg_p fnarg) { dt_put_to_RTC(); m2_SetRoot(&top_el_expandable_menu); dt_current(); }
void time_ok_button(m2_el_fnarg_p fnarg) { time_put_to_RTC(); m2_SetRoot(&top_el_expandable_menu); dt_current(); }
M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year); M2_LABEL(el_dt_sep1, "b1", "-"); M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month); M2_LABEL(el_dt_sep2, "b1", "-"); M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day);
M2_LIST(list_date) = { &el_dt_year, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_day }; M2_HLIST(el_date, NULL, list_date);
M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu); M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_date); M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok }; M2_HLIST(el_dt_buttons, NULL, list_dt_buttons);
M2_LIST(list_dt) = {&el_date, &el_dt_buttons }; M2_VLIST(el_top_dt, NULL, list_dt);
/* edit time ---------------------------------------------------------------------*/
M2_U8NUM(el_dt_hour, "c2", 0,23,&dt_hour); M2_LABEL(el_dt_c, "b1", ":"); M2_U8NUM(el_dt_min, "c2", 0,59,&dt_min);
M2_LIST(list_time) = { &el_dt_hour, &el_dt_c, &el_dt_min}; M2_HLIST(el_time, NULL, list_time);
M2_ROOT(el_time_cancel, NULL, "cancel", &top_el_expandable_menu); M2_BUTTON(el_time_ok, NULL, "ok", time_ok_button); M2_LIST(list_time_buttons) = {&el_time_cancel, &el_time_ok }; M2_HLIST(el_time_buttons, NULL, list_time_buttons);
M2_LIST(list_t) = {&el_time, &el_time_buttons}; M2_VLIST(el_top_time, NULL, list_t);
/* main menu */ m2_menu_entry m2_2lmenu_data[] = { { "Date/Time 1", NULL }, { ". SetDate 1-1", &el_top_dt }, { ". SetTime 1-2", &el_top_time}, { NULL, NULL }, };
uint8_t m2_2lmenu_first; uint8_t m2_2lmenu_cnt;
M2_2LMENU(el_2lmenu,"l4e1w12",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0'); M2_VSB(el_vsb, "l4w1r1", &m2_2lmenu_first, &m2_2lmenu_cnt); M2_LIST(list_2lmenu) = { &el_2lmenu, &el_vsb }; M2_HLIST(top_el_expandable_menu, NULL, list_2lmenu);
// m2 object and constructor M2tk m2(&top_el_expandable_menu, m2_es_arduino_serial, m2_eh_2bs, m2_gh_arduino_serial);
void setup() { Wire.begin(); }
void loop() { m2.checkKey(); m2.checkKey(); if ( m2.handleKey() ) m2.draw(); m2.checkKey(); }
thanks 1000000 for the support :-) enjoy the weekend, gnux
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
God Member
Karma: 69
Posts: 840
If you believe something is right, you won't see what's wrong (David Straker).
|
 |
« Reply #29 on: January 20, 2013, 10:00:54 am » |
Code looks quite good now. Let me know if you need more assistance.
Oliver
|
|
|
|
|
Logged
|
|
|
|
|
|