Jomelo / LCDMenuLib2

Create a tree menu. Use it with different lcd types / console output / ssh console.
MIT License
251 stars 48 forks source link

Dynamic Parameter + Quit = No Scrolling #19

Closed AnoxySoftware closed 6 years ago

AnoxySoftware commented 6 years ago

It seems that when using an _LCDML_TYPE_dynParam with a function like this: LCDML_addAdvanced (8 , LCDML_0_1 , 2 , NULL, "" , menuSetBacklight, 0, _LCDML_TYPE_dynParam);

void menuSetTimeEnd(uint8_t line) {
  if (line == LCDML.MENU_getCursorPos()) {
    // make only an action when the cursor stands on this menuitem
    //check Button
    if(LCDML.BT_checkAny())  {
      if(LCDML.BT_checkEnter())  {
        if(LCDML.MENU_getScrollDisableStatus() == 0) {
          LCDML.MENU_disScroll();
        }
        else {
          LCDML.MENU_enScroll();
          //save data
        }
        // dosomething for example save the data or something else             
        LCDML.BT_resetEnter();
      }

      // This check have only an effekt when MENU_disScroll is set
      if(LCDML.BT_checkUp()) {

      }

      // This check have only an effekt when MENU_disScroll is set
      if(LCDML.BT_checkDown()){
    }              
  }

  char buf[20];
  sprintf_P(buf, PSTR("Test %i"), value);
  lcd.setCursor(1, line);
  lcd.print(buf);
}

If you enter that menu item, and hit the QUIT button, the menu is stuck, as the scrolling is disabled. The LCDML.BT_checkAny() doesn't fire with the Quit button, and the _LCDML_TYPE_dynParam menu type doesn't provide callbacks on function exit as regular menus.

I think a way to get the QUIT event is missing on the _LCDML_TYPE_dynParam

Jomelo commented 6 years ago

Yes, there is a bug.

I have modified your code to test it:

LCDML_addAdvanced (20 , LCDML_0_5       , 4  , NULL,          ""                 , menuSetBacklight, 0,             _LCDML_TYPE_dynParam);                     // NULL = no menu function
//...

void menuSetBacklight(uint8_t line) {
  if (line == LCDML.MENU_getCursorPos()) {
    // make only an action when the cursor stands on this menuitem
    //check Button
    if(LCDML.BT_checkAny())  {
      if(LCDML.BT_checkEnter())  {
        if(LCDML.MENU_getScrollDisableStatus() == 0) {
          LCDML.MENU_disScroll();
        }
        else {
          LCDML.MENU_enScroll();
          //save data
        }
        // dosomething for example save the data or something else             
        LCDML.BT_resetEnter();
      }

      // This check have only an effekt when MENU_disScroll is set
      if(LCDML.BT_checkUp()) {

      }

      // This check have only an effekt when MENU_disScroll is set
      if(LCDML.BT_checkDown()){
    }              
    }
  }
  uint8_t value = 2;

  char buf[20];
  sprintf_P(buf, PSTR("Test %i"), value);
  Serial.println(buf);

  //lcd.setCursor(1, line);
  //lcd.print(buf);
}
Jomelo commented 6 years ago

Should be fixed: https://github.com/Jomelo/LCDMenuLib2/releases/tag/v1.2.3

AnoxySoftware commented 6 years ago

Das war aber superschnell.

Vielen Dank. Gibt's irgendwo ein beispiel wie man das Menü aktivieren und de-aktivieren kann ? Ich benutze es i ein Projekt das Ich mache, und im Moment stelle ich das Menü ein und aus so:

void toggleMenu() {
  isOnMenu = !isOnMenu;
  if (isOnMenu) {
    LCDML.DISP_menuUpdate();
    LCDML.loop_menu();
    LCDML.MENU_goRoot();
  }
  else {
    LCDML.DISP_clear();
  }
}

Ist das Korrekt?

Jomelo commented 6 years ago

Kann man so machen.

Eigentlich reicht es, wenn man LCDML.loop_menu(); nicht mehr ausführt. Die Buttons lassen sich dann weiter verwenden.