Go Down

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

olikraus

Hi

Quote
Is there a signed flavour of uint8_t?

This should be "int8_t".

Quote
Also, what is the purpose of calling "m2.checkKey();" multiple times within the main loop?

A call to "checkKey()" polls the values of the rotary encoder and the other keys. There is no interrupt based check of the rotary encoder, instead M2tklib requires as much calls to "checkKey()" as possible.

Quote
I'm also confused about how i pass a value back through the callback procedure. I was looking at the example code and i'm unsure how i would use that. Say for example i wanted to do a Serial.print(); of the current S8NUM value for el_u1.

You need to use global variables to pass values to a callback procedure (as you did correctly in the second code example).

This will do the print for each changed value:
Code: [Select]
uint8_t global_value = 0;

uint8_t u8_cb(m2_rom_void_p element, uint8_t msg, uint8_t val)
{
  if ( msg == M2_U8_MSG_SET_VALUE )
  {
    global_value = val;
    Serial.print(global_value);
  }
  return global_value;
}


Oliver

marijn

Hi,

For a project I use an old loran C navigator box with intergrated keypad. It has 20 keys in a 5x8 matrix, yes very inefficient.

How should I modify the library to be able to use a matrix keypad?
So if I look deeper into the code I should change m2_arduino_get_key in m2esarduino.c to return the messages on result of a keypress on my matrix keypad. Is that the only place where I should change the code?
Would it be possible to make extra messages for the numbers 0...9?

Cheers,

Marijn

olikraus

Hi

1) Extend the event source to generate the new events (M2_EP_MSG_KEY_1, M2_EP_MSG_KEY_2, ...)

2)  Introduce a new (corresponding) element msg, e.g. M2_EL_MSG_KEY_1
Extend one of the event handlers to process the new key event, for example extend
Code: [Select]
uint8_t m2_eh_4bs(m2_p ep, uint8_t msg, uint8_t arg1, uint8_t arg2)

Then add this code to the event handler (for each event):

Code: [Select]
  case M2_EP_MSG_KEY_1:
    m2_nav_prepare_fn_arg_parent_element(nav);
    m2_fn_arg_call(M2_EL_MSG_KEY_1); // assign the char
    return m2_nav_user_next(nav); // go to next position
   

3) Next step is to make the elements aware about the new element messages.
For example M2_TEXT would make sense here (m2eltext.c):

Extend the char processing function: M2_EL_FN_DEF(m2_el_char_fn)

Code: [Select]
  case M2_EL_MSG_KEY_1:
      cp = m2_get_char_ptr(fn_arg->nav);
      *cp = '1';
      return 1;


Of course: not tested...

Oliver

marijn

Thanks Oliver,

I will try to extend the lib that way.
The matrix keypad question was a RTFM problem   :smiley-red:
I used m2.SetKey to store the result of the matrix into the que.
I'm still amazed about this lib...
Cheers,

Jelbert


olikraus

Yes, it should be possible to use setKey() if you do not want to rewrite the event source.

Oliver

Go Up