void lcd_scroll_menu(const char* menuNameP, int8_t entryCount, entryNameCallback_t entryNameCallback, entryDetailsCallback_t entryDetailsCallback)
{
    if (lcd_lib_button_pressed)
		return;//Selection possibly changed the menu, so do not update it this cycle.

    if (lcd_lib_encoder_pos == ENCODER_NO_SELECTION)
        lcd_lib_encoder_pos = 0;

	static int16_t viewPos = 0;
	if (lcd_lib_encoder_pos < 0) lcd_lib_encoder_pos += entryCount * ENCODER_TICKS_PER_SCROLL_MENU_ITEM;
	if (lcd_lib_encoder_pos >= entryCount * ENCODER_TICKS_PER_SCROLL_MENU_ITEM) lcd_lib_encoder_pos -= entryCount * ENCODER_TICKS_PER_SCROLL_MENU_ITEM;

    uint8_t selIndex = uint16_t(lcd_lib_encoder_pos/ENCODER_TICKS_PER_SCROLL_MENU_ITEM);

    lcd_lib_clear();

    int16_t targetViewPos = selIndex * 8 - 15;

    int16_t viewDiff = targetViewPos - viewPos;
    viewPos += viewDiff / 4;
    if (viewDiff > 0) { viewPos ++; led_glow = led_glow_dir = 0; }
    if (viewDiff < 0) { viewPos --; led_glow = led_glow_dir = 0; }

    uint8_t drawOffset = 10 - (uint16_t(viewPos) % 8);
    uint8_t itemOffset = uint16_t(viewPos) / 8;
    for(uint8_t n=0; n<6; n++)
    {
        uint8_t itemIdx = n + itemOffset;
        if (itemIdx >= entryCount)
            continue;

        char* ptr = entryNameCallback(itemIdx);
		//ptr[10] = '\0';
		ptr[20] = '\0';
        if (itemIdx == selIndex)
        {
            //lcd_lib_set(3, drawOffset+8*n-1, 62, drawOffset+8*n+7);
            lcd_lib_set(3, drawOffset+8*n-1, 124, drawOffset+8*n+7);
            lcd_lib_clear_string(4, drawOffset+8*n, ptr);
        }else{
            lcd_lib_draw_string(4, drawOffset+8*n, ptr);
        }
    }
    lcd_lib_set(3, 0, 124, 8);
    lcd_lib_clear(3, 47, 124, 63);
    lcd_lib_clear(3, 9, 124, 9);

    lcd_lib_draw_hline(3, 124, 48);

    lcd_lib_clear_string_centerP(1, menuNameP);
    
	entryDetailsCallback(selIndex);
	
    lcd_lib_update_screen();
}
void lcd_info_screen(menuFunc_t cancelMenu, menuFunc_t callbackOnCancel, const char* cancelButtonText)
{
    if (lcd_lib_encoder_pos != ENCODER_NO_SELECTION)
    {
        if (lcd_lib_encoder_pos < 0)
            lcd_lib_encoder_pos += 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
        if (lcd_lib_encoder_pos >= 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM)
            lcd_lib_encoder_pos -= 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
    }
    if (lcd_lib_button_pressed && IS_SELECTED_MAIN(0))
    {
        if (callbackOnCancel) callbackOnCancel();
        if (cancelMenu) lcd_change_to_menu(cancelMenu);
    }

    lcd_basic_screen();

    if (!cancelButtonText) cancelButtonText = PSTR("CANCEL");
    if (IS_SELECTED_MAIN(0))
    {
        lcd_lib_draw_box(3+2, 49+2, 125-2, 63-2);
        lcd_lib_set(3+3, 49+3, 125-3, 63-3);
        lcd_lib_clear_stringP(65 - strlen_P(cancelButtonText) * 3, 53, cancelButtonText);
    }else{
        lcd_lib_draw_stringP(65 - strlen_P(cancelButtonText) * 3, 53, cancelButtonText);
    }
}
void lcd_info_screen(menuFunc_t cancelMenu, menuFunc_t callbackOnCancel, const char* cancelButtonText, uint8_t direction)
{
  lcd_lib_encoder_pos = 0;

  if (lcd_lib_button_pressed && IS_SELECTED_MAIN(0))
  {
    if (cancelMenu) lcd_change_to_menu(cancelMenu,MAIN_MENU_ITEM_POS(0), direction);
    if (callbackOnCancel) callbackOnCancel();
  }

  lcd_basic_screen();

  if (!cancelButtonText) cancelButtonText = LS(PSTR("CANCEL"),
                                               PSTR("\xD8" "\x80"  "\xD9" "\x80"  ),
                                               PSTR("\xFF" "\x82"  "\xC6" "\x82"  )) ;
  
  

  switch (languageType) {
  case LANGUAGE_CHINESE:
  case LANGUAGE_KOREAN:
    if (IS_SELECTED_MAIN(0))
    {
      lcd_lib_draw_box(3+3, 54-3+1, 63+61-3, 64-1);
      lcd_lib_set(3+4, 54-3+2, 63+61-4, 64-2);
      lcd_lib_clear_stringP(65 - strlen_P(cancelButtonText) * 3, 56-3, cancelButtonText);
    }else{
      lcd_lib_draw_stringP(65 - strlen_P(cancelButtonText) * 3, 56-3, cancelButtonText);
    }
    break;
  case LANGUAGE_ENGLISH:
    if (IS_SELECTED_MAIN(0))
    {
      lcd_lib_draw_box(3+3, 54+1, 63+61-3, 64-1);
      lcd_lib_set(3+4, 54+2, 63+61-4, 64-2);
      lcd_lib_clear_stringP(65 - strlen_P(cancelButtonText) * 3, 56, cancelButtonText);
    }else{
      lcd_lib_draw_stringP(65 - strlen_P(cancelButtonText) * 3, 56, cancelButtonText);
    }
    break;
  default:
    break;
  }


}
void lcd_tripple_menu(const char* left, const char* right, const char* bottom)
{
    if (lcd_lib_encoder_pos != ENCODER_NO_SELECTION)
    {
        if (lcd_lib_encoder_pos < 0)
            lcd_lib_encoder_pos += 3*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
        if (lcd_lib_encoder_pos >= 3*ENCODER_TICKS_PER_MAIN_MENU_ITEM)
            lcd_lib_encoder_pos -= 3*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
    }

    lcd_lib_clear();
    lcd_lib_draw_vline(64, 5, 45);
    lcd_lib_draw_hline(3, 124, 48);

    if (IS_SELECTED_MAIN(0))
    {
        lcd_lib_draw_box(3+2, 5+2, 64-3-2, 45-2);
        lcd_lib_set(3+3, 5+3, 64-3-3, 45-3);
        lcd_lib_clear_string_center_atP(33, 22, left);
    }else{
        lcd_lib_draw_string_center_atP(33, 22, left);
    }

    if (IS_SELECTED_MAIN(1))
    {
        lcd_lib_draw_box(64+3+2, 5+2, 125-2, 45-2);
        lcd_lib_set(64+3+3, 5+3, 125-3, 45-3);
        lcd_lib_clear_string_center_atP(64 + 33, 22, right);
    }else{
        lcd_lib_draw_string_center_atP(64 + 33, 22, right);
    }

    if (bottom != NULL)
    {
        if (IS_SELECTED_MAIN(2))
        {
            lcd_lib_draw_box(3+2, 49+2, 125-2, 63-2);
            lcd_lib_set(3+3, 49+3, 125-3, 63-3);
            lcd_lib_clear_string_centerP(53, bottom);
        }else{
            lcd_lib_draw_string_centerP(53, bottom);
        }
    }
}
void lcd_question_screen(menuFunc_t optionAMenu, menuFunc_t callbackOnA, const char* AButtonText, menuFunc_t optionBMenu, menuFunc_t callbackOnB, const char* BButtonText)
{
    if (lcd_lib_encoder_pos != ENCODER_NO_SELECTION)
    {
        if (lcd_lib_encoder_pos < 0)
            lcd_lib_encoder_pos += 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
        if (lcd_lib_encoder_pos >= 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM)
            lcd_lib_encoder_pos -= 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
    }
    if (lcd_lib_button_pressed)
    {
        if (IS_SELECTED_MAIN(0))
        {
            if (callbackOnA) callbackOnA();
            if (optionAMenu) lcd_change_to_menu(optionAMenu);
        }else if (IS_SELECTED_MAIN(1))
        {
            if (callbackOnB) callbackOnB();
            if (optionBMenu) lcd_change_to_menu(optionBMenu);
        }
    }

    lcd_basic_screen();

    if (IS_SELECTED_MAIN(0))
    {
        lcd_lib_draw_box(3+2, 49+2, 64-2, 63-2);
        lcd_lib_set(3+3, 49+3, 64-3, 63-3);
        lcd_lib_clear_stringP(35 - strlen_P(AButtonText) * 3, 53, AButtonText);
    }else{
        lcd_lib_draw_stringP(35 - strlen_P(AButtonText) * 3, 53, AButtonText);
    }
    if (IS_SELECTED_MAIN(1))
    {
        lcd_lib_draw_box(64+2, 49+2, 64+60-2, 63-2);
        lcd_lib_set(64+3, 49+3, 64+60-3, 63-3);
        lcd_lib_clear_stringP(64+31 - strlen_P(BButtonText) * 3, 53, BButtonText);
    }else{
        lcd_lib_draw_stringP(64+31 - strlen_P(BButtonText) * 3, 53, BButtonText);
    }
}
void lcd_question_screen(menuFunc_t optionAMenu, menuFunc_t callbackOnA, const char* AButtonText, menuFunc_t optionBMenu, menuFunc_t callbackOnB, const char* BButtonText, uint8_t directionA, uint8_t directionB)
{
  if (lcd_lib_encoder_pos <= 0) {
    lcd_lib_encoder_pos=0;
  }
  else{
    lcd_lib_encoder_pos=1;
  }

  if (lcd_lib_button_pressed)
  {
    if (IS_SELECTED_MAIN(0))
    {
      if (optionAMenu) lcd_change_to_menu(optionAMenu,MAIN_MENU_ITEM_POS(0),directionA);
      if (callbackOnA) callbackOnA();
    }else if (IS_SELECTED_MAIN(1))
    {
      if (optionBMenu) lcd_change_to_menu(optionBMenu,MAIN_MENU_ITEM_POS(0),directionB);
      if (callbackOnB) callbackOnB();
    }
  }

  lcd_basic_screen();

  switch (languageType) {
  case LANGUAGE_CHINESE:
  case LANGUAGE_KOREAN:
    if (IS_SELECTED_MAIN(0))
    {
      lcd_lib_draw_box(3+3, 54-3+1, 63-3, 64-1);
      lcd_lib_set(3+4, 54-3+2, 63-4, 64-2);
      lcd_lib_clear_stringP(34 - strlen_P(AButtonText) * 3, 56-3, AButtonText);
    }else{
      lcd_lib_draw_stringP(34 - strlen_P(AButtonText) * 3, 56-3, AButtonText);
    }
    if (IS_SELECTED_MAIN(1))
    {
      lcd_lib_draw_box(3+61+3, 54-3+1, 63+61-3, 64-1);
      lcd_lib_set(3+61+4, 54-3+2, 63+61-4, 64-2);
      lcd_lib_clear_stringP(34+61 - strlen_P(BButtonText) * 3, 56-3, BButtonText);
    }else{
      lcd_lib_draw_stringP(34+61 - strlen_P(BButtonText) * 3, 56-3, BButtonText);
    }
    break;
  case LANGUAGE_ENGLISH:
    if (IS_SELECTED_MAIN(0))
    {
      lcd_lib_draw_box(3+3, 54+1, 63-3, 64-1);
      lcd_lib_set(3+4, 54+2, 63-4, 64-2);
      lcd_lib_clear_stringP(34 - strlen_P(AButtonText) * 3, 56, AButtonText);
    }else{
      lcd_lib_draw_stringP(34 - strlen_P(AButtonText) * 3, 56, AButtonText);
    }
    if (IS_SELECTED_MAIN(1))
    {
      lcd_lib_draw_box(3+61+3, 54+1, 63+61-3, 64-1);
      lcd_lib_set(3+61+4, 54+2, 63+61-4, 64-2);
      lcd_lib_clear_stringP(34+61 - strlen_P(BButtonText) * 3, 56, BButtonText);
    }else{
      lcd_lib_draw_stringP(34+61 - strlen_P(BButtonText) * 3, 56, BButtonText);
    }
    break;
  default:
    break;
  }



}