lorenzo906 / m2tklib

Automatically exported from code.google.com/p/m2tklib
0 stars 0 forks source link

Map same M2_KEY to more than one PIN #118

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When setting same M2_KEY twice, second overides the first one.

//buttons
m2_SetPin(M2_KEY_NEXT, PN(0, 7));
m2_SetPin(M2_KEY_PREV, PN(0, 6));   
m2_SetPin(M2_KEY_SELECT, PN(2, 0));  <-- first declaration

//encoder
m2_SetPin(M2_KEY_ROT_ENC_A, PN(2,1));
m2_SetPin(M2_KEY_ROT_ENC_B, PN(2,2));
m2_SetPin(M2_KEY_SELECT, PN(2, 3)); <-- second declaration

On this situation, only second declaration of M2_KEY_SELECT works when running 
code.

Original issue reported on code.google.com by robe...@protontec.net on 18 Oct 2013 at 1:28

GoogleCodeExporter commented 8 years ago
well, yes. You can only use one pin. 
hardware solution: Tie both buttons to the same pin. 
software solution: write your own event source:
If the event source is "uint8_t m2_es_arm_u8g(m2_p ep, uint8_t msg)"
then write:
uint8_t m2_es_private(m2_p ep, uint8_t msg)
{
  if ( msg == M2_ES_MSG_GET_KEY )
  {
    if ( your other pin has been pressed )
      return M2_KEY_SELECT;
  }
  return m2_es_arm_u8g(ep, msg)
}

Original comment by olikr...@gmail.com on 18 Oct 2013 at 6:01

GoogleCodeExporter commented 8 years ago
Thanks for the light! I did this:

### m2esavru8g.c ###

Included define for SELECT2
===========================
#define M2_KEY_SELECT2 15
#define M2_KEY_LOOP_END 15 //updated key loop

//#define M2_KEY_ANALOG 15 //comented out, since I dont use it

...
static void m2_avr_u8g_setup(void) 
{
  m2_avr_u8g_setup_key(M2_KEY_SELECT);
  m2_avr_u8g_setup_key(M2_KEY_SELECT2);
...
static uint8_t m2_avr_u8g_get_key(void)
{
  if ( m2_avr_u8g_check_key(M2_KEY_SELECT) ) return M2_KEY_SELECT;
  if ( m2_avr_u8g_check_key(M2_KEY_SELECT2) ) return M2_KEY_SELECT;
...
static void m2_avr_u8g_setup(void) 
{
  m2_avr_u8g_setup_key(M2_KEY_SELECT);
  m2_avr_u8g_setup_key(M2_KEY_SELECT2);

=============================================================================

on my project, keys/pins definitions went this way:
    //buttons
    m2_SetPin(M2_KEY_NEXT, PN(0, 7));
    m2_SetPin(M2_KEY_PREV, PN(0, 6));
    m2_SetPin(M2_KEY_SELECT2, PN(2, 0));

    //encoder
    m2_SetPin(M2_KEY_ROT_ENC_A, PN(2,1));
    m2_SetPin(M2_KEY_ROT_ENC_B, PN(2,2));
    m2_SetPin(M2_KEY_SELECT, PN(2, 3));

This is particularly useful when you need to have rotary encoder and keys 
working together/at same time. This way, user can set values either using 
rotary encoder or using switches.

Original comment by will...@curitiba.org on 18 Oct 2013 at 7:36

GoogleCodeExporter commented 8 years ago
ok, this could be done as an exception for the SELECT message.
Todo: Implement second SELECT pin

Original comment by olikr...@gmail.com on 18 Oct 2013 at 8:43

GoogleCodeExporter commented 8 years ago
M2_KEY_SELECT2 --> implemented, but needs testing (arduino M2_KEY_SELECT2)

ToDo: Testing

Original comment by olikr...@gmail.com on 2 Nov 2013 at 6:13

GoogleCodeExporter commented 8 years ago

Original comment by olikr...@gmail.com on 3 Nov 2013 at 6:12

GoogleCodeExporter commented 8 years ago
tested with Combo.pde --> all ok

Original comment by olikr...@gmail.com on 3 Nov 2013 at 6:31

GoogleCodeExporter commented 8 years ago
documentation done
closing this issue

Original comment by olikr...@gmail.com on 3 Nov 2013 at 6:37