Go Down

Topic: Menu for Display (Read 26347 times) previous topic - next topic


If i understand you correctly, then your question is, how to save memory?

Regarding m2tklib, here are some ideas:

- Format string
  * use NULL instead of ""
  * reuse format strings:
     instead of M2_ALIGN(top_el_sisu_m1, "W64H64", &el_sisu_grid_m1);
     do this:
Code: [Select]

char fmt_W64H64[] = "W64H64";
M2_ALIGN(top_el_sisu_m1, fmt_W64H64, &el_sisu_grid_m1);
     reuse the format string as often as possible
- Reuse elements: Once you have definde a BUTTON, you can reuse the button everywhere
  See also here: http://code.google.com/p/m2tklib/issues/detail?id=89
- Limit the number of different elements.

Maybe this gives some ideas. Please note, that a graphics library, such as u8glib will probably require more space than a LiquidCrystal



Ok :-) Thanks for the information,
I can use your suggest for the separator like /, :,
for the xy also :-)

Thanks you :-)


Mar 04, 2013, 12:04 pm Last Edit: Mar 04, 2013, 03:37 pm by gnusso Reason: 1
Hi Oliver, sorry if i disturb you again... so now after to have develop a lot's of code a take the confidence with your library Im in fill in a "Black Hole" ... Now I've did a menu for put all timers ...

Now i need to build a menu for view a data stored into my byte array[][] ... I've tried to use a label technique but due the fact the value are stored like byte ... is there another way for retrieve this value ? I don't remember how to assign the value to M2_U8NUM elements ...

for example with the menu below reported I stored the value inside my array
DEV: 00  WDay:   START
BATHRO  monda   10:00
ST:On          STOP:
       Ok bk       12:15
array[u8dev][0] = 00;
array[u8dev][20] = 2 (monday)
array[u8dev][19] = 1; (on)
array[u8dev][21] = 10; (hour start)
array[u8dev][22] = 00; (minutes start)
array[u8dev][23] = 12; (hour stop)
array[u8dev][24] = 15; (minutes stop)

now I would like the same menu with the same element that when I changed dev I see the value that I've put into the array but in readonly ... for see how i've set the timer ...

It's a couple of days that i put the head again this ... idea ?

thanks for the support,


Hi I've tried something like this :

const char *label_test(m2_rom_void_p element)

  char s[4];
  sprintf(s,  "%02d", array[u8dev][4]);
  Serial.println(s);   // or LCD.print(s);
  return s;

then call M2_LABELFN(el_v_Timer_test, "x3y1", label_test);

but in serial monitor the value change correctly but not into the menu ...



The code contains a programming error, use this:
Code: [Select]
const char *label_test(m2_rom_void_p element)
  static char s[4];
  sprintf(s,  "%02d", array[u8dev][4]);
  Serial.println(s);   // or LCD.print(s);
  return s;

Then, i would strongly suggest to read tutorial 8: http://code.google.com/p/m2tklib/wiki/t08



Thank you oliver now it's working :-) great ! thanks you ...

so using mega I've added more button because of course is more confortable like below:
Code: [Select]

     uint8_t uiKeySelectPin = 36; // Button: Select (Pin:36)
     uint8_t uiKeyNextPin = 38;   // Button: Next   (Pin:38)
     uint8_t uiKeyHomePin = 40;   // Button: Home   (Pin:40)
     uint8_t uiKeyDownPin = 42;   // Button: Prev   (Pin:42)

     m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
     m2.setPin(M2_KEY_NEXT, uiKeyNextPin);
     m2.setPin(M2_KEY_HOME, uiKeyHomePin);
     m2.setPin(M2_KEY_DATA_DOWN, uiKeyDownPin);

     M2tk m2(&m2_null_element, m2_es_arduino, m2_eh_4bs, m2_gh_lc);

So Home, next and select are working, but data down is not working ... could be useful because with select I can do a data up and select and with data down I can decrease the field without scan all range :-) is there a way how to fix that ?

Thanks for the support again :-)



Fix is easy: You need to use m2_eh_6bs instead of m2_eh_4bs handler. See the function reference manual.



Thanks you Oliver :-) How ever the best :-) !!!!

So Now I've did a View Menu timer where I re-use the label because they are in the same position:
Menu entry:

M2_LABEL(el_v_Timer_Specific_Start, fmt_x8y3, "START");
M2_U8NUM(el_v_Timer_Specific_Day_Start, fmt_x14y3c2, 1,31,&dt_day_start);
M2_LABEL(el_v_Timer_Specific_Sep_Start, fmt_x17y3b1, "/");
M2_U8NUM(el_v_Timer_Specific_Month_Start, fmt_x17y3c2, 1,12,&dt_month_start);
M2_LABEL(el_v_Timer_Specific_Stop, fmt_x9y1, "STOP");
M2_LABELFN(el_v_Timer_State_Specific, fmt_x3y1, label_w_state_specific);
M2_U8NUM(el_v_Timer_Specific_Day_Stop, fmt_x14y1c2, 0,31,&dt_day_stop);
M2_LABEL(el_v_Timer_Specific_Sep_Stop, fmt_x17y1b1, "/");
M2_U8NUM(el_v_Timer_Specific_Month_Stop, fmt_x17y1c2, 1,12,&dt_month_stop);
M2_COMBO(el_v_Timer_Specific_sa, fmt_x3y0r1,&select_priority, 2, fn_w_S_to_Apply_specific);
M2_BUTTON(el_dev_ok_timer, fmt_x7y0, "ok", dev_ok_button_timer);

M2_LIST(num_list_timer) = { &el_G_Timer, &el_G_Timer_dev, &el_v_Timer_Specific_Start,&el_v_Timer_Specific_Day_Start,&el_v_Timer_Specific_Sep_Start,&el_v_Timer_Specific_Month_Start,
M2_XYLIST(el_num_menu_timer, NULL,num_list_timer);

Menu View:

M2_LABELFN(el_v_Timer_lbl_SDayStart, fmt_x14y3c2, lbl_SDayStart);
M2_LABELFN(el_v_lbl_SMonthStart,     fmt_x17y3c2, lbl_SMonthStart);
M2_LABELFN(el_v_lbl_SHourStart,      fmt_x14y2c2, lbl_SHourStart);
M2_LABELFN(el_v_lbl_SMinuteStart,    fmt_x17y2c2, lbl_SMinuteStart);
M2_LABELFN(el_v_lbl_SDayStop,        fmt_x14y1c2, lbl_SDayStop);
M2_LABELFN(el_v_lbl_SMonthStop,      fmt_x17y1c2, lbl_SMonthStop);
M2_LABELFN(el_v_lbl_SHourStop,       fmt_x14y0c2, lbl_SHourStop);
M2_LABELFN(el_v_lbl_SMinuteStop,     fmt_x17y0c2, lbl_SMinuteStop);

M2_LIST(num_list_timer_view) = { &el_G_Timer, &el_G_Timer_dev, &el_v_Timer_Specific_Start,&el_v_Timer_lbl_SDayStart,&el_v_Timer_Specific_Sep_Start,&el_v_lbl_SMonthStart,
M2_XYLIST(el_num_menu_timer_view, NULL,num_list_timer_view);

The field are in the same position: but is happen a strange things the separator into view timer is missing,
is necessary like a M2_LABEL and is not possible to re-use it ?

Thanks for the information
gnux :-)


the separator into view timer is missing

I do not understand what you mean  :(
Is it a compiler error? If yes, please provide the full error message.



Ciao Oliver, if you look the code I've re-used this separator defined into menu entry timer in this way:

M2_LABEL(el_v_Timer_Specific_Sep_Start, fmt_x17y3b1, "/");
M2_LABEL(el_v_Timer_Specific_Sep_Stop, fmt_x17y1b1, "/");

Then I've re-use the two elements for the menu timer view:


the problem is that are not displayed and to be honest I don't understand why ...

Could you help kindly me ?



ok, got your point. I personally think that both seperator are overwritten by elements at the same position (x17y1 and x17y3).
For example:
M2_LABELFN(el_v_lbl_SMonthStart,     fmt_x17y3c2, lbl_SMonthStart);
M2_LABEL(el_v_Timer_Specific_Sep_Start, fmt_x17y3b1, "/");
If i interpret your fmt statement correctly, than both elements are at the same position.



Good Morning Oliver, it's true are into the same position, because in this way are optimized.

Also for the menu entry timer are in the same position but I have different results :-( ... So if change the view timer menu i can see what I've in mind but what i don't understand is I've the same result with a different positioning ... below reported the definition ... the fmt is correct your understanding ...

Menu Entry Timer:
Code: [Select]

M2_U8NUM(el_G_HourStart,        fmt_x14y2c2, 0,23,&dt_hour_start);   // - Re - use in all menu entry timers
M2_LABEL(el_G_Timer_Start_Sep, fmt_x17y2b1, ":");                   // - Re - use in all menu entry timers
M2_U8NUM(el_G_MinuteStart,      fmt_x17y2c2, 0,59, &dt_min_start); // - Re - use in all menu entry timers
M2_U8NUM(el_G_HourStop,          fmt_x14y0c2, 0,23,&dt_hour_stop);     // - Re - use in all menu entry timers
M2_LABEL(el_G_Timer_Stop_Sep,   fmt_x17y0b1, ":");                    // - Re - use in all menu entry timers
M2_U8NUM(el_G_MinStop,             fmt_x17y0c2, 0,59,&dt_min_stop);        // - Re - use in all menu entry timers

M2_U8NUM(el_v_Timer_Specific_Day_Start, fmt_x14y3c2, 1,31,&dt_day_start);
M2_LABEL(el_v_Timer_Specific_Sep_Start, fmt_x17y3b1, "/");
M2_U8NUM(el_v_Timer_Specific_Month_Start, fmt_x17y3c2, 1,12,&dt_month_start);
M2_U8NUM(el_v_Timer_Specific_Day_Stop, fmt_x14y1c2, 0,31,&dt_day_stop);
M2_LABEL(el_v_Timer_Specific_Sep_Stop, fmt_x17y1b1, "/");
M2_U8NUM(el_v_Timer_Specific_Month_Stop, fmt_x17y1c2, 1,12,&dt_month_stop);
//  End Menu Entry
//  Start Menu View Entry
M2_LABELFN(el_v_Timer_lbl_SDayStart, "x15y3c2",   lbl_SDayStart);
M2_LABELFN(el_v_lbl_SMonthStart,       "x18y3c2",   lbl_SMonthStart);
M2_LABELFN(el_v_lbl_SHourStart,         "x15y2c2",   lbl_SHourStart);
M2_LABELFN(el_v_lbl_SMinuteStart,       "x18y2c2",   lbl_SMinuteStart);
M2_LABELFN(el_v_lbl_SDayStop,            "x15y1c2",   lbl_SDayStop);
M2_LABELFN(el_v_lbl_SMonthStop,         "x18y1c2",   lbl_SMonthStop);
M2_LABELFN(el_v_lbl_SHourStop,           "x15y0c2",   lbl_SHourStop);
M2_LABELFN(el_v_lbl_SMinuteStop,         "x18y0c2",   lbl_SMinuteStop);

As you can note the position are different but at the end I've the same result ...

Now what I don't understand is why the same element with the same size on the display is necessary the use  in a different way ...

From the Top-Down metodologies I would like the same position in this way just change one position into fmt, otherwise I will specify a new fmt and then I will use for the menu view menu timer ...

just for understand and use it at the top :-) sorry if i did you maybe a trivial questions for you ...

thansk for the support,


It is difficult to understand your question. Maybe you could send the display results along with the code.
But in general: The x/y position of an element is not an absolute position. Instead, it is relative to the origin of the XY List. This could explain your different results.



Good Afternoon Oliver,
ok I have understand what you mean ... if i not understood bad depend in which kind situation and what you are using that time ... for example in the menu entry is a M2NUM element into viewer is a M2LABEL elements and is not true at 100% that are in the same position ... correct me if i wrong ,

thanks for your help,
have nice week end :-)


Good Morning Oliver,
Kindly could you tell me if is possible remove when i scroll the menu "black squares" on the right side ?

Thanks and have nice week end :-)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131