m2tklib

Hey everyone,
i am somehow frustrated using m2tklib to create a settings menu on a 12x2 character LCD.

Is there really no possibility to just create a scrollable list where every row is showing a value which i
can change directly by firing
M2_KEY_DATA_UP and M2_KEY_DATA_DOWN Events?

I tried so many things now but nothing works.
For example if I do it with strlist I can not know which list entry is focused at the moment.
If i could i could just change values on my encoder events and refresh the screen.

the next thing i tried was a big vertical list of numfields, the problem here is that you cannot scroll vlists and i only have 2 lines on my character display.

Isnt it the most common task to just have a list like this ?

value1 : 99
value2 : 33
[value3 : 72] <- this can be moved via M2_KEY_PREV and M2_KEY_NEXT
value4 : 22

and if there is a M2_KEY_DATA_UP or M2_KEY_DATA_DOWN Event the focused row data will be changed.

I d really appreciate help from anyone : )

best wishes,
flub

Indeed such a list is not there, however somehow close might be M2_X2LMENU if you spent some extra effort to create suitable callback functions for each entry.

Oliver

Thank you very much for the fast answer.
This is the example, but how can i know which menu is entry is focused? and how would i connect the DATA _UP and DATA_DOWN Events to trigger those xmenu_inc and xmenu_dec functions...

//=================================================
uint8_t value = 0;
char buf[20];

// define callback procedure, which returns a menu entry with a value
const char *xmenu_value(uint8_t idx, uint8_t msg)
{  
  if ( msg == M2_STRLIST_MSG_GET_STR ) {
    strcpy(buf, " Value: ");
    itoa((int)value, buf+strlen(buf), 10);
    return buf;
  }
  return "";
}

// define callback procedures which increment and decrement a value
const char *xmenu_inc(uint8_t idx, uint8_t msg) {
  if ( msg == M2_STRLIST_MSG_SELECT  ) {
      value++;
  }
  return "";
}

const char *xmenu_dec(uint8_t idx, uint8_t msg) {
  if ( msg == M2_STRLIST_MSG_SELECT  ) {
      value--;
  }
  return "";
}

//=================================================
// this is the overall menu structure for the X2L Menu

m2_xmenu_entry xmenu_data[] = 
{
  { "Menu 1", NULL, NULL },		/* expandable main menu entry */
  { ".", NULL, xmenu_value },		/* The label of this menu line is returned by the callback procedure */
  { ". Inc", NULL, xmenu_inc },		/* This callback increments the value */
  { ". Dec", NULL, xmenu_dec },		/* This callback decrements the value */
  { "Menu 2", NULL, NULL },
  { ". Sub 2-1", &top_el_mnu1_sel, NULL },
  { ". Sub 2-2", &top_el_mnu2_sel, NULL},
  { ". Sub 2-3", &top_el_mnu3_sel, NULL },
  { NULL, NULL, NULL },
};

My idea was to increment the value via select message. Decrement would not be possible. So your xmenu_value callback should also handle the select message and increment the value accordingly: This means you can navigate to the menue entry which has the xmenu_value callback attached and then press select to cycle through the values. Of course this makes only sense if the number of values is limited.

The initial idea of m2tk was not to have a scrollable list of editable values. Instead the idea was to have several independent pages with data entry fields.

Oliver

Okay, but Do you see a possibility to find out which row in a strlist is focused at the time?
as i only have two lines I only need to seperate between two idx (indexes) I get in a message of the strlist callback.
If there is a way to get a message for focused element everything would be possible. = )
Flo

Okay I found a way to get this message I had to edit two files of the library

In the file utilities/m2elstrlist.c

 ...
line 53
const char *m2_el_strlist_get_str(m2_rom_void_p element, uint8_t idx)
{
  return m2_el_strlist_cb_fnptr(element)(idx, M2_STRLIST_MSG_GET_STR);
}
/* HERE COMES MY EDIT */
const char *m2_el_strlist_focus(m2_rom_void_p element, uint8_t idx)
{
  return m2_el_strlist_cb_fnptr(element)(idx, M2_STRLIST_MSG_FOCUS);
}
/* HERE ENDS MY EDIT */

const char *m2_el_strlist_select(m2_rom_void_p element, uint8_t idx)
{
  return m2_el_strlist_cb_fnptr(element)(idx, M2_STRLIST_MSG_SELECT);
}
line 69
...

...
line 116 
    case M2_EL_MSG_NEW_FOCUS:
      /* adjust the top value, if required */
      m2_el_slbase_adjust_top_to_focus(parent_el, pos);
      /* HERE COMES MY EDIT */ 
      m2_el_strlist_focus(parent_el, pos);
      /* HERE ENDS MY EDIT */
      return 1;
line 121
...

and in the file utilities/m2.h

...
line 484
#define M2_STRLIST_MSG_GET_STR 101
#define M2_STRLIST_MSG_SELECT 102
#define M2_STRLIST_MSG_GET_EXTENDED_STR 103
#define M2_STRLIST_MSG_NEW_DIALOG 104
/* HERE COMES MY EDIT */ 
#define M2_STRLIST_MSG_FOCUS 105
/* HERE ENDS MY EDIT */ 
line 490
....

now i get the M2_STRLIST_MSG_FOCUS message in the strlist callback

thank you for the help! and the library of course... It must have been alot of work...!!