0

I have strange problem with u8glib library. I have code:

void void_Menu_draw_func_men()
{
  if ( menu_redraw_required != 0 ) {
   u8g.firstPage();
    do  {
     Menu_draw_func_men();
   } while( u8g.nextPage() );
   menu_redraw_required = 0;
  }
}

void Menu_draw_func_men()
{

  u8g.setFont(u8g_font_6x13);
  u8g.drawStr(30, 0, "Funkcje");
  u8g.drawStr(15, 15, "Zerowanie modulu");
  u8g.drawStr(15, 30, "Modul na max");
  if(menu_pos == 0){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(144); u8g.enableCursor(); u8g.setCursorPos(10,20);}
  if(menu_pos == 1){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(144); u8g.enableCursor(); u8g.setCursorPos(10,35);}
  u8g.setPrintPos(5, 50); u8g.print("R:  "); u8g.print(pot_R , 2); u8g.print("   L:  "); u8g.print(pot_L , 2);

  Serial.println("func md");//just for check...

}

And oled display shows only cursor and I can move that cursor as I change menu_pos value. But no letters or values are printed on screen. Only cursor...

If I copy and paste only code from void Menu_draw_func_men(); to other part of my program:

void void_Menu_draw_test_man()
{
  if ( menu_redraw_required != 0 ) {
   u8g.firstPage();
    do  {
     Menu_draw_test_man();
   } while( u8g.nextPage() );
   menu_redraw_required = 0;
  }
}
void Menu_draw_test_man()
{

  u8g.setFont(u8g_font_6x13);   //replace this dwo lines
  u8g.drawStr(0, 0, "wykonywanie tefsdfs man...");

}

Everything works perfect... I was trying to change void name, and I don't know where is problem... This is on Arduino Uno; I have 66% used of program memory, and 60% used of dynamic memory. Maybe you have some idea?...

1

Your void_Menu_draw_test_man() function checks menu_redraw_required

Does your other part of the program update that variable? Do you call void_Menu_draw_test_man() from the loop() function?

It may help if you show the complete code, rather than small segments, since there are variables, such as menu_redraw_required, which are not changed anywhere in what is visible.

Note also that u8glib is no longer updated in favor of u8g2

  • I will check u8g2 library, maybe my u8glib couse problem... – Jakub Dec 1 '17 at 8:53
  • about loops, I have while functions till i press back button, and then I back to main menu. It work fine – Jakub Dec 1 '17 at 9:14
0

menu_redraw_required is in every code segment, but all segments are in while loop, there is no chance to update menu_redraw_required in different part code... My code is quite big now... but, when I enter to Menu_draw_func_men(), cursor is turned on, I can move it. I also add Serial.print(); to be sure that I enter to this void Menu_draw_func_men();. And I have always receive in console, a confirmation.

This is how I enter to selected screen from main menu:

if (digitalRead(KEY_SELECT) == LOW)
  {
    in_mmenu = false;

    switch(menu_current)
    {
      case 0:
        menu_redraw_required = 1;
        key_choose();
        break;
      case 1:
        menu_redraw_required = 1;
        test_auto();
        break;
      case 2:
        menu_redraw_required = 1;
        test_man();
        break;
      case 3:
        menu_redraw_required = 1;
        pot_read_menu();
        break;
      case 4:
        menu_redraw_required = 1;
        other_options(); **//previously i was function_menu**
        break;
    }

All screen works properly on almost the same code, only last screen on menu have problem...

See pictures how it looks. I also add code to "wybor klucza" menu. Just print part. enter image description here

How I enter to void_Menu_draw... works fine in others screens. Just small part for entering methode.

 if(digitalRead(KEY_NEXT) == LOW)
{unit++; if(unit >= UNIT_ITEMS + 1)
{unit = 1;} 
menu_redraw_required = 1; void_Menu_draw_keyMenu(); delay(200);}

and

void void_Menu_draw_keyMenu()
{
  if ( menu_redraw_required != 0 ) {
   u8g.firstPage();
    do  {
     Menu_draw_keyMenu();
   } while( u8g.nextPage() );
   menu_redraw_required = 0;
  }
}
void Menu_draw_keyMenu()
{

  u8g.setFont(u8g_font_6x13);
  u8g.drawStr(30, 0, "Wybor klucza");
  u8g.drawStr(15, 15, "Zespol:  "); u8g.drawStr(60, 15, menu_unit_num[unit - 1]);
  u8g.drawStr(15, 30, "Numer mod:  ");  u8g.drawStr(78, 30, menu_mod_num[module - 1]);
  u8g.drawStr(8, 50, "Modul to 2 silniki!");
  if(menu_pos == 0 && in == false){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(144); u8g.enableCursor(); u8g.setCursorPos(10,20);}
  if(menu_pos == 1 && in == false){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(144); u8g.enableCursor(); u8g.setCursorPos(10,35);}
  if(menu_pos == 0 && in == true){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(148); u8g.enableCursor(); u8g.setCursorPos(110,20);}
  if(menu_pos == 1 && in == true){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(148); u8g.enableCursor(); u8g.setCursorPos(110,35);}

}

enter image description here

I show you 2 more codes. There are the same, this one void_Menu_draw_test_man works, this one Menu_other_options not. Notice that I change name from functions_men to other_option, just to be sure that name don't cause this issue. I aleso update u8glib to last version. I try use u8g2 library but i will have to change almost everything...

void test_man()
{
  menu_redraw_required = 1; void_Menu_draw_test_man();
  while(digitalRead(KEY_BACK) == HIGH)
  {
    if(digitalRead(KEY_PREV) == LOW){menu_pos = 1; menu_redraw_required = 1; void_Menu_draw_test_man(); delay(200);}
    if(digitalRead(KEY_NEXT) == LOW){menu_pos = 0; menu_redraw_required = 1; void_Menu_draw_test_man(); delay(200);}
  }
  menu_redraw_required = 1;
  u8g.disableCursor();
  in_mmenu = true;
}

void void_Menu_draw_test_man()
{
  if ( menu_redraw_required != 0 ) {
   u8g.firstPage();
    do  {
     Menu_draw_test_man();
   } while( u8g.nextPage() );
   menu_redraw_required = 0;
  }
}
void Menu_draw_test_man()
{

  u8g.setFont(u8g_font_6x13);
  u8g.drawStr(40, 0, "Funkcje");
  u8g.drawStr(15, 15, "Zerowanie modulu");
  u8g.drawStr(15, 30, "Modul na max");
  if(menu_pos == 0){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(144); u8g.enableCursor(); u8g.setCursorPos(10,20);}
  if(menu_pos == 1){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(144); u8g.enableCursor(); u8g.setCursorPos(10,35);}
  u8g.setPrintPos(5, 50); u8g.print("R:  "); u8g.print(pot_R , 2); u8g.print("   L:  "); u8g.print(pot_L , 2);

}

and second

void other_options()
{
  menu_redraw_required = 1; void_Menu_other_options();
  while(digitalRead(KEY_BACK) == HIGH)
  {
    if(digitalRead(KEY_PREV) == LOW){menu_pos = 1; menu_redraw_required = 1; void_Menu_other_options(); delay(200);}
    if(digitalRead(KEY_NEXT) == LOW){menu_pos = 0; menu_redraw_required = 1; void_Menu_other_options(); delay(200);}
  }
  menu_redraw_required = 1;
  u8g.disableCursor();
  in_mmenu = true;
}

void void_Menu_other_options()
{
  if ( menu_redraw_required != 0 ) {
   u8g.firstPage();
    do  {
     Menu_other_options();
   } while( u8g.nextPage() );
   menu_redraw_required = 0;
  }
}
void Menu_other_options()
{

  u8g.setFont(u8g_font_6x13);
  u8g.drawStr(40, 0, "Funkcje");
  u8g.drawStr(15, 15, "Zerowanie modulu");
  u8g.drawStr(15, 30, "Modul na max");
  if(menu_pos == 0){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(144); u8g.enableCursor(); u8g.setCursorPos(10,20);}
  if(menu_pos == 1){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(144); u8g.enableCursor(); u8g.setCursorPos(10,35);}
  u8g.setPrintPos(5, 50); u8g.print("R:  "); u8g.print(pot_R , 2); u8g.print("   L:  "); u8g.print(pot_L , 2);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.