lorenzo906 / m2tklib

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

Changing Key assignment depending on menu #140

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The m2.setPin function can only be called in setup().

If called in running programs all keys assigned will be jammed. It would be 
great if the assignment between m2tklib functions and input pins could be 
changed dynamically in the running program, as I need to assign different 
functions to the keys depending on the menu item shown on the display.

Original issue reported on code.google.com by Clemens....@physik.uni-halle.de on 28 Aug 2014 at 9:50

GoogleCodeExporter commented 8 years ago
Could the quick keys be an option? Quick keys are bound to M2_BUTTON elements 
directly. You could completly avoid next/prev/select buttons and create your 
menues only with the quick keys. Quick key behavior can be set for each menu 
individually.

Original comment by olikr...@gmail.com on 28 Aug 2014 at 10:49

GoogleCodeExporter commented 8 years ago
Thank you, that's a possible workaround. Unfortunately I have five keys that 
different assignment depending on menu but only four quick keys. Further there 
would always be the need to put the M2_BUTTONS somewhere (ok, I could hide them 
outside the screen).

My solution is to use the interrupt functions on the pins to call m2.setKey() 
with the respective argument for a certain menu. This gives me the possibility 
to use the comfort of your library and to assign extra functions outside the 
library.

Works well so far, if you have a controller with enough interrupts.

Original comment by Clemens....@physik.uni-halle.de on 29 Aug 2014 at 6:50

GoogleCodeExporter commented 8 years ago
Maybe another option is to use the change-root callback:
https://code.google.com/p/m2tklib/wiki/fnref#setRootChangeCallback

You could change the key assignment, based on the new root window. However, i 
have not tested this.

Oliver

Original comment by olikr...@gmail.com on 30 Aug 2014 at 5:05

GoogleCodeExporter commented 8 years ago
...
m2.setPin(M2_KEY_NEXT, uiKeyNextPin); 
m2.setPin(M2_KEY_Q1,   uiKeySelectPin);
...
M2_2LMENU(el_menu, "q1", &el_first, &el_cnt, menu_data, '+', '-', '\0');
...

Selects the first menu item no matter at what point is the focus.

Original comment by seriga...@gmail.com on 28 May 2015 at 8:20

GoogleCodeExporter commented 8 years ago
Maybe so?

extern M2tk m2;
M2_EXTERN_VLIST(el_home);
uint8_t m2_es_home(m2_p ep, uint8_t msg) 
{
  uint8_t key = m2_es_arduino(ep, msg);
  if ( M2_IS_KEY_EVENT(key) == 0 )
  {
     if ( key == M2_KEY_NONE )      return M2_KEY_NONE;
     if ( key == M2_KEY_HOME )      return M2_KEY_HOME;
     m2_rom_void_p carRoot = m2.getRoot();
     if (carRoot == &el_home)
     {
        if ( key == M2_KEY_DATA_UP )   return M2_KEY_DATA_UP;
        if ( key == M2_KEY_DATA_DOWN ) return M2_KEY_DATA_DOWN;
        if ( key == M2_KEY_SELECT )    return M2_KEY_NONE;
        return key;
     } 
     else
     {
        if ( key == M2_KEY_DATA_UP )   return M2_KEY_NEXT;
        if ( key == M2_KEY_DATA_DOWN ) return M2_KEY_PREV;
        if ( key == M2_KEY_SELECT )    return M2_KEY_SELECT;
        return key;
     } 
  } else return key;
}
M2tk m2(&el_home, m2_es_home, m2_eh_6bs, m2_gh_lc);
....
m2.setPin(M2_KEY_HOME,      uiKeyHomePin);  
m2.setPin(M2_KEY_DATA_UP,   uiKeyDataUpPin);
m2.setPin(M2_KEY_DATA_DOWN, uiKeyDataDownPin);
m2.setPin(M2_KEY_SELECT,    uiKeySelectPin); 
....

Original comment by seriga...@gmail.com on 28 May 2015 at 1:49

GoogleCodeExporter commented 8 years ago
M2tklib does not remember the previous position. However you could use the "v" 
option of the corresponding argument of the setRoot function to go to a 
specific position.

Original comment by olikr...@gmail.com on 29 May 2015 at 6:35