Hi,
I am using your great library to construct a menu system for reptile climate system I am designing.
After some initial troubles I believe I am on the right track now..
My display is a 192x64 bought of Ebay...
This is the code untill now:
#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;
uint8_t dt_day = 1;
uint8_t dt_month = 1;
uint8_t dt_year = 12;
uint8_t ti_hour = 1;
uint8_t ti_mins = 1;
uint8_t ti_secs = 12;
uint8_t li_sr_hour = 9;
uint8_t li_sr_mins = 0;
uint8_t li_rt_mins = 30;
uint8_t li_ss_hour = 20;
uint8_t li_ss_mins = 0;
uint8_t li_tl_hour = 2;
uint8_t li_tl_mins = 0;
uint8_t li_ft_mins = 30;
uint8_t th_d_temp = 22;
uint8_t th_n_temp = 18;
uint8_t th_d_humi = 70;
uint8_t th_n_humi = 75;
uint8_t th_b_temp = 5; // basking temp increase
//=================================================
// Forward declaration of the toplevel element
M2_EXTERN_ALIGN(top_el_expandable_menu);
//= Set date menu =
M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day);
M2_LABEL(el_dt_sep1, "b1", "/");
M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month);
M2_LABEL(el_dt_sep2, "b1", "/");
M2_LABEL(el_dt_sep3, "b1","20");
M2_U8NUM(el_dt_year, "c2", 12,99,&dt_year);
M2_LIST(list_date) = { &el_dt_day, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_sep3, &el_dt_year };
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);
//= Set time menu =
M2_U8NUM(el_ti_hour, "c2", 0,23,&ti_hour);
M2_LABEL(el_ti_sep1, "b1", ":");
M2_U8NUM(el_ti_mins, "c2", 0,59,&ti_mins);
M2_LABEL(el_ti_sep2, "b1", ":");
M2_U8NUM(el_ti_secs, "c2", 0,59,&ti_secs);
M2_LIST(list_time) = { &el_ti_hour, &el_ti_sep1, &el_ti_mins, &el_ti_sep2, &el_ti_secs };
M2_HLIST(el_time, NULL, list_time);
M2_ROOT(el_ti_cancel, NULL, "CANCEL", &top_el_expandable_menu);
M2_BUTTON(el_ti_ok, NULL, "OK", ti_ok_fn);
M2_LIST(list_ti_buttons) = {&el_ti_cancel, &el_ti_ok };
M2_HLIST(el_ti_buttons, NULL, list_ti_buttons);
M2_LIST(list_ti) = {&el_time, &el_ti_buttons };
M2_VLIST(el_top_ti, NULL, list_ti);
//= Set lighting menu
M2_LABEL(el_li_tit1,"b1", "Set sunrise : ");
M2_U8NUM(el_li_sr_hour, "c2", 0,23,&li_sr_hour);
M2_LABEL(el_li_sep1, "b1", ":");
M2_U8NUM(el_li_sr_mins, "c2", 0,59,&li_sr_mins);
M2_LIST(list_li_sr) = { &el_li_tit1, &el_li_sr_hour, &el_li_sep1, &el_li_sr_mins };
M2_HLIST(el_li1, NULL, list_li_sr);
M2_LABEL(el_li_tit2,"b1", "Set risetime : ");
M2_U8NUM(el_li_rt_mins, "c2", 1,59,&li_rt_mins);
M2_LIST(list_li_rt) = { &el_li_tit2, &el_li_rt_mins};
M2_HLIST(el_li2, NULL, list_li_rt);
M2_LABEL(el_li_tit3,"b1", "Set sunset : ");
M2_U8NUM(el_li_ss_hour, "c2", 0,23,&li_ss_hour);
M2_LABEL(el_li_ss_sep, "b1", ":");
M2_U8NUM(el_li_ss_mins, "c2", 0,59,&li_ss_mins);
M2_LIST(list_li_ss) = { &el_li_tit3, &el_li_ss_hour, &el_li_ss_sep, &el_li_ss_mins };
M2_HLIST(el_li3, NULL, list_li_ss);
M2_LABEL(el_li_tit4,"b1", "Set twilight : ");
M2_U8NUM(el_li_tl_hour, "c2", 0,23,&li_tl_hour);
M2_LABEL(el_li_tl_sep, "b1", ":");
M2_U8NUM(el_li_tl_mins, "c2", 0,59,&li_tl_mins);
M2_LIST(list_li_tl) = { &el_li_tit4, &el_li_tl_hour, &el_li_tl_sep, &el_li_tl_mins };
M2_HLIST(el_li4, NULL, list_li_tl);
M2_LABEL(el_li_tit5,"b1", "Set fadetime : ");
M2_U8NUM(el_li_ft_mins, "c2", 1,59,&li_ft_mins);
M2_LIST(list_li_ft) = { &el_li_tit5, &el_li_ft_mins};
M2_HLIST(el_li5, NULL, list_li_ft);
M2_LABEL(el_li_spacer,"b1", " ");
M2_ROOT(el_li_cancel, NULL, "CANCEL", &top_el_expandable_menu);
M2_LABEL(el_li_spacer2,"b1", " ");
M2_BUTTON(el_li_ok, NULL, "OK", li_ok_fn);
M2_LIST(list_li_buttons) = {&el_li_spacer, &el_li_cancel, &el_li_spacer2, &el_li_ok };
M2_HLIST(el_li_buttons, NULL, list_li_buttons);
M2_LIST(list_li) = {&el_li1, &el_li2, &el_li3, &el_li4, &el_li5, &el_li_buttons };
M2_VLIST(el_top_li, NULL, list_li);
// == Set temp & humidity
M2_LABEL(el_th_tit1,"b1", "Set day temperature : ");
M2_U8NUM(el_th_d_temp, "c2", 18,55,&th_d_temp);
M2_LABEL(el_th_unit1,"b1", "C");
M2_LIST(list_th_dt) = { &el_th_tit1, &el_th_d_temp, &el_th_unit1};
M2_HLIST(el_th1, NULL, list_th_dt);
M2_LABEL(el_th_tit2,"b1", "Set night temperature : ");
M2_U8NUM(el_th_n_temp, "c2", 15,55,&th_n_temp);
M2_LABEL(el_th_unit2,"b1", "C");
M2_LIST(list_th_nt) = { &el_th_tit2, &el_th_n_temp, &el_th_unit2};
M2_HLIST(el_th2, NULL, list_th_nt);
M2_LABEL(el_th_tit3,"b1", "Set day humidity : ");
M2_U8NUM(el_th_d_humi, "c2", 55,99,&th_d_humi);
M2_LABEL(el_th_unit3,"b1", "%");
M2_LIST(list_th_dh) = { &el_th_tit3, &el_th_d_humi, &el_th_unit3};
M2_HLIST(el_th3, NULL, list_th_dh);
M2_LABEL(el_th_tit4,"b1", "Set night humidity : ");
M2_U8NUM(el_th_n_humi, "c2", 55,99,&th_n_humi);
M2_LABEL(el_th_unit4,"b1", "%");
M2_LIST(list_th_nh) = { &el_th_tit4, &el_th_n_humi, &el_th_unit4};
M2_HLIST(el_th4, NULL, list_th_nh);
M2_LABEL(el_th_spacer,"b1", " ");
M2_ROOT(el_th_cancel, NULL, "CANCEL", &top_el_expandable_menu);
M2_LABEL(el_th_spacer2,"b1", " ");
M2_BUTTON(el_th_ok, NULL, "OK", th_ok_fn);
M2_LIST(list_th_buttons) = {&el_th_spacer, &el_th_cancel, &el_th_spacer2, &el_th_ok };
M2_HLIST(el_th_buttons, NULL, list_th_buttons);
M2_LIST(list_th) = {&el_th1, &el_th2, &el_th3, &el_th4, &el_th_buttons };
M2_VLIST(el_top_th, NULL, list_th);
// 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[] =
{
{ "Set time & date", &top_el_expandable_menu },
{ ". Set time", &el_top_ti },
{ ". Set date", &el_top_dt },
{ "Set temp & humidity", &el_top_th },
{ "Set lighting", &el_top_li },
{ "Review settings", &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,"l5e10W54",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0');
M2_SPACE(el_space, "W1h1");
M2_VSB(el_vsb, "l5W2r1", &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|1W192H64", &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 dt_ok_fn(m2_el_fnarg_p fnarg) {
m2_SetRoot(&top_el_expandable_menu);
}
void ti_ok_fn(m2_el_fnarg_p fnarg) {
m2_SetRoot(&top_el_expandable_menu);
}
void li_ok_fn(m2_el_fnarg_p fnarg) {
m2_SetRoot(&top_el_expandable_menu);
}
void th_ok_fn(m2_el_fnarg_p fnarg) {
m2_SetRoot(&top_el_expandable_menu);
}
I still have some issues though:
In the 'set lightning' menu I run out of space on my LCD... How (if any) can I add a scrollbar to this?
The last option in the main menu is to review all the settings. Here I want to list all the values I have entered in the previous menus.
So do I make a whole new label array or can I use the ones created before? and again... a scrollbar
Please let me know what you think of the code so far and any remarks/corrections you might have.
Thanks.