Go Down

Topic: M2TKLIB - A User-Interface-Toolkit for the Arduino Hardware (Read 8 times) previous topic - next topic

olikraus

Hi

I have added the requested functionality: M2_COMBOPTR and M2_SPACECB

M2_COMBOPTR is identical to M2_COMBO except that the cnt (len) parameter now is a pointer to a 8-bit variable:

Code: [Select]


uint8_t comboptr_val = 0;
uint8_t comboptr_cnt = 3;
const char *comboptr_idx_to_color(uint8_t idx)
{
  if ( idx == 0 )
    return "red";
  else if (idx == 1 )
    return "green";
  return "blue";
}
M2_COMBOPTR(el_comboptr, NULL, &comboptr_val, &comboptr_cnt, comboptr_idx_to_color);
M2_ALIGN(top_el_comboptr_menu, "W64H64", &el_comboptr);


M2_SPACECB is identical to M2_SPACE except that a callback procedure will be called as soon as a new menu is rendered on the screen. This makes M2_SPACECB a suitable element that implements a single action for the 2LMENU. In the following example, the 2LMenu does not refer to other menues, but instead calls M2_SPACECB and its action procedures. These action procedures modify a 8 bit variable in the following example:

Code: [Select]

M2_EXTERN_ALIGN(top_el_spacecb_menu);
uint8_t el_space_u8 = 0;
void fn_space_cb_zero(m2_el_fnarg_p fnarg) {
  el_space_u8 = 0;
  m2_SetRootExtended(&top_el_spacecb_menu, 0, 0);
}
void fn_space_cb_inc(m2_el_fnarg_p fnarg) {
  puts("inc");
  el_space_u8++;
  m2_SetRootExtended(&top_el_spacecb_menu, 1, 0);
}
void fn_space_cb_dec(m2_el_fnarg_p fnarg) {
  el_space_u8--;
  m2_SetRootExtended(&top_el_spacecb_menu, 2, 0);
}
M2_SPACECB(el_space_cb_zero, NULL, fn_space_cb_zero);
M2_SPACECB(el_space_cb_inc, NULL, fn_space_cb_inc);
M2_SPACECB(el_space_cb_dec, NULL, fn_space_cb_dec);
m2_menu_entry space_cb_menu_data[] = {
  { "Zero", &el_space_cb_zero },
  { "Inc", &el_space_cb_inc },
  { "Dec", &el_space_cb_dec },
  { NULL, NULL },
};
uint8_t el_2lspace_first = 0;
uint8_t el_2lspace_cnt = 3;
M2_U8NUM(el_2lspace_u8, "r1c3", 0, 255, &el_space_u8);
M2_2LMENU(el_2lspace_strlist, "l3e15F3W47", &el_2lspace_first, &el_2lspace_cnt, space_cb_menu_data, 65, 102, '\0');
M2_LIST(list_2lspace_strlist) = { &el_2lspace_u8, &el_2lspace_strlist };
M2_VLIST(el_2lspace_hlist, NULL, list_2lspace_strlist);
M2_ALIGN(top_el_spacecb_menu, "-1|1W64H64", &el_2lspace_hlist);


M2tklib for GLCD attached. Let me know if other variants are needed.

Oliver

solo_joe

tested and perfect, this is what I needed.
I have trouble express my thoughts in english, very bad. :smiley-red:

Thanks you

Veco

Afternoon, is it possible for a user to input a negative number in the M2_U8NUM or U32NUM elements?

e.g.
Code: [Select]

M2_U8NUM(el_u1, "c2", -20, 80, &n1);


I'm just playing around with the Rotary Encoder example at the moment to get to grips with this.

I'm trying to get a user to select a target temperature for a heater/cooler combination that can range from -20c to 80c.

olikraus

Hi

Thanks for the request. I added issue 96 to the project for the implementation of M2_S8NUM.
It is almost finished:
Code: [Select]
M2_S8NUM(el_num_2, "+1c3", -128, 127, &s8num);

The new format option "+" controls visibibility of the "+" sign:
"+1": "+" is visible
"+0": "+" is not displayed

Let me know which m2tklib variant you need. I will add a prerelease here.

Oliver


Veco

Ooh, thank you.
I'm using the Liquid Crystal varient.

I spent a few hours today just playing around with menu's. i must say i'm impressed, this is perfect for my project.

Now, only if i could get my damn weird bouncy rotary encoder working well! Accidentally bought a ABC switch type one.

Go Up