// =====================================================================
//
// Output function
//
// =====================================================================

/* ******************************************************************** */
void lcdml_menu_clear()
/* ******************************************************************** */
{
  for(uint8_t i=0;i<15;i++) {
    Serial.println();
  }
}

/* ******************************************************************** */
void lcdml_menu_display()
/* ******************************************************************** */
{
  // init vars
  //uint8_t n_max = (LCDML.MENU_getChilds() >= _LCDML_DISP_rows) ? _LCDML_DISP_rows : (LCDML.MENU_getChilds());

  // update content
  // ***************
  if (LCDML.DISP_checkMenuUpdate() || LCDML.DISP_checkMenuCursorUpdate() ) {
    // clear menu
    // ***************
    LCDML.DISP_clear();

    Serial.println(F("==========================================="));
    Serial.println(F("================  Menu ===================="));
    Serial.println(F("==========================================="));

    // declaration of some variables
    // ***************
    // content variable
    char content_text[_LCDML_DISP_cols];  // save the content text of every menu element
    // menu element object
    LCDMenuLib2_menu *tmp;
    // some limit values
    uint8_t i = LCDML.MENU_getScroll();
    uint8_t maxi = (_LCDML_DISP_rows - _LCDML_DSIP_use_header) + i;
    uint8_t n = 0;

    // check if this element has children
    if ((tmp = LCDML.MENU_getDisplayedObj()) != NULL)
    {
      // Display a header with the parent element name
      if(_LCDML_DSIP_use_header > 0)
      {
        // only one line
        if(LCDML.MENU_getLayer() == 0)
        {
          // this text is displayed when no header is available
          Serial.println(F("Root Menu"));
        }
        else
        {
          // Display parent name
          LCDML_getContent(content_text, LCDML.MENU_getParentID());
          Serial.print(content_text);
          Serial.println();
        }        
      }

      // loop to display lines
      do
      {
        // check if a menu element has a condition and if the condition be true
        if (tmp->checkCondition())
        {
          // display cursor
          if (n == LCDML.MENU_getCursorPos())
          {
            Serial.print(F("(x) "));
          }
          else
          {
            Serial.print(F("( ) "));
          }

          // check the type off a menu element
          if(tmp->checkType_menu() == true)
          {
            // display normal content
            LCDML_getContent(content_text, tmp->getID());
            Serial.print(content_text);
          }
          else
          {
            if(tmp->checkType_dynParam()) {
              tmp->callback(n);
            }
          }

          Serial.println();

          // increment some values
          i++;
          n++;
        }
      // try to go to the next sibling and check the number of displayed rows
      } while (((tmp = tmp->getSibling(1)) != NULL) && (i < maxi));
    }
  }
}
