From 4ffb3d4136cec3419f10fd3156f1cd12337cfc0d Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Wed, 31 Mar 2021 15:16:12 -0300 Subject: [PATCH 1/4] delay u8glib init to avoid it trying to use uninitialised hardware --- Marlin/src/lcd/dogm/lcdprint_u8g.cpp | 28 ++--- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 102 +++++++++--------- Marlin/src/lcd/dogm/marlinui_DOGM.h | 9 +- Marlin/src/lcd/dogm/status_screen_DOGM.cpp | 58 +++++----- .../dogm/u8g_dev_tft_upscale_from_128x64.cpp | 2 +- Marlin/src/lcd/marlinui.cpp | 6 +- Marlin/src/lcd/menu/game/brickout.cpp | 12 +-- Marlin/src/lcd/menu/game/game.cpp | 6 +- Marlin/src/lcd/menu/game/invaders.cpp | 16 +-- Marlin/src/lcd/menu/game/maze.cpp | 18 ++-- Marlin/src/lcd/menu/game/snake.cpp | 20 ++-- 11 files changed, 141 insertions(+), 136 deletions(-) diff --git a/Marlin/src/lcd/dogm/lcdprint_u8g.cpp b/Marlin/src/lcd/dogm/lcdprint_u8g.cpp index a85dc9f97911..76c53b0855f3 100644 --- a/Marlin/src/lcd/dogm/lcdprint_u8g.cpp +++ b/Marlin/src/lcd/dogm/lcdprint_u8g.cpp @@ -20,36 +20,36 @@ #include "u8g_fontutf8.h" #include "../lcdprint.h" -int lcd_glyph_height() { return u8g_GetFontBBXHeight(u8g.getU8g()); } +int lcd_glyph_height() { return u8g_GetFontBBXHeight(u8g().getU8g()); } -void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { u8g.setPrintPos(col, row); } +void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { u8g().setPrintPos(col, row); } -void lcd_put_int(const int i) { u8g.print(i); } +void lcd_put_int(const int i) { u8g().print(i); } // return < 0 on error // return the advanced pixels int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) { if (c < 256) { - u8g.print((char)c); - return u8g_GetFontBBXWidth(u8g.getU8g()); + u8g().print((char)c); + return u8g_GetFontBBXWidth(u8g().getU8g()); } - u8g_uint_t x = u8g.getPrintCol(), y = u8g.getPrintRow(), - ret = uxg_DrawWchar(u8g.getU8g(), x, y, c, max_length); - u8g.setPrintPos(x + ret, y); + u8g_uint_t x = u8g().getPrintCol(), y = u8g().getPrintRow(), + ret = uxg_DrawWchar(u8g().getU8g(), x, y, c, max_length); + u8g().setPrintPos(x + ret, y); return ret; } int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) { - u8g_uint_t x = u8g.getPrintCol(), y = u8g.getPrintRow(), - ret = uxg_DrawUtf8Str(u8g.getU8g(), x, y, utf8_str, max_length); - u8g.setPrintPos(x + ret, y); + u8g_uint_t x = u8g().getPrintCol(), y = u8g().getPrintRow(), + ret = uxg_DrawUtf8Str(u8g().getU8g(), x, y, utf8_str, max_length); + u8g().setPrintPos(x + ret, y); return ret; } int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) { - u8g_uint_t x = u8g.getPrintCol(), y = u8g.getPrintRow(), - ret = uxg_DrawUtf8StrP(u8g.getU8g(), x, y, utf8_str_P, max_length); - u8g.setPrintPos(x + ret, y); + u8g_uint_t x = u8g().getPrintCol(), y = u8g().getPrintRow(), + ret = uxg_DrawUtf8StrP(u8g().getU8g(), x, y, utf8_str_P, max_length); + u8g().setPrintPos(x + ret, y); return ret; } diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index c2d2cf43af48..1eb495f8a37f 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -76,7 +76,11 @@ #define FONT_STATUSMENU_NAME MENU_FONT_NAME #endif -U8G_CLASS u8g(U8G_PARAM); +U8G_CLASS& u8g() +{ + static U8G_CLASS _u8g(U8G_PARAM); + return _u8g; +} #include LANGUAGE_DATA_INCL(LCD_LANGUAGE) @@ -86,7 +90,7 @@ U8G_CLASS u8g(U8G_PARAM); void MarlinUI::set_contrast(const int16_t value) { contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX); - u8g.setContrast(contrast); + u8g().setContrast(contrast); } #endif @@ -95,10 +99,10 @@ void MarlinUI::set_font(const MarlinFont font_nr) { static char currentfont = 0; if (font_nr != currentfont) { switch ((currentfont = font_nr)) { - case FONT_STATUSMENU : u8g.setFont(FONT_STATUSMENU_NAME); break; - case FONT_EDIT : u8g.setFont(EDIT_FONT_NAME); break; + case FONT_STATUSMENU : u8g().setFont(FONT_STATUSMENU_NAME); break; + case FONT_EDIT : u8g().setFont(EDIT_FONT_NAME); break; default: - case FONT_MENU : u8g.setFont(MENU_FONT_NAME); break; + case FONT_MENU : u8g().setFont(MENU_FONT_NAME); break; } } } @@ -129,15 +133,15 @@ bool MarlinUI::detected() { return true; } UNUSED(frame); - u8g.drawBitmapP(left, top, CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH, CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp); + u8g().drawBitmapP(left, top, CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH, CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp); #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED) if (frame == 0) { - u8g.setColorIndex(1); - if (top) u8g.drawBox(0, 0, LCD_PIXEL_WIDTH, top); - if (left) u8g.drawBox(0, top, left, CUSTOM_BOOTSCREEN_BMPHEIGHT); - if (right < LCD_PIXEL_WIDTH) u8g.drawBox(right, top, LCD_PIXEL_WIDTH - right, CUSTOM_BOOTSCREEN_BMPHEIGHT); - if (bottom < LCD_PIXEL_HEIGHT) u8g.drawBox(0, bottom, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT - bottom); + u8g().setColorIndex(1); + if (top) u8g().drawBox(0, 0, LCD_PIXEL_WIDTH, top); + if (left) u8g().drawBox(0, top, left, CUSTOM_BOOTSCREEN_BMPHEIGHT); + if (right < LCD_PIXEL_WIDTH) u8g().drawBox(right, top, LCD_PIXEL_WIDTH - right, CUSTOM_BOOTSCREEN_BMPHEIGHT); + if (bottom < LCD_PIXEL_HEIGHT) u8g().drawBox(0, bottom, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT - bottom); } #endif } @@ -158,8 +162,8 @@ bool MarlinUI::detected() { return true; } const uint8_t fr = _MIN(f, COUNT(custom_bootscreen_animation) - 1); const millis_t frame_time = pgm_read_word(&custom_bootscreen_animation[fr].duration); #endif - u8g.firstPage(); - do { draw_custom_bootscreen(f); } while (u8g.nextPage()); + u8g().firstPage(); + do { draw_custom_bootscreen(f); } while (u8g().nextPage()); if (frame_time) safe_delay(frame_time); } @@ -209,14 +213,14 @@ bool MarlinUI::detected() { return true; } NOLESS(offy, 0); auto _draw_bootscreen_bmp = [&](const uint8_t *bitmap) { - u8g.drawBitmapP(offx, offy, START_BMP_BYTEWIDTH, START_BMPHEIGHT, bitmap); + u8g().drawBitmapP(offx, offy, START_BMP_BYTEWIDTH, START_BMPHEIGHT, bitmap); set_font(FONT_MENU); if (!two_part || !line2) lcd_put_u8str_P(txt_offx_1, txt_base - (MENU_FONT_HEIGHT), PSTR(SHORT_BUILD_VERSION)); if (!two_part || line2) lcd_put_u8str_P(txt_offx_2, txt_base, PSTR(MARLIN_WEBSITE_URL)); }; auto draw_bootscreen_bmp = [&](const uint8_t *bitmap) { - u8g.firstPage(); do { _draw_bootscreen_bmp(bitmap); } while (u8g.nextPage()); + u8g().firstPage(); do { _draw_bootscreen_bmp(bitmap); } while (u8g().nextPage()); }; #if DISABLED(BOOT_MARLIN_LOGO_ANIMATED) @@ -269,7 +273,7 @@ void MarlinUI::init_lcd() { _delay_ms(5); WRITE(LCD_RESET_PIN, HIGH); _delay_ms(5); - u8g.begin(); + u8g().begin(); #endif #if PIN_EXISTS(LCD_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) @@ -278,9 +282,9 @@ void MarlinUI::init_lcd() { TERN_(HAS_LCD_CONTRAST, refresh_contrast()); - TERN_(LCD_SCREEN_ROT_90, u8g.setRot90()); - TERN_(LCD_SCREEN_ROT_180, u8g.setRot180()); - TERN_(LCD_SCREEN_ROT_270, u8g.setRot270()); + TERN_(LCD_SCREEN_ROT_90, u8g().setRot90()); + TERN_(LCD_SCREEN_ROT_180, u8g().setRot180()); + TERN_(LCD_SCREEN_ROT_270, u8g().setRot270()); uxg_SetUtf8Fonts(g_fontinfo, COUNT(g_fontinfo)); } @@ -288,14 +292,14 @@ void MarlinUI::init_lcd() { // The kill screen is displayed for unrecoverable conditions void MarlinUI::draw_kill_screen() { TERN_(LIGHTWEIGHT_UI, ST7920_Lite_Status_Screen::clear_text_buffer()); - const u8g_uint_t h4 = u8g.getHeight() / 4; - u8g.firstPage(); + const u8g_uint_t h4 = u8g().getHeight() / 4; + u8g().firstPage(); do { set_font(FONT_MENU); lcd_put_u8str(0, h4 * 1, status_message); lcd_put_u8str_P(0, h4 * 2, GET_TEXT(MSG_HALTED)); lcd_put_u8str_P(0, h4 * 3, GET_TEXT(MSG_PLEASE_RESET)); - } while (u8g.nextPage()); + } while (u8g().nextPage()); } void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop @@ -336,16 +340,16 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop if (sel) { #if ENABLED(MENU_HOLLOW_FRAME) - u8g.drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH); - u8g.drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH); + u8g().drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH); + u8g().drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH); #else - u8g.setColorIndex(1); // solid outline - u8g.drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, MENU_FONT_HEIGHT - 1); - u8g.setColorIndex(0); // inverted text + u8g().setColorIndex(1); // solid outline + u8g().drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, MENU_FONT_HEIGHT - 1); + u8g().setColorIndex(0); // inverted text #endif } #if DISABLED(MENU_HOLLOW_FRAME) - else u8g.setColorIndex(1); // solid text + else u8g().setColorIndex(1); // solid text #endif if (!PAGE_CONTAINS(row_y1, row_y2)) return false; @@ -388,7 +392,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char * const inStr, const bool pgm) { if (mark_as_selected(row, sel)) { const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen((char*)inStr)), - pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g.getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g.getU8g(), (char*)inStr)); + pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g().getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g().getU8g(), (char*)inStr)); pixel_len_t n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, LCD_WIDTH - 2 - vallen) * (MENU_FONT_WIDTH); if (vallen) { @@ -456,12 +460,12 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1; const pixel_len_t bw = len * prop * (MENU_FONT_WIDTH), bx = x * prop * (MENU_FONT_WIDTH); if (inv) { - u8g.setColorIndex(1); - u8g.drawBox(bx / prop - 1, by - (MENU_FONT_ASCENT) + 1, bw / prop + 2, MENU_FONT_HEIGHT - 1); - u8g.setColorIndex(0); + u8g().setColorIndex(1); + u8g().drawBox(bx / prop - 1, by - (MENU_FONT_ASCENT) + 1, bw / prop + 2, MENU_FONT_HEIGHT - 1); + u8g().setColorIndex(0); } lcd_put_u8str_P(bx / prop, by, pstr); - if (inv) u8g.setColorIndex(1); + if (inv) u8g().setColorIndex(1); } void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) { @@ -509,23 +513,23 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Clear the Mesh Map if (PAGE_CONTAINS(y_offset - 2, y_offset + y_map_pixels + 4)) { - u8g.setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box - u8g.drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4); + u8g().setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box + u8g().drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4); if (PAGE_CONTAINS(y_offset, y_offset + y_map_pixels)) { - u8g.setColorIndex(0); // Now actually clear the mesh map box - u8g.drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels); + u8g().setColorIndex(0); // Now actually clear the mesh map box + u8g().drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels); } } // Display Mesh Point Locations - u8g.setColorIndex(1); + u8g().setColorIndex(1); const u8g_uint_t sx = x_offset + pixels_per_x_mesh_pnt / 2; u8g_uint_t y = y_offset + pixels_per_y_mesh_pnt / 2; for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt) if (PAGE_CONTAINS(y, y)) for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt) - u8g.drawBox(x, y, 1, 1); + u8g().drawBox(x, y, 1, 1); // Fill in the Specified Mesh Point @@ -534,7 +538,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop const u8g_uint_t by = y_offset + y_plot_inv * pixels_per_y_mesh_pnt; if (PAGE_CONTAINS(by, by + pixels_per_y_mesh_pnt)) - u8g.drawBox( + u8g().drawBox( x_offset + x_plot * pixels_per_x_mesh_pnt, by, pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt ); @@ -542,7 +546,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Put Relevant Text on Display // Show X and Y positions at top of screen - u8g.setColorIndex(1); + u8g().setColorIndex(1); if (PAGE_UNDER(7)) { const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) }, lpos = pos.asLogical(); @@ -555,9 +559,9 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Print plot position if (PAGE_CONTAINS(LCD_PIXEL_HEIGHT - (INFO_FONT_HEIGHT - 1), LCD_PIXEL_HEIGHT)) { lcd_put_wchar(5, LCD_PIXEL_HEIGHT, '('); - u8g.print(x_plot); + u8g().print(x_plot); lcd_put_wchar(','); - u8g.print(y_plot); + u8g().print(y_plot); lcd_put_wchar(')'); // Show the location value @@ -686,15 +690,15 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop nozzle = TERN(USE_BIG_EDIT_FONT, 95, 60); // Draw nozzle lowered or raised according to direction moved - if (PAGE_CONTAINS( 3, 16)) u8g.drawBitmapP(nozzle + 6, 4 - dir, 2, 12, nozzle_bmp); - if (PAGE_CONTAINS(20, 20)) u8g.drawBitmapP(nozzle + 0, 20 , 3, 1, offset_bedline_bmp); + if (PAGE_CONTAINS( 3, 16)) u8g().drawBitmapP(nozzle + 6, 4 - dir, 2, 12, nozzle_bmp); + if (PAGE_CONTAINS(20, 20)) u8g().drawBitmapP(nozzle + 0, 20 , 3, 1, offset_bedline_bmp); // Draw cw/ccw indicator and up/down arrows. if (PAGE_CONTAINS(47, 62)) { - u8g.drawBitmapP(right + 0, 48 - dir, 2, 13, up_arrow_bmp); - u8g.drawBitmapP(left + 0, 49 - dir, 2, 13, down_arrow_bmp); - u8g.drawBitmapP(left + 13, 47 , 3, 16, rot_down); - u8g.drawBitmapP(right + 13, 47 , 3, 16, rot_up); + u8g().drawBitmapP(right + 0, 48 - dir, 2, 13, up_arrow_bmp); + u8g().drawBitmapP(left + 0, 49 - dir, 2, 13, down_arrow_bmp); + u8g().drawBitmapP(left + 13, 47 , 3, 16, rot_down); + u8g().drawBitmapP(right + 13, 47 , 3, 16, rot_up); } } diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.h b/Marlin/src/lcd/dogm/marlinui_DOGM.h index e3ceb63f96b5..9898ff3c3faf 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.h +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.h @@ -227,8 +227,9 @@ #endif // For selective rendering within a Y range -#define PAGE_OVER(ya) ((ya) <= u8g.getU8g()->current_page.y1) // Does the current page follow a region top? -#define PAGE_UNDER(yb) ((yb) >= u8g.getU8g()->current_page.y0) // Does the current page precede a region bottom? -#define PAGE_CONTAINS(ya, yb) ((yb) >= u8g.getU8g()->current_page.y0 && (ya) <= u8g.getU8g()->current_page.y1) // Do two vertical regions overlap? +#define PAGE_OVER(ya) ((ya) <= u8g().getU8g()->current_page.y1) // Does the current page follow a region top? +#define PAGE_UNDER(yb) ((yb) >= u8g().getU8g()->current_page.y0) // Does the current page precede a region bottom? +#define PAGE_CONTAINS(ya, yb) ((yb) >= u8g().getU8g()->current_page.y0 && (ya) <= u8g().getU8g()->current_page.y1) // Do two vertical regions overlap? -extern U8G_CLASS u8g; +// extern U8G_CLASS u8g; +extern U8G_CLASS& u8g(); diff --git a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp index 2ec462c34a23..e9b9a6c31292 100644 --- a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp +++ b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp @@ -268,12 +268,12 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co #if ENABLED(STATUS_HEAT_PERCENT) if (isHeat && tall <= BAR_TALL) { const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall; - u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, ph, HOTEND_BITMAP(heater_id, false)); - u8g.drawBitmapP(hx, STATUS_HEATERS_Y + ph, bw, tall + 1, HOTEND_BITMAP(heater_id, true) + ph * bw); + u8g().drawBitmapP(hx, STATUS_HEATERS_Y, bw, ph, HOTEND_BITMAP(heater_id, false)); + u8g().drawBitmapP(hx, STATUS_HEATERS_Y + ph, bw, tall + 1, HOTEND_BITMAP(heater_id, true) + ph * bw); } else #endif - u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(heater_id, isHeat)); + u8g().drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(heater_id, isHeat)); #endif } // PAGE_CONTAINS @@ -291,9 +291,9 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co _draw_centered_temp(temp, tx, 28); if (STATIC_HOTEND && HOTEND_DOT && PAGE_CONTAINS(17, 19)) { - u8g.setColorIndex(0); // set to white on black - u8g.drawBox(tx, 20 - 3, 2, 2); - u8g.setColorIndex(1); // restore black on white + u8g().setColorIndex(0); // set to white on black + u8g().drawBox(tx, 20 - 3, 2, 2); + u8g().setColorIndex(1); // restore black on white } } @@ -339,11 +339,11 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co if (isHeat) { const uint8_t bx = STATUS_BED_X + STATUS_BED_WIDTH; - u8g.drawFrame(bx, STATUS_HEATERS_Y, 3, STATUS_HEATERS_HEIGHT); + u8g().drawFrame(bx, STATUS_HEATERS_Y, 3, STATUS_HEATERS_HEIGHT); if (tall) { const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall; if (PAGE_OVER(STATUS_HEATERS_Y + ph)) - u8g.drawVLine(bx + 1, STATUS_HEATERS_Y + ph, tall); + u8g().drawVLine(bx + 1, STATUS_HEATERS_Y + ph, tall); } } @@ -364,9 +364,9 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co _draw_centered_temp(temp, tx, 28); if (STATIC_BED && BED_DOT && PAGE_CONTAINS(17, 19)) { - u8g.setColorIndex(0); // set to white on black - u8g.drawBox(tx, 20 - 2, 2, 2); - u8g.setColorIndex(1); // restore black on white + u8g().setColorIndex(0); // set to white on black + u8g().drawBox(tx, 20 - 2, 2, 2); + u8g().setColorIndex(1); // restore black on white } } @@ -562,13 +562,13 @@ void MarlinUI::draw_status_screen() { #if DO_DRAW_LOGO if (PAGE_CONTAINS(STATUS_LOGO_Y, STATUS_LOGO_Y + STATUS_LOGO_HEIGHT - 1)) - u8g.drawBitmapP(STATUS_LOGO_X, STATUS_LOGO_Y, STATUS_LOGO_BYTEWIDTH, STATUS_LOGO_HEIGHT, status_logo_bmp); + u8g().drawBitmapP(STATUS_LOGO_X, STATUS_LOGO_Y, STATUS_LOGO_BYTEWIDTH, STATUS_LOGO_HEIGHT, status_logo_bmp); #endif #if STATUS_HEATERS_WIDTH // Draw all heaters (and maybe the bed) in one go if (PAGE_CONTAINS(STATUS_HEATERS_Y, STATUS_HEATERS_Y + STATUS_HEATERS_HEIGHT - 1)) - u8g.drawBitmapP(STATUS_HEATERS_X, STATUS_HEATERS_Y, STATUS_HEATERS_BYTEWIDTH, STATUS_HEATERS_HEIGHT, status_heaters_bmp); + u8g().drawBitmapP(STATUS_HEATERS_X, STATUS_HEATERS_Y, STATUS_HEATERS_BYTEWIDTH, STATUS_HEATERS_HEIGHT, status_heaters_bmp); #endif #if DO_DRAW_CUTTER && DISABLED(STATUS_COMBINE_HEATERS) @@ -580,7 +580,7 @@ void MarlinUI::draw_status_screen() { const uint8_t cuttery = STATUS_CUTTER_Y(CUTTER_ALT()), cutterh = STATUS_CUTTER_HEIGHT(CUTTER_ALT()); if (PAGE_CONTAINS(cuttery, cuttery + cutterh - 1)) - u8g.drawBitmapP(STATUS_CUTTER_X, cuttery, STATUS_CUTTER_BYTEWIDTH, cutterh, CUTTER_BITMAP(CUTTER_ALT())); + u8g().drawBitmapP(STATUS_CUTTER_X, cuttery, STATUS_CUTTER_BYTEWIDTH, cutterh, CUTTER_BITMAP(CUTTER_ALT())); #endif #if DO_DRAW_BED && DISABLED(STATUS_COMBINE_HEATERS) @@ -592,7 +592,7 @@ void MarlinUI::draw_status_screen() { const uint8_t bedy = STATUS_BED_Y(BED_ALT()), bedh = STATUS_BED_HEIGHT(BED_ALT()); if (PAGE_CONTAINS(bedy, bedy + bedh - 1)) - u8g.drawBitmapP(STATUS_BED_X, bedy, STATUS_BED_BYTEWIDTH, bedh, BED_BITMAP(BED_ALT())); + u8g().drawBitmapP(STATUS_BED_X, bedy, STATUS_BED_BYTEWIDTH, bedh, BED_BITMAP(BED_ALT())); #endif #if DO_DRAW_CHAMBER && DISABLED(STATUS_COMBINE_HEATERS) @@ -604,7 +604,7 @@ void MarlinUI::draw_status_screen() { const uint8_t chambery = STATUS_CHAMBER_Y(CHAMBER_ALT()), chamberh = STATUS_CHAMBER_HEIGHT(CHAMBER_ALT()); if (PAGE_CONTAINS(chambery, chambery + chamberh - 1)) - u8g.drawBitmapP(STATUS_CHAMBER_X, chambery, STATUS_CHAMBER_BYTEWIDTH, chamberh, CHAMBER_BITMAP(CHAMBER_ALT())); + u8g().drawBitmapP(STATUS_CHAMBER_X, chambery, STATUS_CHAMBER_BYTEWIDTH, chamberh, CHAMBER_BITMAP(CHAMBER_ALT())); #endif #if DO_DRAW_FAN @@ -617,7 +617,7 @@ void MarlinUI::draw_status_screen() { } #endif if (PAGE_CONTAINS(STATUS_FAN_Y, STATUS_FAN_Y + STATUS_FAN_HEIGHT - 1)) - u8g.drawBitmapP(STATUS_FAN_X, STATUS_FAN_Y, STATUS_FAN_BYTEWIDTH, STATUS_FAN_HEIGHT, + u8g().drawBitmapP(STATUS_FAN_X, STATUS_FAN_Y, STATUS_FAN_BYTEWIDTH, STATUS_FAN_HEIGHT, #if STATUS_FAN_FRAMES > 2 fan_frame == 1 ? status_fan1_bmp : fan_frame == 2 ? status_fan2_bmp : @@ -660,7 +660,7 @@ void MarlinUI::draw_status_screen() { const uint8_t coolery = STATUS_COOLER_Y(status_cooler_bmp1), coolerh = STATUS_COOLER_HEIGHT(status_cooler_bmp1); if (PAGE_CONTAINS(coolery, coolery + coolerh - 1)) - u8g.drawBitmapP(STATUS_COOLER_X, coolery, STATUS_COOLER_BYTEWIDTH, coolerh, blink && cooler.enabled ? status_cooler_bmp2 : status_cooler_bmp1); + u8g().drawBitmapP(STATUS_COOLER_X, coolery, STATUS_COOLER_BYTEWIDTH, coolerh, blink && cooler.enabled ? status_cooler_bmp2 : status_cooler_bmp1); #endif // Laser Cooler Flow Meter @@ -668,7 +668,7 @@ void MarlinUI::draw_status_screen() { const uint8_t flowmetery = STATUS_FLOWMETER_Y(status_flowmeter_bmp1), flowmeterh = STATUS_FLOWMETER_HEIGHT(status_flowmeter_bmp1); if (PAGE_CONTAINS(flowmetery, flowmetery + flowmeterh - 1)) - u8g.drawBitmapP(STATUS_FLOWMETER_X, flowmetery, STATUS_FLOWMETER_BYTEWIDTH, flowmeterh, blink && cooler.flowpulses ? status_flowmeter_bmp2 : status_flowmeter_bmp1); + u8g().drawBitmapP(STATUS_FLOWMETER_X, flowmetery, STATUS_FLOWMETER_BYTEWIDTH, flowmeterh, blink && cooler.flowpulses ? status_flowmeter_bmp2 : status_flowmeter_bmp1); #endif @@ -709,13 +709,13 @@ void MarlinUI::draw_status_screen() { // if (card.isFileOpen() && PAGE_CONTAINS(42, 51)) { // Upper box - u8g.drawBox(42, 42, 8, 7); // 42-48 (or 41-47) + u8g().drawBox(42, 42, 8, 7); // 42-48 (or 41-47) // Right edge - u8g.drawBox(50, 44, 2, 5); // 44-48 (or 43-47) + u8g().drawBox(50, 44, 2, 5); // 44-48 (or 43-47) // Bottom hollow box - u8g.drawFrame(42, 49, 10, 4); // 49-52 (or 48-51) + u8g().drawFrame(42, 49, 10, 4); // 49-52 (or 48-51) // Corner pixel - u8g.drawPixel(50, 43); // 43 (or 42) + u8g().drawPixel(50, 43); // 43 (or 42) } #endif // SDSUPPORT @@ -725,14 +725,14 @@ void MarlinUI::draw_status_screen() { // if (PAGE_CONTAINS(PROGRESS_BAR_Y, PROGRESS_BAR_Y + 3)) - u8g.drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, 4); + u8g().drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, 4); // // Progress bar solid part // if (PAGE_CONTAINS(PROGRESS_BAR_Y + 1, PROGRESS_BAR_Y + 2)) - u8g.drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, 2); + u8g().drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, 2); if (PAGE_CONTAINS(EXTRAS_BASELINE - INFO_FONT_ASCENT, EXTRAS_BASELINE - 1)) { @@ -805,16 +805,16 @@ void MarlinUI::draw_status_screen() { #if DISABLED(XYZ_NO_FRAME) #if ENABLED(XYZ_HOLLOW_FRAME) - u8g.drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39 + u8g().drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39 #else - u8g.drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37 + u8g().drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37 #endif #endif if (PAGE_CONTAINS(XYZ_BASELINE - (INFO_FONT_ASCENT - 1), XYZ_BASELINE)) { #if NONE(XYZ_NO_FRAME, XYZ_HOLLOW_FRAME) - u8g.setColorIndex(0); // white on black + u8g().setColorIndex(0); // white on black #endif #if HAS_DUAL_MIXING @@ -859,7 +859,7 @@ void MarlinUI::draw_status_screen() { _draw_axis_value(Z_AXIS, zstring, blink); #if NONE(XYZ_NO_FRAME, XYZ_HOLLOW_FRAME) - u8g.setColorIndex(1); // black on white + u8g().setColorIndex(1); // black on white #endif } } diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp index 3842611fdf73..6b528b418ccb 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp @@ -522,7 +522,7 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, do { set_font(FONT_MENU); lcd_put_u8str(0, LCD_PIXEL_HEIGHT / 2, str); - } while (u8g.nextPage()); + } while (u8g().nextPage()); drawing_screen = false; safe_delay(250); if (calibration_stage == CALIBRATION_SUCCESS) { diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 4d457dc6aa01..cb4179336f94 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -1062,18 +1062,18 @@ void MarlinUI::update() { if (do_u8g_loop) { if (!drawing_screen) { // If not already drawing pages - u8g.firstPage(); // Start the first page + u8g().firstPage(); // Start the first page drawing_screen = first_page = true; // Flag as drawing pages } set_font(FONT_MENU); // Setup font for every page draw - u8g.setColorIndex(1); // And reset the color + u8g().setColorIndex(1); // And reset the color run_current_screen(); // Draw and process the current screen first_page = false; // The screen handler can clear drawing_screen for an action that changes the screen. // If still drawing and there's another page, update max-time and return now. // The nextPage will already be set up on the next call. - if (drawing_screen && (drawing_screen = u8g.nextPage())) { + if (drawing_screen && (drawing_screen = u8g().nextPage())) { if (on_status_screen()) NOLESS(max_display_update_time, millis() - ms); return; diff --git a/Marlin/src/lcd/menu/game/brickout.cpp b/Marlin/src/lcd/menu/game/brickout.cpp index 4bdc9243801e..a418f556d464 100644 --- a/Marlin/src/lcd/menu/game/brickout.cpp +++ b/Marlin/src/lcd/menu/game/brickout.cpp @@ -136,7 +136,7 @@ void BrickoutGame::game_screen() { } while (false); } - u8g.setColorIndex(1); + u8g().setColorIndex(1); // Draw bricks if (PAGE_CONTAINS(BRICK_TOP, BRICK_BOT)) { @@ -148,7 +148,7 @@ void BrickoutGame::game_screen() { const uint8_t xx = x * BRICK_W; LOOP_L_N(v, BRICK_H - 1) if (PAGE_CONTAINS(yy + v, yy + v)) - u8g.drawHLine(xx, yy + v, BRICK_W - 1); + u8g().drawHLine(xx, yy + v, BRICK_W - 1); } } } @@ -157,11 +157,11 @@ void BrickoutGame::game_screen() { // Draw paddle if (PAGE_CONTAINS(PADDLE_Y-1, PADDLE_Y)) { - u8g.drawHLine(bdat.paddle_x, PADDLE_Y, PADDLE_W); + u8g().drawHLine(bdat.paddle_x, PADDLE_Y, PADDLE_W); #if PADDLE_H > 1 - u8g.drawHLine(bdat.paddle_x, PADDLE_Y-1, PADDLE_W); + u8g().drawHLine(bdat.paddle_x, PADDLE_Y-1, PADDLE_W); #if PADDLE_H > 2 - u8g.drawHLine(bdat.paddle_x, PADDLE_Y-2, PADDLE_W); + u8g().drawHLine(bdat.paddle_x, PADDLE_Y-2, PADDLE_W); #endif #endif } @@ -170,7 +170,7 @@ void BrickoutGame::game_screen() { if (game_state) { const uint8_t by = FTOB(bdat.bally); if (PAGE_CONTAINS(by, by+1)) - u8g.drawFrame(FTOB(bdat.ballx), by, 2, 2); + u8g().drawFrame(FTOB(bdat.ballx), by, 2, 2); } // Or draw GAME OVER else diff --git a/Marlin/src/lcd/menu/game/game.cpp b/Marlin/src/lcd/menu/game/game.cpp index c14bd2a68df8..875faa9b71e2 100644 --- a/Marlin/src/lcd/menu/game/game.cpp +++ b/Marlin/src/lcd/menu/game/game.cpp @@ -45,9 +45,9 @@ void MarlinGame::draw_game_over() { lx = (LCD_PIXEL_WIDTH - gowide) / 2, ly = (LCD_PIXEL_HEIGHT + gohigh) / 2; if (PAGE_CONTAINS(ly - gohigh - 1, ly + 1)) { - u8g.setColorIndex(0); - u8g.drawBox(lx - 1, ly - gohigh - 1, gowide + 2, gohigh + 2); - u8g.setColorIndex(1); + u8g().setColorIndex(0); + u8g().drawBox(lx - 1, ly - gohigh - 1, gowide + 2, gohigh + 2); + u8g().setColorIndex(1); if (ui.get_blink()) lcd_put_u8str_P(lx, ly, PSTR("GAME OVER")); } } diff --git a/Marlin/src/lcd/menu/game/invaders.cpp b/Marlin/src/lcd/menu/game/invaders.cpp index 56e4c224dd14..deb35f07c354 100644 --- a/Marlin/src/lcd/menu/game/invaders.cpp +++ b/Marlin/src/lcd/menu/game/invaders.cpp @@ -366,7 +366,7 @@ void InvadersGame::game_screen() { if (!idat.quit_count) exit_game(); - u8g.setColorIndex(1); + u8g().setColorIndex(1); // Draw invaders if (PAGE_CONTAINS(idat.pos.y, idat.pos.y + idat.botmost * (INVADER_ROW_H) - 2 - 1)) { @@ -377,7 +377,7 @@ void InvadersGame::game_screen() { int8_t xx = idat.pos.x; LOOP_L_N(x, INVADER_COLS) { if (TEST(idat.bugs[y], x)) - u8g.drawBitmapP(xx, yy, 2, INVADER_H, invader[type][idat.game_blink]); + u8g().drawBitmapP(xx, yy, 2, INVADER_H, invader[type][idat.game_blink]); xx += INVADER_COL_W; } } @@ -387,25 +387,25 @@ void InvadersGame::game_screen() { // Draw UFO if (idat.ufov && PAGE_UNDER(UFO_H + 2)) - u8g.drawBitmapP(idat.ufox, 2, 2, UFO_H, ufo); + u8g().drawBitmapP(idat.ufox, 2, 2, UFO_H, ufo); // Draw cannon if (game_state && PAGE_CONTAINS(CANNON_Y, CANNON_Y + CANNON_H - 1) && (game_state < 2 || (game_state & 0x02))) - u8g.drawBitmapP(idat.cannon_x, CANNON_Y, 2, CANNON_H, cannon); + u8g().drawBitmapP(idat.cannon_x, CANNON_Y, 2, CANNON_H, cannon); // Draw laser if (idat.laser.v && PAGE_CONTAINS(idat.laser.y, idat.laser.y + LASER_H - 1)) - u8g.drawVLine(idat.laser.x, idat.laser.y, LASER_H); + u8g().drawVLine(idat.laser.x, idat.laser.y, LASER_H); // Draw invader bullets LOOP_L_N (i, COUNT(idat.bullet)) { if (idat.bullet[i].v && PAGE_CONTAINS(idat.bullet[i].y - (SHOT_H - 1), idat.bullet[i].y)) - u8g.drawVLine(idat.bullet[i].x, idat.bullet[i].y - (SHOT_H - 1), SHOT_H); + u8g().drawVLine(idat.bullet[i].x, idat.bullet[i].y - (SHOT_H - 1), SHOT_H); } // Draw explosion if (idat.explod.v && PAGE_CONTAINS(idat.explod.y, idat.explod.y + 7 - 1)) { - u8g.drawBitmapP(idat.explod.x, idat.explod.y, 2, 7, explosion); + u8g().drawBitmapP(idat.explod.x, idat.explod.y, 2, 7, explosion); --idat.explod.v; } @@ -421,7 +421,7 @@ void InvadersGame::game_screen() { // Draw lives if (idat.cannons_left) for (uint8_t i = 1; i <= idat.cannons_left; ++i) - u8g.drawBitmapP(LCD_PIXEL_WIDTH - i * (LIFE_W), 6 - (LIFE_H), 1, LIFE_H, life); + u8g().drawBitmapP(LCD_PIXEL_WIDTH - i * (LIFE_W), 6 - (LIFE_H), 1, LIFE_H, life); } } diff --git a/Marlin/src/lcd/menu/game/maze.cpp b/Marlin/src/lcd/menu/game/maze.cpp index 85f752ee7de5..3a64d409ccda 100644 --- a/Marlin/src/lcd/menu/game/maze.cpp +++ b/Marlin/src/lcd/menu/game/maze.cpp @@ -77,7 +77,7 @@ void MazeGame::game_screen() { } while(0); - u8g.setColorIndex(1); + u8g().setColorIndex(1); // Draw Score if (PAGE_UNDER(HEADER_H)) lcd_put_int(0, HEADER_H - 1, score); @@ -88,11 +88,11 @@ void MazeGame::game_screen() { // if (p.x == q.x) { // const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y)); // if (PAGE_CONTAINS(y1, y2)) - // u8g.drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); + // u8g().drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); // } // else if (PAGE_CONTAINS(GAMEY(p.y), GAMEY(p.y))) { // const int8_t x1 = GAMEX(_MIN(p.x, q.x)), x2 = GAMEX(_MAX(p.x, q.x)); - // u8g.drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); + // u8g().drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); // } // } @@ -100,22 +100,22 @@ void MazeGame::game_screen() { // const int8_t fy = GAMEY(foody); // if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) { // const int8_t fx = GAMEX(foodx); - // u8g.drawFrame(fx, fy, FOOD_WH, FOOD_WH); - // if (FOOD_WH == 5) u8g.drawPixel(fx + 2, fy + 2); + // u8g().drawFrame(fx, fy, FOOD_WH, FOOD_WH); + // if (FOOD_WH == 5) u8g().drawPixel(fx + 2, fy + 2); // } // Draw Ghosts // const int8_t fy = GAMEY(foody); // if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) { // const int8_t fx = GAMEX(foodx); - // u8g.drawFrame(fx, fy, FOOD_WH, FOOD_WH); - // if (FOOD_WH == 5) u8g.drawPixel(fx + 2, fy + 2); + // u8g().drawFrame(fx, fy, FOOD_WH, FOOD_WH); + // if (FOOD_WH == 5) u8g().drawPixel(fx + 2, fy + 2); // } // Draw Prize // if (PAGE_CONTAINS(prizey, prizey + PRIZE_WH - 1)) { - // u8g.drawFrame(prizex, prizey, PRIZE_WH, PRIZE_WH); - // if (PRIZE_WH == 5) u8g.drawPixel(prizex + 2, prizey + 2); + // u8g().drawFrame(prizex, prizey, PRIZE_WH, PRIZE_WH); + // if (PRIZE_WH == 5) u8g().drawPixel(prizex + 2, prizey + 2); // } // Draw GAME OVER diff --git a/Marlin/src/lcd/menu/game/snake.cpp b/Marlin/src/lcd/menu/game/snake.cpp index f8892a4e7a39..1fdc87b5c3ce 100644 --- a/Marlin/src/lcd/menu/game/snake.cpp +++ b/Marlin/src/lcd/menu/game/snake.cpp @@ -228,13 +228,13 @@ void SnakeGame::game_screen() { } while(0); - u8g.setColorIndex(1); + u8g().setColorIndex(1); // Draw Score if (PAGE_UNDER(HEADER_H)) lcd_put_int(0, HEADER_H - 1, score); // DRAW THE PLAYFIELD BORDER - u8g.drawFrame(BOARD_L - 2, BOARD_T - 2, BOARD_R - BOARD_L + 4, BOARD_B - BOARD_T + 4); + u8g().drawFrame(BOARD_L - 2, BOARD_T - 2, BOARD_R - BOARD_L + 4, BOARD_B - BOARD_T + 4); // Draw the snake (tail) #if SNAKE_WH < 2 @@ -245,11 +245,11 @@ void SnakeGame::game_screen() { if (p.x == q.x) { const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y)); if (PAGE_CONTAINS(y1, y2)) - u8g.drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); + u8g().drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); } else if (PAGE_CONTAINS(GAMEY(p.y), GAMEY(p.y))) { const int8_t x1 = GAMEX(_MIN(p.x, q.x)), x2 = GAMEX(_MAX(p.x, q.x)); - u8g.drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); + u8g().drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); } } @@ -261,13 +261,13 @@ void SnakeGame::game_screen() { if (p.x == q.x) { const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y)); if (PAGE_CONTAINS(y1, y2 + 1)) - u8g.drawFrame(GAMEX(p.x), y1, 2, y2 - y1 + 1 + 1); + u8g().drawFrame(GAMEX(p.x), y1, 2, y2 - y1 + 1 + 1); } else { const int8_t py = GAMEY(p.y); if (PAGE_CONTAINS(py, py + 1)) { const int8_t x1 = GAMEX(_MIN(p.x, q.x)), x2 = GAMEX(_MAX(p.x, q.x)); - u8g.drawFrame(x1, py, x2 - x1 + 1 + 1, 2); + u8g().drawFrame(x1, py, x2 - x1 + 1 + 1, 2); } } } @@ -283,7 +283,7 @@ void SnakeGame::game_screen() { for (int8_t i = y1; i <= y2; ++i) { const int8_t y = GAMEY(i); if (PAGE_CONTAINS(y, y + SNAKE_SIZ - 1)) - u8g.drawBox(GAMEX(p.x), y, SNAKE_SIZ, SNAKE_SIZ); + u8g().drawBox(GAMEX(p.x), y, SNAKE_SIZ, SNAKE_SIZ); } } } @@ -292,7 +292,7 @@ void SnakeGame::game_screen() { if (PAGE_CONTAINS(py, py + SNAKE_SIZ - 1)) { const int8_t x1 = _MIN(p.x, q.x), x2 = _MAX(p.x, q.x); for (int8_t i = x1; i <= x2; ++i) - u8g.drawBox(GAMEX(i), py, SNAKE_SIZ, SNAKE_SIZ); + u8g().drawBox(GAMEX(i), py, SNAKE_SIZ, SNAKE_SIZ); } } } @@ -303,8 +303,8 @@ void SnakeGame::game_screen() { const int8_t fy = GAMEY(sdat.foody); if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) { const int8_t fx = GAMEX(sdat.foodx); - u8g.drawFrame(fx, fy, FOOD_WH, FOOD_WH); - if (FOOD_WH == 5) u8g.drawPixel(fx + 2, fy + 2); + u8g().drawFrame(fx, fy, FOOD_WH, FOOD_WH); + if (FOOD_WH == 5) u8g().drawPixel(fx + 2, fy + 2); } // Draw GAME OVER From 4c4839987cf51f84691846a5cfe9fcd2ac8b70b7 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 1 Apr 2021 00:31:51 -0300 Subject: [PATCH 2/4] use a pointer to avoid unnecessary calls --- Marlin/src/lcd/dogm/lcdprint_u8g.cpp | 28 ++--- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 102 +++++++++--------- Marlin/src/lcd/dogm/marlinui_DOGM.h | 9 +- Marlin/src/lcd/dogm/status_screen_DOGM.cpp | 58 +++++----- .../dogm/u8g_dev_tft_upscale_from_128x64.cpp | 2 +- Marlin/src/lcd/marlinui.cpp | 17 ++- Marlin/src/lcd/menu/game/brickout.cpp | 12 +-- Marlin/src/lcd/menu/game/game.cpp | 6 +- Marlin/src/lcd/menu/game/invaders.cpp | 16 +-- Marlin/src/lcd/menu/game/maze.cpp | 18 ++-- Marlin/src/lcd/menu/game/snake.cpp | 20 ++-- 11 files changed, 146 insertions(+), 142 deletions(-) diff --git a/Marlin/src/lcd/dogm/lcdprint_u8g.cpp b/Marlin/src/lcd/dogm/lcdprint_u8g.cpp index 76c53b0855f3..3e026f615fac 100644 --- a/Marlin/src/lcd/dogm/lcdprint_u8g.cpp +++ b/Marlin/src/lcd/dogm/lcdprint_u8g.cpp @@ -20,36 +20,36 @@ #include "u8g_fontutf8.h" #include "../lcdprint.h" -int lcd_glyph_height() { return u8g_GetFontBBXHeight(u8g().getU8g()); } +int lcd_glyph_height() { return u8g_GetFontBBXHeight(u8g->getU8g()); } -void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { u8g().setPrintPos(col, row); } +void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { u8g->setPrintPos(col, row); } -void lcd_put_int(const int i) { u8g().print(i); } +void lcd_put_int(const int i) { u8g->print(i); } // return < 0 on error // return the advanced pixels int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) { if (c < 256) { - u8g().print((char)c); - return u8g_GetFontBBXWidth(u8g().getU8g()); + u8g->print((char)c); + return u8g_GetFontBBXWidth(u8g->getU8g()); } - u8g_uint_t x = u8g().getPrintCol(), y = u8g().getPrintRow(), - ret = uxg_DrawWchar(u8g().getU8g(), x, y, c, max_length); - u8g().setPrintPos(x + ret, y); + u8g_uint_t x = u8g->getPrintCol(), y = u8g->getPrintRow(), + ret = uxg_DrawWchar(u8g->getU8g(), x, y, c, max_length); + u8g->setPrintPos(x + ret, y); return ret; } int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) { - u8g_uint_t x = u8g().getPrintCol(), y = u8g().getPrintRow(), - ret = uxg_DrawUtf8Str(u8g().getU8g(), x, y, utf8_str, max_length); - u8g().setPrintPos(x + ret, y); + u8g_uint_t x = u8g->getPrintCol(), y = u8g->getPrintRow(), + ret = uxg_DrawUtf8Str(u8g->getU8g(), x, y, utf8_str, max_length); + u8g->setPrintPos(x + ret, y); return ret; } int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) { - u8g_uint_t x = u8g().getPrintCol(), y = u8g().getPrintRow(), - ret = uxg_DrawUtf8StrP(u8g().getU8g(), x, y, utf8_str_P, max_length); - u8g().setPrintPos(x + ret, y); + u8g_uint_t x = u8g->getPrintCol(), y = u8g->getPrintRow(), + ret = uxg_DrawUtf8StrP(u8g->getU8g(), x, y, utf8_str_P, max_length); + u8g->setPrintPos(x + ret, y); return ret; } diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 1eb495f8a37f..c17950fee8f0 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -76,11 +76,7 @@ #define FONT_STATUSMENU_NAME MENU_FONT_NAME #endif -U8G_CLASS& u8g() -{ - static U8G_CLASS _u8g(U8G_PARAM); - return _u8g; -} +U8G_CLASS* u8g = nullptr; #include LANGUAGE_DATA_INCL(LCD_LANGUAGE) @@ -90,7 +86,7 @@ U8G_CLASS& u8g() void MarlinUI::set_contrast(const int16_t value) { contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX); - u8g().setContrast(contrast); + u8g->setContrast(contrast); } #endif @@ -99,10 +95,10 @@ void MarlinUI::set_font(const MarlinFont font_nr) { static char currentfont = 0; if (font_nr != currentfont) { switch ((currentfont = font_nr)) { - case FONT_STATUSMENU : u8g().setFont(FONT_STATUSMENU_NAME); break; - case FONT_EDIT : u8g().setFont(EDIT_FONT_NAME); break; + case FONT_STATUSMENU : u8g->setFont(FONT_STATUSMENU_NAME); break; + case FONT_EDIT : u8g->setFont(EDIT_FONT_NAME); break; default: - case FONT_MENU : u8g().setFont(MENU_FONT_NAME); break; + case FONT_MENU : u8g->setFont(MENU_FONT_NAME); break; } } } @@ -133,15 +129,15 @@ bool MarlinUI::detected() { return true; } UNUSED(frame); - u8g().drawBitmapP(left, top, CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH, CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp); + u8g->drawBitmapP(left, top, CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH, CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp); #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED) if (frame == 0) { - u8g().setColorIndex(1); - if (top) u8g().drawBox(0, 0, LCD_PIXEL_WIDTH, top); - if (left) u8g().drawBox(0, top, left, CUSTOM_BOOTSCREEN_BMPHEIGHT); - if (right < LCD_PIXEL_WIDTH) u8g().drawBox(right, top, LCD_PIXEL_WIDTH - right, CUSTOM_BOOTSCREEN_BMPHEIGHT); - if (bottom < LCD_PIXEL_HEIGHT) u8g().drawBox(0, bottom, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT - bottom); + u8g->setColorIndex(1); + if (top) u8g->drawBox(0, 0, LCD_PIXEL_WIDTH, top); + if (left) u8g->drawBox(0, top, left, CUSTOM_BOOTSCREEN_BMPHEIGHT); + if (right < LCD_PIXEL_WIDTH) u8g->drawBox(right, top, LCD_PIXEL_WIDTH - right, CUSTOM_BOOTSCREEN_BMPHEIGHT); + if (bottom < LCD_PIXEL_HEIGHT) u8g->drawBox(0, bottom, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT - bottom); } #endif } @@ -162,8 +158,8 @@ bool MarlinUI::detected() { return true; } const uint8_t fr = _MIN(f, COUNT(custom_bootscreen_animation) - 1); const millis_t frame_time = pgm_read_word(&custom_bootscreen_animation[fr].duration); #endif - u8g().firstPage(); - do { draw_custom_bootscreen(f); } while (u8g().nextPage()); + u8g->firstPage(); + do { draw_custom_bootscreen(f); } while (u8g->nextPage()); if (frame_time) safe_delay(frame_time); } @@ -213,14 +209,14 @@ bool MarlinUI::detected() { return true; } NOLESS(offy, 0); auto _draw_bootscreen_bmp = [&](const uint8_t *bitmap) { - u8g().drawBitmapP(offx, offy, START_BMP_BYTEWIDTH, START_BMPHEIGHT, bitmap); + u8g->drawBitmapP(offx, offy, START_BMP_BYTEWIDTH, START_BMPHEIGHT, bitmap); set_font(FONT_MENU); if (!two_part || !line2) lcd_put_u8str_P(txt_offx_1, txt_base - (MENU_FONT_HEIGHT), PSTR(SHORT_BUILD_VERSION)); if (!two_part || line2) lcd_put_u8str_P(txt_offx_2, txt_base, PSTR(MARLIN_WEBSITE_URL)); }; auto draw_bootscreen_bmp = [&](const uint8_t *bitmap) { - u8g().firstPage(); do { _draw_bootscreen_bmp(bitmap); } while (u8g().nextPage()); + u8g->firstPage(); do { _draw_bootscreen_bmp(bitmap); } while (u8g->nextPage()); }; #if DISABLED(BOOT_MARLIN_LOGO_ANIMATED) @@ -273,7 +269,7 @@ void MarlinUI::init_lcd() { _delay_ms(5); WRITE(LCD_RESET_PIN, HIGH); _delay_ms(5); - u8g().begin(); + u8g->begin(); #endif #if PIN_EXISTS(LCD_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) @@ -282,9 +278,9 @@ void MarlinUI::init_lcd() { TERN_(HAS_LCD_CONTRAST, refresh_contrast()); - TERN_(LCD_SCREEN_ROT_90, u8g().setRot90()); - TERN_(LCD_SCREEN_ROT_180, u8g().setRot180()); - TERN_(LCD_SCREEN_ROT_270, u8g().setRot270()); + TERN_(LCD_SCREEN_ROT_90, u8g->setRot90()); + TERN_(LCD_SCREEN_ROT_180, u8g->setRot180()); + TERN_(LCD_SCREEN_ROT_270, u8g->setRot270()); uxg_SetUtf8Fonts(g_fontinfo, COUNT(g_fontinfo)); } @@ -292,14 +288,14 @@ void MarlinUI::init_lcd() { // The kill screen is displayed for unrecoverable conditions void MarlinUI::draw_kill_screen() { TERN_(LIGHTWEIGHT_UI, ST7920_Lite_Status_Screen::clear_text_buffer()); - const u8g_uint_t h4 = u8g().getHeight() / 4; - u8g().firstPage(); + const u8g_uint_t h4 = u8g->getHeight() / 4; + u8g->firstPage(); do { set_font(FONT_MENU); lcd_put_u8str(0, h4 * 1, status_message); lcd_put_u8str_P(0, h4 * 2, GET_TEXT(MSG_HALTED)); lcd_put_u8str_P(0, h4 * 3, GET_TEXT(MSG_PLEASE_RESET)); - } while (u8g().nextPage()); + } while (u8g->nextPage()); } void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop @@ -340,16 +336,16 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop if (sel) { #if ENABLED(MENU_HOLLOW_FRAME) - u8g().drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH); - u8g().drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH); + u8g->drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH); + u8g->drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH); #else - u8g().setColorIndex(1); // solid outline - u8g().drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, MENU_FONT_HEIGHT - 1); - u8g().setColorIndex(0); // inverted text + u8g->setColorIndex(1); // solid outline + u8g->drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, MENU_FONT_HEIGHT - 1); + u8g->setColorIndex(0); // inverted text #endif } #if DISABLED(MENU_HOLLOW_FRAME) - else u8g().setColorIndex(1); // solid text + else u8g->setColorIndex(1); // solid text #endif if (!PAGE_CONTAINS(row_y1, row_y2)) return false; @@ -392,7 +388,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char * const inStr, const bool pgm) { if (mark_as_selected(row, sel)) { const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen((char*)inStr)), - pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g().getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g().getU8g(), (char*)inStr)); + pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g->getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g->getU8g(), (char*)inStr)); pixel_len_t n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, LCD_WIDTH - 2 - vallen) * (MENU_FONT_WIDTH); if (vallen) { @@ -460,12 +456,12 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1; const pixel_len_t bw = len * prop * (MENU_FONT_WIDTH), bx = x * prop * (MENU_FONT_WIDTH); if (inv) { - u8g().setColorIndex(1); - u8g().drawBox(bx / prop - 1, by - (MENU_FONT_ASCENT) + 1, bw / prop + 2, MENU_FONT_HEIGHT - 1); - u8g().setColorIndex(0); + u8g->setColorIndex(1); + u8g->drawBox(bx / prop - 1, by - (MENU_FONT_ASCENT) + 1, bw / prop + 2, MENU_FONT_HEIGHT - 1); + u8g->setColorIndex(0); } lcd_put_u8str_P(bx / prop, by, pstr); - if (inv) u8g().setColorIndex(1); + if (inv) u8g->setColorIndex(1); } void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) { @@ -513,23 +509,23 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Clear the Mesh Map if (PAGE_CONTAINS(y_offset - 2, y_offset + y_map_pixels + 4)) { - u8g().setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box - u8g().drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4); + u8g->setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box + u8g->drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4); if (PAGE_CONTAINS(y_offset, y_offset + y_map_pixels)) { - u8g().setColorIndex(0); // Now actually clear the mesh map box - u8g().drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels); + u8g->setColorIndex(0); // Now actually clear the mesh map box + u8g->drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels); } } // Display Mesh Point Locations - u8g().setColorIndex(1); + u8g->setColorIndex(1); const u8g_uint_t sx = x_offset + pixels_per_x_mesh_pnt / 2; u8g_uint_t y = y_offset + pixels_per_y_mesh_pnt / 2; for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt) if (PAGE_CONTAINS(y, y)) for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt) - u8g().drawBox(x, y, 1, 1); + u8g->drawBox(x, y, 1, 1); // Fill in the Specified Mesh Point @@ -538,7 +534,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop const u8g_uint_t by = y_offset + y_plot_inv * pixels_per_y_mesh_pnt; if (PAGE_CONTAINS(by, by + pixels_per_y_mesh_pnt)) - u8g().drawBox( + u8g->drawBox( x_offset + x_plot * pixels_per_x_mesh_pnt, by, pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt ); @@ -546,7 +542,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Put Relevant Text on Display // Show X and Y positions at top of screen - u8g().setColorIndex(1); + u8g->setColorIndex(1); if (PAGE_UNDER(7)) { const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) }, lpos = pos.asLogical(); @@ -559,9 +555,9 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Print plot position if (PAGE_CONTAINS(LCD_PIXEL_HEIGHT - (INFO_FONT_HEIGHT - 1), LCD_PIXEL_HEIGHT)) { lcd_put_wchar(5, LCD_PIXEL_HEIGHT, '('); - u8g().print(x_plot); + u8g->print(x_plot); lcd_put_wchar(','); - u8g().print(y_plot); + u8g->print(y_plot); lcd_put_wchar(')'); // Show the location value @@ -690,15 +686,15 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop nozzle = TERN(USE_BIG_EDIT_FONT, 95, 60); // Draw nozzle lowered or raised according to direction moved - if (PAGE_CONTAINS( 3, 16)) u8g().drawBitmapP(nozzle + 6, 4 - dir, 2, 12, nozzle_bmp); - if (PAGE_CONTAINS(20, 20)) u8g().drawBitmapP(nozzle + 0, 20 , 3, 1, offset_bedline_bmp); + if (PAGE_CONTAINS( 3, 16)) u8g->drawBitmapP(nozzle + 6, 4 - dir, 2, 12, nozzle_bmp); + if (PAGE_CONTAINS(20, 20)) u8g->drawBitmapP(nozzle + 0, 20 , 3, 1, offset_bedline_bmp); // Draw cw/ccw indicator and up/down arrows. if (PAGE_CONTAINS(47, 62)) { - u8g().drawBitmapP(right + 0, 48 - dir, 2, 13, up_arrow_bmp); - u8g().drawBitmapP(left + 0, 49 - dir, 2, 13, down_arrow_bmp); - u8g().drawBitmapP(left + 13, 47 , 3, 16, rot_down); - u8g().drawBitmapP(right + 13, 47 , 3, 16, rot_up); + u8g->drawBitmapP(right + 0, 48 - dir, 2, 13, up_arrow_bmp); + u8g->drawBitmapP(left + 0, 49 - dir, 2, 13, down_arrow_bmp); + u8g->drawBitmapP(left + 13, 47 , 3, 16, rot_down); + u8g->drawBitmapP(right + 13, 47 , 3, 16, rot_up); } } diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.h b/Marlin/src/lcd/dogm/marlinui_DOGM.h index 9898ff3c3faf..2c0a3e75707c 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.h +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.h @@ -227,9 +227,8 @@ #endif // For selective rendering within a Y range -#define PAGE_OVER(ya) ((ya) <= u8g().getU8g()->current_page.y1) // Does the current page follow a region top? -#define PAGE_UNDER(yb) ((yb) >= u8g().getU8g()->current_page.y0) // Does the current page precede a region bottom? -#define PAGE_CONTAINS(ya, yb) ((yb) >= u8g().getU8g()->current_page.y0 && (ya) <= u8g().getU8g()->current_page.y1) // Do two vertical regions overlap? +#define PAGE_OVER(ya) ((ya) <= u8g->getU8g()->current_page.y1) // Does the current page follow a region top? +#define PAGE_UNDER(yb) ((yb) >= u8g->getU8g()->current_page.y0) // Does the current page precede a region bottom? +#define PAGE_CONTAINS(ya, yb) ((yb) >= u8g->getU8g()->current_page.y0 && (ya) <= u8g->getU8g()->current_page.y1) // Do two vertical regions overlap? -// extern U8G_CLASS u8g; -extern U8G_CLASS& u8g(); +extern U8G_CLASS* u8g; diff --git a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp index e9b9a6c31292..7ee4c093089e 100644 --- a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp +++ b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp @@ -268,12 +268,12 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co #if ENABLED(STATUS_HEAT_PERCENT) if (isHeat && tall <= BAR_TALL) { const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall; - u8g().drawBitmapP(hx, STATUS_HEATERS_Y, bw, ph, HOTEND_BITMAP(heater_id, false)); - u8g().drawBitmapP(hx, STATUS_HEATERS_Y + ph, bw, tall + 1, HOTEND_BITMAP(heater_id, true) + ph * bw); + u8g->drawBitmapP(hx, STATUS_HEATERS_Y, bw, ph, HOTEND_BITMAP(heater_id, false)); + u8g->drawBitmapP(hx, STATUS_HEATERS_Y + ph, bw, tall + 1, HOTEND_BITMAP(heater_id, true) + ph * bw); } else #endif - u8g().drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(heater_id, isHeat)); + u8g->drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(heater_id, isHeat)); #endif } // PAGE_CONTAINS @@ -291,9 +291,9 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co _draw_centered_temp(temp, tx, 28); if (STATIC_HOTEND && HOTEND_DOT && PAGE_CONTAINS(17, 19)) { - u8g().setColorIndex(0); // set to white on black - u8g().drawBox(tx, 20 - 3, 2, 2); - u8g().setColorIndex(1); // restore black on white + u8g->setColorIndex(0); // set to white on black + u8g->drawBox(tx, 20 - 3, 2, 2); + u8g->setColorIndex(1); // restore black on white } } @@ -339,11 +339,11 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co if (isHeat) { const uint8_t bx = STATUS_BED_X + STATUS_BED_WIDTH; - u8g().drawFrame(bx, STATUS_HEATERS_Y, 3, STATUS_HEATERS_HEIGHT); + u8g->drawFrame(bx, STATUS_HEATERS_Y, 3, STATUS_HEATERS_HEIGHT); if (tall) { const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall; if (PAGE_OVER(STATUS_HEATERS_Y + ph)) - u8g().drawVLine(bx + 1, STATUS_HEATERS_Y + ph, tall); + u8g->drawVLine(bx + 1, STATUS_HEATERS_Y + ph, tall); } } @@ -364,9 +364,9 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co _draw_centered_temp(temp, tx, 28); if (STATIC_BED && BED_DOT && PAGE_CONTAINS(17, 19)) { - u8g().setColorIndex(0); // set to white on black - u8g().drawBox(tx, 20 - 2, 2, 2); - u8g().setColorIndex(1); // restore black on white + u8g->setColorIndex(0); // set to white on black + u8g->drawBox(tx, 20 - 2, 2, 2); + u8g->setColorIndex(1); // restore black on white } } @@ -562,13 +562,13 @@ void MarlinUI::draw_status_screen() { #if DO_DRAW_LOGO if (PAGE_CONTAINS(STATUS_LOGO_Y, STATUS_LOGO_Y + STATUS_LOGO_HEIGHT - 1)) - u8g().drawBitmapP(STATUS_LOGO_X, STATUS_LOGO_Y, STATUS_LOGO_BYTEWIDTH, STATUS_LOGO_HEIGHT, status_logo_bmp); + u8g->drawBitmapP(STATUS_LOGO_X, STATUS_LOGO_Y, STATUS_LOGO_BYTEWIDTH, STATUS_LOGO_HEIGHT, status_logo_bmp); #endif #if STATUS_HEATERS_WIDTH // Draw all heaters (and maybe the bed) in one go if (PAGE_CONTAINS(STATUS_HEATERS_Y, STATUS_HEATERS_Y + STATUS_HEATERS_HEIGHT - 1)) - u8g().drawBitmapP(STATUS_HEATERS_X, STATUS_HEATERS_Y, STATUS_HEATERS_BYTEWIDTH, STATUS_HEATERS_HEIGHT, status_heaters_bmp); + u8g->drawBitmapP(STATUS_HEATERS_X, STATUS_HEATERS_Y, STATUS_HEATERS_BYTEWIDTH, STATUS_HEATERS_HEIGHT, status_heaters_bmp); #endif #if DO_DRAW_CUTTER && DISABLED(STATUS_COMBINE_HEATERS) @@ -580,7 +580,7 @@ void MarlinUI::draw_status_screen() { const uint8_t cuttery = STATUS_CUTTER_Y(CUTTER_ALT()), cutterh = STATUS_CUTTER_HEIGHT(CUTTER_ALT()); if (PAGE_CONTAINS(cuttery, cuttery + cutterh - 1)) - u8g().drawBitmapP(STATUS_CUTTER_X, cuttery, STATUS_CUTTER_BYTEWIDTH, cutterh, CUTTER_BITMAP(CUTTER_ALT())); + u8g->drawBitmapP(STATUS_CUTTER_X, cuttery, STATUS_CUTTER_BYTEWIDTH, cutterh, CUTTER_BITMAP(CUTTER_ALT())); #endif #if DO_DRAW_BED && DISABLED(STATUS_COMBINE_HEATERS) @@ -592,7 +592,7 @@ void MarlinUI::draw_status_screen() { const uint8_t bedy = STATUS_BED_Y(BED_ALT()), bedh = STATUS_BED_HEIGHT(BED_ALT()); if (PAGE_CONTAINS(bedy, bedy + bedh - 1)) - u8g().drawBitmapP(STATUS_BED_X, bedy, STATUS_BED_BYTEWIDTH, bedh, BED_BITMAP(BED_ALT())); + u8g->drawBitmapP(STATUS_BED_X, bedy, STATUS_BED_BYTEWIDTH, bedh, BED_BITMAP(BED_ALT())); #endif #if DO_DRAW_CHAMBER && DISABLED(STATUS_COMBINE_HEATERS) @@ -604,7 +604,7 @@ void MarlinUI::draw_status_screen() { const uint8_t chambery = STATUS_CHAMBER_Y(CHAMBER_ALT()), chamberh = STATUS_CHAMBER_HEIGHT(CHAMBER_ALT()); if (PAGE_CONTAINS(chambery, chambery + chamberh - 1)) - u8g().drawBitmapP(STATUS_CHAMBER_X, chambery, STATUS_CHAMBER_BYTEWIDTH, chamberh, CHAMBER_BITMAP(CHAMBER_ALT())); + u8g->drawBitmapP(STATUS_CHAMBER_X, chambery, STATUS_CHAMBER_BYTEWIDTH, chamberh, CHAMBER_BITMAP(CHAMBER_ALT())); #endif #if DO_DRAW_FAN @@ -617,7 +617,7 @@ void MarlinUI::draw_status_screen() { } #endif if (PAGE_CONTAINS(STATUS_FAN_Y, STATUS_FAN_Y + STATUS_FAN_HEIGHT - 1)) - u8g().drawBitmapP(STATUS_FAN_X, STATUS_FAN_Y, STATUS_FAN_BYTEWIDTH, STATUS_FAN_HEIGHT, + u8g->drawBitmapP(STATUS_FAN_X, STATUS_FAN_Y, STATUS_FAN_BYTEWIDTH, STATUS_FAN_HEIGHT, #if STATUS_FAN_FRAMES > 2 fan_frame == 1 ? status_fan1_bmp : fan_frame == 2 ? status_fan2_bmp : @@ -660,7 +660,7 @@ void MarlinUI::draw_status_screen() { const uint8_t coolery = STATUS_COOLER_Y(status_cooler_bmp1), coolerh = STATUS_COOLER_HEIGHT(status_cooler_bmp1); if (PAGE_CONTAINS(coolery, coolery + coolerh - 1)) - u8g().drawBitmapP(STATUS_COOLER_X, coolery, STATUS_COOLER_BYTEWIDTH, coolerh, blink && cooler.enabled ? status_cooler_bmp2 : status_cooler_bmp1); + u8g->drawBitmapP(STATUS_COOLER_X, coolery, STATUS_COOLER_BYTEWIDTH, coolerh, blink && cooler.enabled ? status_cooler_bmp2 : status_cooler_bmp1); #endif // Laser Cooler Flow Meter @@ -668,7 +668,7 @@ void MarlinUI::draw_status_screen() { const uint8_t flowmetery = STATUS_FLOWMETER_Y(status_flowmeter_bmp1), flowmeterh = STATUS_FLOWMETER_HEIGHT(status_flowmeter_bmp1); if (PAGE_CONTAINS(flowmetery, flowmetery + flowmeterh - 1)) - u8g().drawBitmapP(STATUS_FLOWMETER_X, flowmetery, STATUS_FLOWMETER_BYTEWIDTH, flowmeterh, blink && cooler.flowpulses ? status_flowmeter_bmp2 : status_flowmeter_bmp1); + u8g->drawBitmapP(STATUS_FLOWMETER_X, flowmetery, STATUS_FLOWMETER_BYTEWIDTH, flowmeterh, blink && cooler.flowpulses ? status_flowmeter_bmp2 : status_flowmeter_bmp1); #endif @@ -709,13 +709,13 @@ void MarlinUI::draw_status_screen() { // if (card.isFileOpen() && PAGE_CONTAINS(42, 51)) { // Upper box - u8g().drawBox(42, 42, 8, 7); // 42-48 (or 41-47) + u8g->drawBox(42, 42, 8, 7); // 42-48 (or 41-47) // Right edge - u8g().drawBox(50, 44, 2, 5); // 44-48 (or 43-47) + u8g->drawBox(50, 44, 2, 5); // 44-48 (or 43-47) // Bottom hollow box - u8g().drawFrame(42, 49, 10, 4); // 49-52 (or 48-51) + u8g->drawFrame(42, 49, 10, 4); // 49-52 (or 48-51) // Corner pixel - u8g().drawPixel(50, 43); // 43 (or 42) + u8g->drawPixel(50, 43); // 43 (or 42) } #endif // SDSUPPORT @@ -725,14 +725,14 @@ void MarlinUI::draw_status_screen() { // if (PAGE_CONTAINS(PROGRESS_BAR_Y, PROGRESS_BAR_Y + 3)) - u8g().drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, 4); + u8g->drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, 4); // // Progress bar solid part // if (PAGE_CONTAINS(PROGRESS_BAR_Y + 1, PROGRESS_BAR_Y + 2)) - u8g().drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, 2); + u8g->drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, 2); if (PAGE_CONTAINS(EXTRAS_BASELINE - INFO_FONT_ASCENT, EXTRAS_BASELINE - 1)) { @@ -805,16 +805,16 @@ void MarlinUI::draw_status_screen() { #if DISABLED(XYZ_NO_FRAME) #if ENABLED(XYZ_HOLLOW_FRAME) - u8g().drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39 + u8g->drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39 #else - u8g().drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37 + u8g->drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37 #endif #endif if (PAGE_CONTAINS(XYZ_BASELINE - (INFO_FONT_ASCENT - 1), XYZ_BASELINE)) { #if NONE(XYZ_NO_FRAME, XYZ_HOLLOW_FRAME) - u8g().setColorIndex(0); // white on black + u8g->setColorIndex(0); // white on black #endif #if HAS_DUAL_MIXING @@ -859,7 +859,7 @@ void MarlinUI::draw_status_screen() { _draw_axis_value(Z_AXIS, zstring, blink); #if NONE(XYZ_NO_FRAME, XYZ_HOLLOW_FRAME) - u8g().setColorIndex(1); // black on white + u8g->setColorIndex(1); // black on white #endif } } diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp index 6b528b418ccb..96a26c57280b 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp @@ -522,7 +522,7 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, do { set_font(FONT_MENU); lcd_put_u8str(0, LCD_PIXEL_HEIGHT / 2, str); - } while (u8g().nextPage()); + } while (u8g->nextPage()); drawing_screen = false; safe_delay(250); if (calibration_stage == CALIBRATION_SUCCESS) { diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index cb4179336f94..61f653f454d9 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -349,8 +349,17 @@ millis_t MarlinUI::next_button_update_ms; // = 0 #endif // HAS_LCD_MENU -void MarlinUI::init() { +#if HAS_MARLINUI_U8GLIB + static void u8gInit() { + static U8G_CLASS _u8g(U8G_PARAM); + u8g = &_u8g; + } +#endif +void MarlinUI::init() { + #if HAS_MARLINUI_U8GLIB + u8gInit(); + #endif init_lcd(); #if HAS_DIGITAL_BUTTONS @@ -1062,18 +1071,18 @@ void MarlinUI::update() { if (do_u8g_loop) { if (!drawing_screen) { // If not already drawing pages - u8g().firstPage(); // Start the first page + u8g->firstPage(); // Start the first page drawing_screen = first_page = true; // Flag as drawing pages } set_font(FONT_MENU); // Setup font for every page draw - u8g().setColorIndex(1); // And reset the color + u8g->setColorIndex(1); // And reset the color run_current_screen(); // Draw and process the current screen first_page = false; // The screen handler can clear drawing_screen for an action that changes the screen. // If still drawing and there's another page, update max-time and return now. // The nextPage will already be set up on the next call. - if (drawing_screen && (drawing_screen = u8g().nextPage())) { + if (drawing_screen && (drawing_screen = u8g->nextPage())) { if (on_status_screen()) NOLESS(max_display_update_time, millis() - ms); return; diff --git a/Marlin/src/lcd/menu/game/brickout.cpp b/Marlin/src/lcd/menu/game/brickout.cpp index a418f556d464..9fb391c00ee4 100644 --- a/Marlin/src/lcd/menu/game/brickout.cpp +++ b/Marlin/src/lcd/menu/game/brickout.cpp @@ -136,7 +136,7 @@ void BrickoutGame::game_screen() { } while (false); } - u8g().setColorIndex(1); + u8g->setColorIndex(1); // Draw bricks if (PAGE_CONTAINS(BRICK_TOP, BRICK_BOT)) { @@ -148,7 +148,7 @@ void BrickoutGame::game_screen() { const uint8_t xx = x * BRICK_W; LOOP_L_N(v, BRICK_H - 1) if (PAGE_CONTAINS(yy + v, yy + v)) - u8g().drawHLine(xx, yy + v, BRICK_W - 1); + u8g->drawHLine(xx, yy + v, BRICK_W - 1); } } } @@ -157,11 +157,11 @@ void BrickoutGame::game_screen() { // Draw paddle if (PAGE_CONTAINS(PADDLE_Y-1, PADDLE_Y)) { - u8g().drawHLine(bdat.paddle_x, PADDLE_Y, PADDLE_W); + u8g->drawHLine(bdat.paddle_x, PADDLE_Y, PADDLE_W); #if PADDLE_H > 1 - u8g().drawHLine(bdat.paddle_x, PADDLE_Y-1, PADDLE_W); + u8g->drawHLine(bdat.paddle_x, PADDLE_Y-1, PADDLE_W); #if PADDLE_H > 2 - u8g().drawHLine(bdat.paddle_x, PADDLE_Y-2, PADDLE_W); + u8g->drawHLine(bdat.paddle_x, PADDLE_Y-2, PADDLE_W); #endif #endif } @@ -170,7 +170,7 @@ void BrickoutGame::game_screen() { if (game_state) { const uint8_t by = FTOB(bdat.bally); if (PAGE_CONTAINS(by, by+1)) - u8g().drawFrame(FTOB(bdat.ballx), by, 2, 2); + u8g->drawFrame(FTOB(bdat.ballx), by, 2, 2); } // Or draw GAME OVER else diff --git a/Marlin/src/lcd/menu/game/game.cpp b/Marlin/src/lcd/menu/game/game.cpp index 875faa9b71e2..2fd32f065533 100644 --- a/Marlin/src/lcd/menu/game/game.cpp +++ b/Marlin/src/lcd/menu/game/game.cpp @@ -45,9 +45,9 @@ void MarlinGame::draw_game_over() { lx = (LCD_PIXEL_WIDTH - gowide) / 2, ly = (LCD_PIXEL_HEIGHT + gohigh) / 2; if (PAGE_CONTAINS(ly - gohigh - 1, ly + 1)) { - u8g().setColorIndex(0); - u8g().drawBox(lx - 1, ly - gohigh - 1, gowide + 2, gohigh + 2); - u8g().setColorIndex(1); + u8g->setColorIndex(0); + u8g->drawBox(lx - 1, ly - gohigh - 1, gowide + 2, gohigh + 2); + u8g->setColorIndex(1); if (ui.get_blink()) lcd_put_u8str_P(lx, ly, PSTR("GAME OVER")); } } diff --git a/Marlin/src/lcd/menu/game/invaders.cpp b/Marlin/src/lcd/menu/game/invaders.cpp index deb35f07c354..08128b6e4f97 100644 --- a/Marlin/src/lcd/menu/game/invaders.cpp +++ b/Marlin/src/lcd/menu/game/invaders.cpp @@ -366,7 +366,7 @@ void InvadersGame::game_screen() { if (!idat.quit_count) exit_game(); - u8g().setColorIndex(1); + u8g->setColorIndex(1); // Draw invaders if (PAGE_CONTAINS(idat.pos.y, idat.pos.y + idat.botmost * (INVADER_ROW_H) - 2 - 1)) { @@ -377,7 +377,7 @@ void InvadersGame::game_screen() { int8_t xx = idat.pos.x; LOOP_L_N(x, INVADER_COLS) { if (TEST(idat.bugs[y], x)) - u8g().drawBitmapP(xx, yy, 2, INVADER_H, invader[type][idat.game_blink]); + u8g->drawBitmapP(xx, yy, 2, INVADER_H, invader[type][idat.game_blink]); xx += INVADER_COL_W; } } @@ -387,25 +387,25 @@ void InvadersGame::game_screen() { // Draw UFO if (idat.ufov && PAGE_UNDER(UFO_H + 2)) - u8g().drawBitmapP(idat.ufox, 2, 2, UFO_H, ufo); + u8g->drawBitmapP(idat.ufox, 2, 2, UFO_H, ufo); // Draw cannon if (game_state && PAGE_CONTAINS(CANNON_Y, CANNON_Y + CANNON_H - 1) && (game_state < 2 || (game_state & 0x02))) - u8g().drawBitmapP(idat.cannon_x, CANNON_Y, 2, CANNON_H, cannon); + u8g->drawBitmapP(idat.cannon_x, CANNON_Y, 2, CANNON_H, cannon); // Draw laser if (idat.laser.v && PAGE_CONTAINS(idat.laser.y, idat.laser.y + LASER_H - 1)) - u8g().drawVLine(idat.laser.x, idat.laser.y, LASER_H); + u8g->drawVLine(idat.laser.x, idat.laser.y, LASER_H); // Draw invader bullets LOOP_L_N (i, COUNT(idat.bullet)) { if (idat.bullet[i].v && PAGE_CONTAINS(idat.bullet[i].y - (SHOT_H - 1), idat.bullet[i].y)) - u8g().drawVLine(idat.bullet[i].x, idat.bullet[i].y - (SHOT_H - 1), SHOT_H); + u8g->drawVLine(idat.bullet[i].x, idat.bullet[i].y - (SHOT_H - 1), SHOT_H); } // Draw explosion if (idat.explod.v && PAGE_CONTAINS(idat.explod.y, idat.explod.y + 7 - 1)) { - u8g().drawBitmapP(idat.explod.x, idat.explod.y, 2, 7, explosion); + u8g->drawBitmapP(idat.explod.x, idat.explod.y, 2, 7, explosion); --idat.explod.v; } @@ -421,7 +421,7 @@ void InvadersGame::game_screen() { // Draw lives if (idat.cannons_left) for (uint8_t i = 1; i <= idat.cannons_left; ++i) - u8g().drawBitmapP(LCD_PIXEL_WIDTH - i * (LIFE_W), 6 - (LIFE_H), 1, LIFE_H, life); + u8g->drawBitmapP(LCD_PIXEL_WIDTH - i * (LIFE_W), 6 - (LIFE_H), 1, LIFE_H, life); } } diff --git a/Marlin/src/lcd/menu/game/maze.cpp b/Marlin/src/lcd/menu/game/maze.cpp index 3a64d409ccda..99b8e292d97e 100644 --- a/Marlin/src/lcd/menu/game/maze.cpp +++ b/Marlin/src/lcd/menu/game/maze.cpp @@ -77,7 +77,7 @@ void MazeGame::game_screen() { } while(0); - u8g().setColorIndex(1); + u8g->setColorIndex(1); // Draw Score if (PAGE_UNDER(HEADER_H)) lcd_put_int(0, HEADER_H - 1, score); @@ -88,11 +88,11 @@ void MazeGame::game_screen() { // if (p.x == q.x) { // const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y)); // if (PAGE_CONTAINS(y1, y2)) - // u8g().drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); + // u8g->drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); // } // else if (PAGE_CONTAINS(GAMEY(p.y), GAMEY(p.y))) { // const int8_t x1 = GAMEX(_MIN(p.x, q.x)), x2 = GAMEX(_MAX(p.x, q.x)); - // u8g().drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); + // u8g->drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); // } // } @@ -100,22 +100,22 @@ void MazeGame::game_screen() { // const int8_t fy = GAMEY(foody); // if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) { // const int8_t fx = GAMEX(foodx); - // u8g().drawFrame(fx, fy, FOOD_WH, FOOD_WH); - // if (FOOD_WH == 5) u8g().drawPixel(fx + 2, fy + 2); + // u8g->drawFrame(fx, fy, FOOD_WH, FOOD_WH); + // if (FOOD_WH == 5) u8g->drawPixel(fx + 2, fy + 2); // } // Draw Ghosts // const int8_t fy = GAMEY(foody); // if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) { // const int8_t fx = GAMEX(foodx); - // u8g().drawFrame(fx, fy, FOOD_WH, FOOD_WH); - // if (FOOD_WH == 5) u8g().drawPixel(fx + 2, fy + 2); + // u8g->drawFrame(fx, fy, FOOD_WH, FOOD_WH); + // if (FOOD_WH == 5) u8g->drawPixel(fx + 2, fy + 2); // } // Draw Prize // if (PAGE_CONTAINS(prizey, prizey + PRIZE_WH - 1)) { - // u8g().drawFrame(prizex, prizey, PRIZE_WH, PRIZE_WH); - // if (PRIZE_WH == 5) u8g().drawPixel(prizex + 2, prizey + 2); + // u8g->drawFrame(prizex, prizey, PRIZE_WH, PRIZE_WH); + // if (PRIZE_WH == 5) u8g->drawPixel(prizex + 2, prizey + 2); // } // Draw GAME OVER diff --git a/Marlin/src/lcd/menu/game/snake.cpp b/Marlin/src/lcd/menu/game/snake.cpp index 1fdc87b5c3ce..2e587fe55f64 100644 --- a/Marlin/src/lcd/menu/game/snake.cpp +++ b/Marlin/src/lcd/menu/game/snake.cpp @@ -228,13 +228,13 @@ void SnakeGame::game_screen() { } while(0); - u8g().setColorIndex(1); + u8g->setColorIndex(1); // Draw Score if (PAGE_UNDER(HEADER_H)) lcd_put_int(0, HEADER_H - 1, score); // DRAW THE PLAYFIELD BORDER - u8g().drawFrame(BOARD_L - 2, BOARD_T - 2, BOARD_R - BOARD_L + 4, BOARD_B - BOARD_T + 4); + u8g->drawFrame(BOARD_L - 2, BOARD_T - 2, BOARD_R - BOARD_L + 4, BOARD_B - BOARD_T + 4); // Draw the snake (tail) #if SNAKE_WH < 2 @@ -245,11 +245,11 @@ void SnakeGame::game_screen() { if (p.x == q.x) { const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y)); if (PAGE_CONTAINS(y1, y2)) - u8g().drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); + u8g->drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); } else if (PAGE_CONTAINS(GAMEY(p.y), GAMEY(p.y))) { const int8_t x1 = GAMEX(_MIN(p.x, q.x)), x2 = GAMEX(_MAX(p.x, q.x)); - u8g().drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); + u8g->drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); } } @@ -261,13 +261,13 @@ void SnakeGame::game_screen() { if (p.x == q.x) { const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y)); if (PAGE_CONTAINS(y1, y2 + 1)) - u8g().drawFrame(GAMEX(p.x), y1, 2, y2 - y1 + 1 + 1); + u8g->drawFrame(GAMEX(p.x), y1, 2, y2 - y1 + 1 + 1); } else { const int8_t py = GAMEY(p.y); if (PAGE_CONTAINS(py, py + 1)) { const int8_t x1 = GAMEX(_MIN(p.x, q.x)), x2 = GAMEX(_MAX(p.x, q.x)); - u8g().drawFrame(x1, py, x2 - x1 + 1 + 1, 2); + u8g->drawFrame(x1, py, x2 - x1 + 1 + 1, 2); } } } @@ -283,7 +283,7 @@ void SnakeGame::game_screen() { for (int8_t i = y1; i <= y2; ++i) { const int8_t y = GAMEY(i); if (PAGE_CONTAINS(y, y + SNAKE_SIZ - 1)) - u8g().drawBox(GAMEX(p.x), y, SNAKE_SIZ, SNAKE_SIZ); + u8g->drawBox(GAMEX(p.x), y, SNAKE_SIZ, SNAKE_SIZ); } } } @@ -292,7 +292,7 @@ void SnakeGame::game_screen() { if (PAGE_CONTAINS(py, py + SNAKE_SIZ - 1)) { const int8_t x1 = _MIN(p.x, q.x), x2 = _MAX(p.x, q.x); for (int8_t i = x1; i <= x2; ++i) - u8g().drawBox(GAMEX(i), py, SNAKE_SIZ, SNAKE_SIZ); + u8g->drawBox(GAMEX(i), py, SNAKE_SIZ, SNAKE_SIZ); } } } @@ -303,8 +303,8 @@ void SnakeGame::game_screen() { const int8_t fy = GAMEY(sdat.foody); if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) { const int8_t fx = GAMEX(sdat.foodx); - u8g().drawFrame(fx, fy, FOOD_WH, FOOD_WH); - if (FOOD_WH == 5) u8g().drawPixel(fx + 2, fy + 2); + u8g->drawFrame(fx, fy, FOOD_WH, FOOD_WH); + if (FOOD_WH == 5) u8g->drawPixel(fx + 2, fy + 2); } // Draw GAME OVER From 2d372dfbebfbd34db9dbd07fa27abb55c56db776 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 7 Apr 2021 19:54:10 -0500 Subject: [PATCH 3/4] Use new U8glib-HAL with late init --- Marlin/src/lcd/dogm/HAL_LCD_class_defines.h | 86 ++++++++------ Marlin/src/lcd/dogm/lcdprint_u8g.cpp | 28 ++--- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 105 ++++++++++-------- Marlin/src/lcd/dogm/marlinui_DOGM.h | 8 +- Marlin/src/lcd/dogm/status_screen_DOGM.cpp | 58 +++++----- .../dogm/u8g_dev_tft_upscale_from_128x64.cpp | 2 +- Marlin/src/lcd/marlinui.cpp | 17 +-- Marlin/src/lcd/menu/game/brickout.cpp | 12 +- Marlin/src/lcd/menu/game/game.cpp | 6 +- Marlin/src/lcd/menu/game/invaders.cpp | 16 +-- Marlin/src/lcd/menu/game/maze.cpp | 18 +-- Marlin/src/lcd/menu/game/snake.cpp | 20 ++-- ini/features.ini | 2 +- 13 files changed, 195 insertions(+), 183 deletions(-) diff --git a/Marlin/src/lcd/dogm/HAL_LCD_class_defines.h b/Marlin/src/lcd/dogm/HAL_LCD_class_defines.h index 30a5361ab926..28ca26134e16 100644 --- a/Marlin/src/lcd/dogm/HAL_LCD_class_defines.h +++ b/Marlin/src/lcd/dogm/HAL_LCD_class_defines.h @@ -30,12 +30,15 @@ extern u8g_dev_t u8g_dev_st7565_64128n_HAL_2x_hw_spi; class U8GLIB_64128N_2X_HAL : public U8GLIB { public: - U8GLIB_64128N_2X_HAL(pin_t sck, pin_t mosi, pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) - : U8GLIB(&u8g_dev_st7565_64128n_HAL_2x_sw_spi, (uint8_t)sck, (uint8_t)mosi, (uint8_t)cs, (uint8_t)a0, (uint8_t)reset) - { } - U8GLIB_64128N_2X_HAL(pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) - : U8GLIB(&u8g_dev_st7565_64128n_HAL_2x_hw_spi, (uint8_t)cs, (uint8_t)a0, (uint8_t)reset) - { } + U8GLIB_64128N_2X_HAL() : U8GLIB() { } + U8GLIB_64128N_2X_HAL(pin_t sck, pin_t mosi, pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) { init(sck, mosi, cs, a0, reset); } + U8GLIB_64128N_2X_HAL(pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) { init(cs, a0, reset); } + void init(pin_t sck, pin_t mosi, pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) { + U8GLIB::init(&u8g_dev_st7565_64128n_HAL_2x_sw_spi, (uint8_t)sck, (uint8_t)mosi, (uint8_t)cs, (uint8_t)a0, (uint8_t)reset); + } + void init(pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) { + U8GLIB::init(&u8g_dev_st7565_64128n_HAL_2x_hw_spi, (uint8_t)cs, (uint8_t)a0, (uint8_t)reset); + } }; extern u8g_dev_t u8g_dev_st7920_128x64_HAL_4x_sw_spi; @@ -43,12 +46,15 @@ extern u8g_dev_t u8g_dev_st7920_128x64_HAL_4x_hw_spi; class U8GLIB_ST7920_128X64_4X_HAL : public U8GLIB { public: - U8GLIB_ST7920_128X64_4X_HAL(pin_t sck, pin_t mosi, pin_t cs, pin_t reset = U8G_PIN_NONE) - : U8GLIB(&u8g_dev_st7920_128x64_HAL_4x_sw_spi, (uint8_t)sck, (uint8_t)mosi, (uint8_t)cs, U8G_PIN_NONE, (uint8_t)reset) // a0 = U8G_PIN_NONE - { } - U8GLIB_ST7920_128X64_4X_HAL(pin_t cs, pin_t reset = U8G_PIN_NONE) - : U8GLIB(&u8g_dev_st7920_128x64_HAL_4x_hw_spi, (uint8_t)cs, U8G_PIN_NONE, (uint8_t)reset) // a0 = U8G_PIN_NONE - { } + U8GLIB_ST7920_128X64_4X_HAL() : U8GLIB() { } + U8GLIB_ST7920_128X64_4X_HAL(pin_t sck, pin_t mosi, pin_t cs, pin_t reset = U8G_PIN_NONE) { init(sck, mosi, cs, reset); } + U8GLIB_ST7920_128X64_4X_HAL(pin_t cs, pin_t reset = U8G_PIN_NONE) { init(cs, reset); } + void init(pin_t sck, pin_t mosi, pin_t cs, pin_t reset = U8G_PIN_NONE) { + U8GLIB::init(&u8g_dev_st7920_128x64_HAL_4x_sw_spi, (uint8_t)sck, (uint8_t)mosi, (uint8_t)cs, U8G_PIN_NONE, (uint8_t)reset); // a0 = U8G_PIN_NONE + } + void init(pin_t cs, pin_t reset = U8G_PIN_NONE) { + U8GLIB::init(&u8g_dev_st7920_128x64_HAL_4x_hw_spi, (uint8_t)cs, U8G_PIN_NONE, (uint8_t)reset); // a0 = U8G_PIN_NONE + } }; // @@ -59,27 +65,29 @@ extern u8g_dev_t u8g_dev_st7920_128x64_rrd_sw_spi; class U8GLIB_ST7920_128X64_RRD : public U8GLIB { public: - U8GLIB_ST7920_128X64_RRD(pin_t sck, pin_t mosi, pin_t cs, pin_t reset = U8G_PIN_NONE) - : U8GLIB(&u8g_dev_st7920_128x64_rrd_sw_spi, (uint8_t)sck, (uint8_t)mosi, (uint8_t)cs, U8G_PIN_NONE, (uint8_t)reset) // a0 = U8G_PIN_NONE - { } + U8GLIB_ST7920_128X64_RRD() : U8GLIB() { } + U8GLIB_ST7920_128X64_RRD(pin_t sck, pin_t mosi, pin_t cs, pin_t reset = U8G_PIN_NONE) { init(sck, mosi, cs, reset); } + void init(pin_t sck, pin_t mosi, pin_t cs, pin_t reset = U8G_PIN_NONE) { + U8GLIB::init(&u8g_dev_st7920_128x64_rrd_sw_spi, (uint8_t)sck, (uint8_t)mosi, (uint8_t)cs, U8G_PIN_NONE, (uint8_t)reset); // a0 = U8G_PIN_NONE + } }; extern u8g_dev_t u8g_dev_sh1106_128x64_2x_i2c_2_wire; class U8GLIB_SH1106_128X64_2X_I2C_2_WIRE : public U8GLIB { public: - U8GLIB_SH1106_128X64_2X_I2C_2_WIRE(uint8_t options = U8G_I2C_OPT_NONE) - : U8GLIB(&u8g_dev_sh1106_128x64_2x_i2c_2_wire, options) - { } + U8GLIB_SH1106_128X64_2X_I2C_2_WIRE() : U8GLIB() { } + U8GLIB_SH1106_128X64_2X_I2C_2_WIRE(uint8_t options) { init(options); } + void init(uint8_t options = U8G_I2C_OPT_NONE) { U8GLIB::init(&u8g_dev_sh1106_128x64_2x_i2c_2_wire, options); } }; extern u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c_2_wire; class U8GLIB_SSD1306_128X64_2X_I2C_2_WIRE : public U8GLIB { public: - U8GLIB_SSD1306_128X64_2X_I2C_2_WIRE(uint8_t options = U8G_I2C_OPT_NONE) - : U8GLIB(&u8g_dev_ssd1306_128x64_2x_i2c_2_wire, options) - { } + U8GLIB_SSD1306_128X64_2X_I2C_2_WIRE() : U8GLIB() { } + U8GLIB_SSD1306_128X64_2X_I2C_2_WIRE(uint8_t options) { init(options); } + void init(uint8_t options = U8G_I2C_OPT_NONE) { U8GLIB::init(&u8g_dev_ssd1306_128x64_2x_i2c_2_wire, options); } }; // @@ -90,9 +98,9 @@ extern u8g_dev_t u8g_dev_tft_320x240_upscale_from_128x64; class U8GLIB_TFT_320X240_UPSCALE_FROM_128X64 : public U8GLIB { public: - U8GLIB_TFT_320X240_UPSCALE_FROM_128X64(uint8_t cs, uint8_t rs, uint8_t reset = U8G_PIN_NONE) - : U8GLIB(&u8g_dev_tft_320x240_upscale_from_128x64, cs, rs, reset) - { } + U8GLIB_TFT_320X240_UPSCALE_FROM_128X64() : U8GLIB() { } + U8GLIB_TFT_320X240_UPSCALE_FROM_128X64(uint8_t cs, uint8_t rs, uint8_t reset = U8G_PIN_NONE) { init(cs, rs, reset); } + void init(uint8_t cs, uint8_t rs, uint8_t reset = U8G_PIN_NONE) { U8GLIB::init(&u8g_dev_tft_320x240_upscale_from_128x64, cs, rs, reset); } }; @@ -100,12 +108,15 @@ extern u8g_dev_t u8g_dev_uc1701_mini12864_HAL_2x_sw_spi, u8g_dev_uc1701_mini1286 class U8GLIB_MINI12864_2X_HAL : public U8GLIB { public: - U8GLIB_MINI12864_2X_HAL(uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset = U8G_PIN_NONE) - : U8GLIB(&u8g_dev_uc1701_mini12864_HAL_2x_sw_spi, sck, mosi, cs, a0, reset) - { } - U8GLIB_MINI12864_2X_HAL(uint8_t cs, uint8_t a0, uint8_t reset = U8G_PIN_NONE) - : U8GLIB(&u8g_dev_uc1701_mini12864_HAL_2x_hw_spi, cs, a0, reset) - { } + U8GLIB_MINI12864_2X_HAL() : U8GLIB() { } + U8GLIB_MINI12864_2X_HAL(uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset = U8G_PIN_NONE) { init(sck, mosi, cs, a0, reset); } + U8GLIB_MINI12864_2X_HAL(uint8_t cs, uint8_t a0, uint8_t reset = U8G_PIN_NONE) { init(cs, a0, reset); } + void init(uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset = U8G_PIN_NONE) { + U8GLIB::init(&u8g_dev_uc1701_mini12864_HAL_2x_sw_spi, sck, mosi, cs, a0, reset); + } + void init(uint8_t cs, uint8_t a0, uint8_t reset = U8G_PIN_NONE) { + U8GLIB::init(&u8g_dev_uc1701_mini12864_HAL_2x_hw_spi, cs, a0, reset); + } }; extern u8g_dev_t u8g_dev_ssd1309_sw_spi; @@ -113,10 +124,13 @@ extern u8g_dev_t u8g_dev_ssd1309_hw_spi; class U8GLIB_SSD1309_128X64_HAL : public U8GLIB { public: - U8GLIB_SSD1309_128X64_HAL(pin_t sck, pin_t mosi, pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) - : U8GLIB(&u8g_dev_ssd1309_sw_spi, (uint8_t)sck, (uint8_t)mosi, (uint8_t)cs, (uint8_t)a0, (uint8_t)reset) - { } - U8GLIB_SSD1309_128X64_HAL(pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) - : U8GLIB(&u8g_dev_ssd1309_hw_spi, (uint8_t)cs, (uint8_t)a0, (uint8_t)reset) - { } + U8GLIB_SSD1309_128X64_HAL() : U8GLIB() { } + U8GLIB_SSD1309_128X64_HAL(pin_t sck, pin_t mosi, pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) { init(sck, mosi, cs, a0, reset); } + U8GLIB_SSD1309_128X64_HAL(pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) { init(cs, a0, reset); } + void init(pin_t sck, pin_t mosi, pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) { + U8GLIB::init(&u8g_dev_ssd1309_sw_spi, (uint8_t)sck, (uint8_t)mosi, (uint8_t)cs, (uint8_t)a0, (uint8_t)reset); + } + void init(pin_t cs, pin_t a0, pin_t reset = U8G_PIN_NONE) { + U8GLIB::init(&u8g_dev_ssd1309_hw_spi, (uint8_t)cs, (uint8_t)a0, (uint8_t)reset); + } }; diff --git a/Marlin/src/lcd/dogm/lcdprint_u8g.cpp b/Marlin/src/lcd/dogm/lcdprint_u8g.cpp index 3e026f615fac..a85dc9f97911 100644 --- a/Marlin/src/lcd/dogm/lcdprint_u8g.cpp +++ b/Marlin/src/lcd/dogm/lcdprint_u8g.cpp @@ -20,36 +20,36 @@ #include "u8g_fontutf8.h" #include "../lcdprint.h" -int lcd_glyph_height() { return u8g_GetFontBBXHeight(u8g->getU8g()); } +int lcd_glyph_height() { return u8g_GetFontBBXHeight(u8g.getU8g()); } -void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { u8g->setPrintPos(col, row); } +void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { u8g.setPrintPos(col, row); } -void lcd_put_int(const int i) { u8g->print(i); } +void lcd_put_int(const int i) { u8g.print(i); } // return < 0 on error // return the advanced pixels int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) { if (c < 256) { - u8g->print((char)c); - return u8g_GetFontBBXWidth(u8g->getU8g()); + u8g.print((char)c); + return u8g_GetFontBBXWidth(u8g.getU8g()); } - u8g_uint_t x = u8g->getPrintCol(), y = u8g->getPrintRow(), - ret = uxg_DrawWchar(u8g->getU8g(), x, y, c, max_length); - u8g->setPrintPos(x + ret, y); + u8g_uint_t x = u8g.getPrintCol(), y = u8g.getPrintRow(), + ret = uxg_DrawWchar(u8g.getU8g(), x, y, c, max_length); + u8g.setPrintPos(x + ret, y); return ret; } int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) { - u8g_uint_t x = u8g->getPrintCol(), y = u8g->getPrintRow(), - ret = uxg_DrawUtf8Str(u8g->getU8g(), x, y, utf8_str, max_length); - u8g->setPrintPos(x + ret, y); + u8g_uint_t x = u8g.getPrintCol(), y = u8g.getPrintRow(), + ret = uxg_DrawUtf8Str(u8g.getU8g(), x, y, utf8_str, max_length); + u8g.setPrintPos(x + ret, y); return ret; } int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) { - u8g_uint_t x = u8g->getPrintCol(), y = u8g->getPrintRow(), - ret = uxg_DrawUtf8StrP(u8g->getU8g(), x, y, utf8_str_P, max_length); - u8g->setPrintPos(x + ret, y); + u8g_uint_t x = u8g.getPrintCol(), y = u8g.getPrintRow(), + ret = uxg_DrawUtf8StrP(u8g.getU8g(), x, y, utf8_str_P, max_length); + u8g.setPrintPos(x + ret, y); return ret; } diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 09ae73e9ff86..dc60c1bff3be 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -76,7 +76,7 @@ #define FONT_STATUSMENU_NAME MENU_FONT_NAME #endif -U8G_CLASS* u8g = nullptr; +U8G_CLASS u8g; #include LANGUAGE_DATA_INCL(LCD_LANGUAGE) @@ -86,7 +86,7 @@ U8G_CLASS* u8g = nullptr; void MarlinUI::set_contrast(const int16_t value) { contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX); - u8g->setContrast(contrast); + u8g.setContrast(contrast); } #endif @@ -95,10 +95,10 @@ void MarlinUI::set_font(const MarlinFont font_nr) { static char currentfont = 0; if (font_nr != currentfont) { switch ((currentfont = font_nr)) { - case FONT_STATUSMENU : u8g->setFont(FONT_STATUSMENU_NAME); break; - case FONT_EDIT : u8g->setFont(EDIT_FONT_NAME); break; + case FONT_STATUSMENU : u8g.setFont(FONT_STATUSMENU_NAME); break; + case FONT_EDIT : u8g.setFont(EDIT_FONT_NAME); break; default: - case FONT_MENU : u8g->setFont(MENU_FONT_NAME); break; + case FONT_MENU : u8g.setFont(MENU_FONT_NAME); break; } } } @@ -129,15 +129,15 @@ bool MarlinUI::detected() { return true; } UNUSED(frame); - u8g->drawBitmapP(left, top, CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH, CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp); + u8g.drawBitmapP(left, top, CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH, CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp); #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED) if (frame == 0) { - u8g->setColorIndex(1); - if (top) u8g->drawBox(0, 0, LCD_PIXEL_WIDTH, top); - if (left) u8g->drawBox(0, top, left, CUSTOM_BOOTSCREEN_BMPHEIGHT); - if (right < LCD_PIXEL_WIDTH) u8g->drawBox(right, top, LCD_PIXEL_WIDTH - right, CUSTOM_BOOTSCREEN_BMPHEIGHT); - if (bottom < LCD_PIXEL_HEIGHT) u8g->drawBox(0, bottom, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT - bottom); + u8g.setColorIndex(1); + if (top) u8g.drawBox(0, 0, LCD_PIXEL_WIDTH, top); + if (left) u8g.drawBox(0, top, left, CUSTOM_BOOTSCREEN_BMPHEIGHT); + if (right < LCD_PIXEL_WIDTH) u8g.drawBox(right, top, LCD_PIXEL_WIDTH - right, CUSTOM_BOOTSCREEN_BMPHEIGHT); + if (bottom < LCD_PIXEL_HEIGHT) u8g.drawBox(0, bottom, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT - bottom); } #endif } @@ -158,8 +158,8 @@ bool MarlinUI::detected() { return true; } const uint8_t fr = _MIN(f, COUNT(custom_bootscreen_animation) - 1); const millis_t frame_time = pgm_read_word(&custom_bootscreen_animation[fr].duration); #endif - u8g->firstPage(); - do { draw_custom_bootscreen(f); } while (u8g->nextPage()); + u8g.firstPage(); + do { draw_custom_bootscreen(f); } while (u8g.nextPage()); if (frame_time) safe_delay(frame_time); } @@ -209,14 +209,14 @@ bool MarlinUI::detected() { return true; } NOLESS(offy, 0); auto _draw_bootscreen_bmp = [&](const uint8_t *bitmap) { - u8g->drawBitmapP(offx, offy, START_BMP_BYTEWIDTH, START_BMPHEIGHT, bitmap); + u8g.drawBitmapP(offx, offy, START_BMP_BYTEWIDTH, START_BMPHEIGHT, bitmap); set_font(FONT_MENU); if (!two_part || !line2) lcd_put_u8str_P(txt_offx_1, txt_base - (MENU_FONT_HEIGHT), PSTR(SHORT_BUILD_VERSION)); if (!two_part || line2) lcd_put_u8str_P(txt_offx_2, txt_base, PSTR(MARLIN_WEBSITE_URL)); }; auto draw_bootscreen_bmp = [&](const uint8_t *bitmap) { - u8g->firstPage(); do { _draw_bootscreen_bmp(bitmap); } while (u8g->nextPage()); + u8g.firstPage(); do { _draw_bootscreen_bmp(bitmap); } while (u8g.nextPage()); }; #if DISABLED(BOOT_MARLIN_LOGO_ANIMATED) @@ -252,6 +252,13 @@ bool MarlinUI::detected() { return true; } // Initialize or re-initialize the LCD void MarlinUI::init_lcd() { + + static bool did_init_u8g = false; + if (!did_init_u8g) { + u8g.init(U8G_PARAM); + did_init_u8g = true; + } + #if PIN_EXISTS(LCD_BACKLIGHT) OUT_WRITE(LCD_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); // Illuminate after reset or right away #endif @@ -269,7 +276,7 @@ void MarlinUI::init_lcd() { _delay_ms(5); WRITE(LCD_RESET_PIN, HIGH); _delay_ms(5); - u8g->begin(); + u8g.begin(); #endif #if PIN_EXISTS(LCD_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) @@ -278,9 +285,9 @@ void MarlinUI::init_lcd() { TERN_(HAS_LCD_CONTRAST, refresh_contrast()); - TERN_(LCD_SCREEN_ROT_90, u8g->setRot90()); - TERN_(LCD_SCREEN_ROT_180, u8g->setRot180()); - TERN_(LCD_SCREEN_ROT_270, u8g->setRot270()); + TERN_(LCD_SCREEN_ROT_90, u8g.setRot90()); + TERN_(LCD_SCREEN_ROT_180, u8g.setRot180()); + TERN_(LCD_SCREEN_ROT_270, u8g.setRot270()); uxg_SetUtf8Fonts(g_fontinfo, COUNT(g_fontinfo)); } @@ -288,14 +295,14 @@ void MarlinUI::init_lcd() { // The kill screen is displayed for unrecoverable conditions void MarlinUI::draw_kill_screen() { TERN_(LIGHTWEIGHT_UI, ST7920_Lite_Status_Screen::clear_text_buffer()); - const u8g_uint_t h4 = u8g->getHeight() / 4; - u8g->firstPage(); + const u8g_uint_t h4 = u8g.getHeight() / 4; + u8g.firstPage(); do { set_font(FONT_MENU); lcd_put_u8str(0, h4 * 1, status_message); lcd_put_u8str_P(0, h4 * 2, GET_TEXT(MSG_HALTED)); lcd_put_u8str_P(0, h4 * 3, GET_TEXT(MSG_PLEASE_RESET)); - } while (u8g->nextPage()); + } while (u8g.nextPage()); } void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop @@ -336,16 +343,16 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop if (sel) { #if ENABLED(MENU_HOLLOW_FRAME) - u8g->drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH); - u8g->drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH); + u8g.drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH); + u8g.drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH); #else - u8g->setColorIndex(1); // solid outline - u8g->drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, MENU_FONT_HEIGHT - 1); - u8g->setColorIndex(0); // inverted text + u8g.setColorIndex(1); // solid outline + u8g.drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, MENU_FONT_HEIGHT - 1); + u8g.setColorIndex(0); // inverted text #endif } #if DISABLED(MENU_HOLLOW_FRAME) - else u8g->setColorIndex(1); // solid text + else u8g.setColorIndex(1); // solid text #endif if (!PAGE_CONTAINS(row_y1, row_y2)) return false; @@ -388,7 +395,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char * const inStr, const bool pgm) { if (mark_as_selected(row, sel)) { const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen((char*)inStr)), - pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g->getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g->getU8g(), (char*)inStr)); + pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g.getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g.getU8g(), (char*)inStr)); pixel_len_t n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, LCD_WIDTH - 2 - vallen) * (MENU_FONT_WIDTH); if (vallen) { @@ -456,12 +463,12 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1; const pixel_len_t bw = len * prop * (MENU_FONT_WIDTH), bx = x * prop * (MENU_FONT_WIDTH); if (inv) { - u8g->setColorIndex(1); - u8g->drawBox(bx / prop - 1, by - (MENU_FONT_ASCENT) + 1, bw / prop + 2, MENU_FONT_HEIGHT - 1); - u8g->setColorIndex(0); + u8g.setColorIndex(1); + u8g.drawBox(bx / prop - 1, by - (MENU_FONT_ASCENT) + 1, bw / prop + 2, MENU_FONT_HEIGHT - 1); + u8g.setColorIndex(0); } lcd_put_u8str_P(bx / prop, by, pstr); - if (inv) u8g->setColorIndex(1); + if (inv) u8g.setColorIndex(1); } void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) { @@ -509,23 +516,23 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Clear the Mesh Map if (PAGE_CONTAINS(y_offset - 2, y_offset + y_map_pixels + 4)) { - u8g->setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box - u8g->drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4); + u8g.setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box + u8g.drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4); if (PAGE_CONTAINS(y_offset, y_offset + y_map_pixels)) { - u8g->setColorIndex(0); // Now actually clear the mesh map box - u8g->drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels); + u8g.setColorIndex(0); // Now actually clear the mesh map box + u8g.drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels); } } // Display Mesh Point Locations - u8g->setColorIndex(1); + u8g.setColorIndex(1); const u8g_uint_t sx = x_offset + pixels_per_x_mesh_pnt / 2; u8g_uint_t y = y_offset + pixels_per_y_mesh_pnt / 2; for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt) if (PAGE_CONTAINS(y, y)) for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt) - u8g->drawBox(x, y, 1, 1); + u8g.drawBox(x, y, 1, 1); // Fill in the Specified Mesh Point @@ -534,7 +541,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop const u8g_uint_t by = y_offset + y_plot_inv * pixels_per_y_mesh_pnt; if (PAGE_CONTAINS(by, by + pixels_per_y_mesh_pnt)) - u8g->drawBox( + u8g.drawBox( x_offset + x_plot * pixels_per_x_mesh_pnt, by, pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt ); @@ -542,7 +549,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Put Relevant Text on Display // Show X and Y positions at top of screen - u8g->setColorIndex(1); + u8g.setColorIndex(1); if (PAGE_UNDER(7)) { const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) }, lpos = pos.asLogical(); @@ -555,9 +562,9 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Print plot position if (PAGE_CONTAINS(LCD_PIXEL_HEIGHT - (INFO_FONT_HEIGHT - 1), LCD_PIXEL_HEIGHT)) { lcd_put_wchar(5, LCD_PIXEL_HEIGHT, '('); - u8g->print(x_plot); + u8g.print(x_plot); lcd_put_wchar(','); - u8g->print(y_plot); + u8g.print(y_plot); lcd_put_wchar(')'); // Show the location value @@ -686,15 +693,15 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop nozzle = TERN(USE_BIG_EDIT_FONT, 95, 60); // Draw nozzle lowered or raised according to direction moved - if (PAGE_CONTAINS( 3, 16)) u8g->drawBitmapP(nozzle + 6, 4 - dir, 2, 12, nozzle_bmp); - if (PAGE_CONTAINS(20, 20)) u8g->drawBitmapP(nozzle + 0, 20 , 3, 1, offset_bedline_bmp); + if (PAGE_CONTAINS( 3, 16)) u8g.drawBitmapP(nozzle + 6, 4 - dir, 2, 12, nozzle_bmp); + if (PAGE_CONTAINS(20, 20)) u8g.drawBitmapP(nozzle + 0, 20 , 3, 1, offset_bedline_bmp); // Draw cw/ccw indicator and up/down arrows. if (PAGE_CONTAINS(47, 62)) { - u8g->drawBitmapP(right + 0, 48 - dir, 2, 13, up_arrow_bmp); - u8g->drawBitmapP(left + 0, 49 - dir, 2, 13, down_arrow_bmp); - u8g->drawBitmapP(left + 13, 47 , 3, 16, rot_down); - u8g->drawBitmapP(right + 13, 47 , 3, 16, rot_up); + u8g.drawBitmapP(right + 0, 48 - dir, 2, 13, up_arrow_bmp); + u8g.drawBitmapP(left + 0, 49 - dir, 2, 13, down_arrow_bmp); + u8g.drawBitmapP(left + 13, 47 , 3, 16, rot_down); + u8g.drawBitmapP(right + 13, 47 , 3, 16, rot_up); } } diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.h b/Marlin/src/lcd/dogm/marlinui_DOGM.h index 2c0a3e75707c..e3ceb63f96b5 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.h +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.h @@ -227,8 +227,8 @@ #endif // For selective rendering within a Y range -#define PAGE_OVER(ya) ((ya) <= u8g->getU8g()->current_page.y1) // Does the current page follow a region top? -#define PAGE_UNDER(yb) ((yb) >= u8g->getU8g()->current_page.y0) // Does the current page precede a region bottom? -#define PAGE_CONTAINS(ya, yb) ((yb) >= u8g->getU8g()->current_page.y0 && (ya) <= u8g->getU8g()->current_page.y1) // Do two vertical regions overlap? +#define PAGE_OVER(ya) ((ya) <= u8g.getU8g()->current_page.y1) // Does the current page follow a region top? +#define PAGE_UNDER(yb) ((yb) >= u8g.getU8g()->current_page.y0) // Does the current page precede a region bottom? +#define PAGE_CONTAINS(ya, yb) ((yb) >= u8g.getU8g()->current_page.y0 && (ya) <= u8g.getU8g()->current_page.y1) // Do two vertical regions overlap? -extern U8G_CLASS* u8g; +extern U8G_CLASS u8g; diff --git a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp index ab763f831dd7..921dee0e34c0 100644 --- a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp +++ b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp @@ -268,12 +268,12 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co #if ENABLED(STATUS_HEAT_PERCENT) if (isHeat && tall <= BAR_TALL) { const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall; - u8g->drawBitmapP(hx, STATUS_HEATERS_Y, bw, ph, HOTEND_BITMAP(heater_id, false)); - u8g->drawBitmapP(hx, STATUS_HEATERS_Y + ph, bw, tall + 1, HOTEND_BITMAP(heater_id, true) + ph * bw); + u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, ph, HOTEND_BITMAP(heater_id, false)); + u8g.drawBitmapP(hx, STATUS_HEATERS_Y + ph, bw, tall + 1, HOTEND_BITMAP(heater_id, true) + ph * bw); } else #endif - u8g->drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(heater_id, isHeat)); + u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(heater_id, isHeat)); #endif } // PAGE_CONTAINS @@ -291,9 +291,9 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co _draw_centered_temp(temp, tx, 28); if (STATIC_HOTEND && HOTEND_DOT && PAGE_CONTAINS(17, 19)) { - u8g->setColorIndex(0); // set to white on black - u8g->drawBox(tx, 20 - 3, 2, 2); - u8g->setColorIndex(1); // restore black on white + u8g.setColorIndex(0); // set to white on black + u8g.drawBox(tx, 20 - 3, 2, 2); + u8g.setColorIndex(1); // restore black on white } } @@ -339,11 +339,11 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co if (isHeat) { const uint8_t bx = STATUS_BED_X + STATUS_BED_WIDTH; - u8g->drawFrame(bx, STATUS_HEATERS_Y, 3, STATUS_HEATERS_HEIGHT); + u8g.drawFrame(bx, STATUS_HEATERS_Y, 3, STATUS_HEATERS_HEIGHT); if (tall) { const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall; if (PAGE_OVER(STATUS_HEATERS_Y + ph)) - u8g->drawVLine(bx + 1, STATUS_HEATERS_Y + ph, tall); + u8g.drawVLine(bx + 1, STATUS_HEATERS_Y + ph, tall); } } @@ -364,9 +364,9 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co _draw_centered_temp(temp, tx, 28); if (STATIC_BED && BED_DOT && PAGE_CONTAINS(17, 19)) { - u8g->setColorIndex(0); // set to white on black - u8g->drawBox(tx, 20 - 2, 2, 2); - u8g->setColorIndex(1); // restore black on white + u8g.setColorIndex(0); // set to white on black + u8g.drawBox(tx, 20 - 2, 2, 2); + u8g.setColorIndex(1); // restore black on white } } @@ -562,13 +562,13 @@ void MarlinUI::draw_status_screen() { #if DO_DRAW_LOGO if (PAGE_CONTAINS(STATUS_LOGO_Y, STATUS_LOGO_Y + STATUS_LOGO_HEIGHT - 1)) - u8g->drawBitmapP(STATUS_LOGO_X, STATUS_LOGO_Y, STATUS_LOGO_BYTEWIDTH, STATUS_LOGO_HEIGHT, status_logo_bmp); + u8g.drawBitmapP(STATUS_LOGO_X, STATUS_LOGO_Y, STATUS_LOGO_BYTEWIDTH, STATUS_LOGO_HEIGHT, status_logo_bmp); #endif #if STATUS_HEATERS_WIDTH // Draw all heaters (and maybe the bed) in one go if (PAGE_CONTAINS(STATUS_HEATERS_Y, STATUS_HEATERS_Y + STATUS_HEATERS_HEIGHT - 1)) - u8g->drawBitmapP(STATUS_HEATERS_X, STATUS_HEATERS_Y, STATUS_HEATERS_BYTEWIDTH, STATUS_HEATERS_HEIGHT, status_heaters_bmp); + u8g.drawBitmapP(STATUS_HEATERS_X, STATUS_HEATERS_Y, STATUS_HEATERS_BYTEWIDTH, STATUS_HEATERS_HEIGHT, status_heaters_bmp); #endif #if DO_DRAW_CUTTER && DISABLED(STATUS_COMBINE_HEATERS) @@ -580,7 +580,7 @@ void MarlinUI::draw_status_screen() { const uint8_t cuttery = STATUS_CUTTER_Y(CUTTER_ALT()), cutterh = STATUS_CUTTER_HEIGHT(CUTTER_ALT()); if (PAGE_CONTAINS(cuttery, cuttery + cutterh - 1)) - u8g->drawBitmapP(STATUS_CUTTER_X, cuttery, STATUS_CUTTER_BYTEWIDTH, cutterh, CUTTER_BITMAP(CUTTER_ALT())); + u8g.drawBitmapP(STATUS_CUTTER_X, cuttery, STATUS_CUTTER_BYTEWIDTH, cutterh, CUTTER_BITMAP(CUTTER_ALT())); #endif #if DO_DRAW_BED && DISABLED(STATUS_COMBINE_HEATERS) @@ -592,7 +592,7 @@ void MarlinUI::draw_status_screen() { const uint8_t bedy = STATUS_BED_Y(BED_ALT()), bedh = STATUS_BED_HEIGHT(BED_ALT()); if (PAGE_CONTAINS(bedy, bedy + bedh - 1)) - u8g->drawBitmapP(STATUS_BED_X, bedy, STATUS_BED_BYTEWIDTH, bedh, BED_BITMAP(BED_ALT())); + u8g.drawBitmapP(STATUS_BED_X, bedy, STATUS_BED_BYTEWIDTH, bedh, BED_BITMAP(BED_ALT())); #endif #if DO_DRAW_CHAMBER && DISABLED(STATUS_COMBINE_HEATERS) @@ -604,7 +604,7 @@ void MarlinUI::draw_status_screen() { const uint8_t chambery = STATUS_CHAMBER_Y(CHAMBER_ALT()), chamberh = STATUS_CHAMBER_HEIGHT(CHAMBER_ALT()); if (PAGE_CONTAINS(chambery, chambery + chamberh - 1)) - u8g->drawBitmapP(STATUS_CHAMBER_X, chambery, STATUS_CHAMBER_BYTEWIDTH, chamberh, CHAMBER_BITMAP(CHAMBER_ALT())); + u8g.drawBitmapP(STATUS_CHAMBER_X, chambery, STATUS_CHAMBER_BYTEWIDTH, chamberh, CHAMBER_BITMAP(CHAMBER_ALT())); #endif #if DO_DRAW_FAN @@ -617,7 +617,7 @@ void MarlinUI::draw_status_screen() { } #endif if (PAGE_CONTAINS(STATUS_FAN_Y, STATUS_FAN_Y + STATUS_FAN_HEIGHT - 1)) - u8g->drawBitmapP(STATUS_FAN_X, STATUS_FAN_Y, STATUS_FAN_BYTEWIDTH, STATUS_FAN_HEIGHT, + u8g.drawBitmapP(STATUS_FAN_X, STATUS_FAN_Y, STATUS_FAN_BYTEWIDTH, STATUS_FAN_HEIGHT, #if STATUS_FAN_FRAMES > 2 fan_frame == 1 ? status_fan1_bmp : fan_frame == 2 ? status_fan2_bmp : @@ -660,7 +660,7 @@ void MarlinUI::draw_status_screen() { const uint8_t coolery = STATUS_COOLER_Y(status_cooler_bmp1), coolerh = STATUS_COOLER_HEIGHT(status_cooler_bmp1); if (PAGE_CONTAINS(coolery, coolery + coolerh - 1)) - u8g->drawBitmapP(STATUS_COOLER_X, coolery, STATUS_COOLER_BYTEWIDTH, coolerh, blink && cooler.enabled ? status_cooler_bmp2 : status_cooler_bmp1); + u8g.drawBitmapP(STATUS_COOLER_X, coolery, STATUS_COOLER_BYTEWIDTH, coolerh, blink && cooler.enabled ? status_cooler_bmp2 : status_cooler_bmp1); #endif // Laser Cooler Flow Meter @@ -668,7 +668,7 @@ void MarlinUI::draw_status_screen() { const uint8_t flowmetery = STATUS_FLOWMETER_Y(status_flowmeter_bmp1), flowmeterh = STATUS_FLOWMETER_HEIGHT(status_flowmeter_bmp1); if (PAGE_CONTAINS(flowmetery, flowmetery + flowmeterh - 1)) - u8g->drawBitmapP(STATUS_FLOWMETER_X, flowmetery, STATUS_FLOWMETER_BYTEWIDTH, flowmeterh, blink && cooler.flowpulses ? status_flowmeter_bmp2 : status_flowmeter_bmp1); + u8g.drawBitmapP(STATUS_FLOWMETER_X, flowmetery, STATUS_FLOWMETER_BYTEWIDTH, flowmeterh, blink && cooler.flowpulses ? status_flowmeter_bmp2 : status_flowmeter_bmp1); #endif @@ -709,13 +709,13 @@ void MarlinUI::draw_status_screen() { // if (card.isFileOpen() && PAGE_CONTAINS(42, 51)) { // Upper box - u8g->drawBox(42, 42, 8, 7); // 42-48 (or 41-47) + u8g.drawBox(42, 42, 8, 7); // 42-48 (or 41-47) // Right edge - u8g->drawBox(50, 44, 2, 5); // 44-48 (or 43-47) + u8g.drawBox(50, 44, 2, 5); // 44-48 (or 43-47) // Bottom hollow box - u8g->drawFrame(42, 49, 10, 4); // 49-52 (or 48-51) + u8g.drawFrame(42, 49, 10, 4); // 49-52 (or 48-51) // Corner pixel - u8g->drawPixel(50, 43); // 43 (or 42) + u8g.drawPixel(50, 43); // 43 (or 42) } #endif // SDSUPPORT @@ -725,14 +725,14 @@ void MarlinUI::draw_status_screen() { // if (PAGE_CONTAINS(PROGRESS_BAR_Y, PROGRESS_BAR_Y + 3)) - u8g->drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, 4); + u8g.drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, 4); // // Progress bar solid part // if (PAGE_CONTAINS(PROGRESS_BAR_Y + 1, PROGRESS_BAR_Y + 2)) - u8g->drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, 2); + u8g.drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, 2); if (PAGE_CONTAINS(EXTRAS_BASELINE - INFO_FONT_ASCENT, EXTRAS_BASELINE - 1)) { @@ -805,16 +805,16 @@ void MarlinUI::draw_status_screen() { #if DISABLED(XYZ_NO_FRAME) #if ENABLED(XYZ_HOLLOW_FRAME) - u8g->drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39 + u8g.drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39 #else - u8g->drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37 + u8g.drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37 #endif #endif if (PAGE_CONTAINS(XYZ_BASELINE - (INFO_FONT_ASCENT - 1), XYZ_BASELINE)) { #if NONE(XYZ_NO_FRAME, XYZ_HOLLOW_FRAME) - u8g->setColorIndex(0); // white on black + u8g.setColorIndex(0); // white on black #endif #if HAS_DUAL_MIXING @@ -859,7 +859,7 @@ void MarlinUI::draw_status_screen() { _draw_axis_value(Z_AXIS, zstring, blink); #if NONE(XYZ_NO_FRAME, XYZ_HOLLOW_FRAME) - u8g->setColorIndex(1); // black on white + u8g.setColorIndex(1); // black on white #endif } } diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp index a9af0e8e9ff4..682178efe521 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp @@ -522,7 +522,7 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, do { set_font(FONT_MENU); lcd_put_u8str(0, LCD_PIXEL_HEIGHT / 2, str); - } while (u8g->nextPage()); + } while (u8g.nextPage()); drawing_screen = false; safe_delay(250); if (calibration_stage == CALIBRATION_SUCCESS) { diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index e60bddbc7306..149da8b54e5d 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -349,17 +349,8 @@ millis_t MarlinUI::next_button_update_ms; // = 0 #endif // HAS_LCD_MENU -#if HAS_MARLINUI_U8GLIB - static void u8gInit() { - static U8G_CLASS _u8g(U8G_PARAM); - u8g = &_u8g; - } -#endif - void MarlinUI::init() { - #if HAS_MARLINUI_U8GLIB - u8gInit(); - #endif + init_lcd(); #if HAS_DIGITAL_BUTTONS @@ -1071,18 +1062,18 @@ void MarlinUI::update() { if (do_u8g_loop) { if (!drawing_screen) { // If not already drawing pages - u8g->firstPage(); // Start the first page + u8g.firstPage(); // Start the first page drawing_screen = first_page = true; // Flag as drawing pages } set_font(FONT_MENU); // Setup font for every page draw - u8g->setColorIndex(1); // And reset the color + u8g.setColorIndex(1); // And reset the color run_current_screen(); // Draw and process the current screen first_page = false; // The screen handler can clear drawing_screen for an action that changes the screen. // If still drawing and there's another page, update max-time and return now. // The nextPage will already be set up on the next call. - if (drawing_screen && (drawing_screen = u8g->nextPage())) { + if (drawing_screen && (drawing_screen = u8g.nextPage())) { if (on_status_screen()) NOLESS(max_display_update_time, millis() - ms); return; diff --git a/Marlin/src/lcd/menu/game/brickout.cpp b/Marlin/src/lcd/menu/game/brickout.cpp index 9fb391c00ee4..4bdc9243801e 100644 --- a/Marlin/src/lcd/menu/game/brickout.cpp +++ b/Marlin/src/lcd/menu/game/brickout.cpp @@ -136,7 +136,7 @@ void BrickoutGame::game_screen() { } while (false); } - u8g->setColorIndex(1); + u8g.setColorIndex(1); // Draw bricks if (PAGE_CONTAINS(BRICK_TOP, BRICK_BOT)) { @@ -148,7 +148,7 @@ void BrickoutGame::game_screen() { const uint8_t xx = x * BRICK_W; LOOP_L_N(v, BRICK_H - 1) if (PAGE_CONTAINS(yy + v, yy + v)) - u8g->drawHLine(xx, yy + v, BRICK_W - 1); + u8g.drawHLine(xx, yy + v, BRICK_W - 1); } } } @@ -157,11 +157,11 @@ void BrickoutGame::game_screen() { // Draw paddle if (PAGE_CONTAINS(PADDLE_Y-1, PADDLE_Y)) { - u8g->drawHLine(bdat.paddle_x, PADDLE_Y, PADDLE_W); + u8g.drawHLine(bdat.paddle_x, PADDLE_Y, PADDLE_W); #if PADDLE_H > 1 - u8g->drawHLine(bdat.paddle_x, PADDLE_Y-1, PADDLE_W); + u8g.drawHLine(bdat.paddle_x, PADDLE_Y-1, PADDLE_W); #if PADDLE_H > 2 - u8g->drawHLine(bdat.paddle_x, PADDLE_Y-2, PADDLE_W); + u8g.drawHLine(bdat.paddle_x, PADDLE_Y-2, PADDLE_W); #endif #endif } @@ -170,7 +170,7 @@ void BrickoutGame::game_screen() { if (game_state) { const uint8_t by = FTOB(bdat.bally); if (PAGE_CONTAINS(by, by+1)) - u8g->drawFrame(FTOB(bdat.ballx), by, 2, 2); + u8g.drawFrame(FTOB(bdat.ballx), by, 2, 2); } // Or draw GAME OVER else diff --git a/Marlin/src/lcd/menu/game/game.cpp b/Marlin/src/lcd/menu/game/game.cpp index 2fd32f065533..c14bd2a68df8 100644 --- a/Marlin/src/lcd/menu/game/game.cpp +++ b/Marlin/src/lcd/menu/game/game.cpp @@ -45,9 +45,9 @@ void MarlinGame::draw_game_over() { lx = (LCD_PIXEL_WIDTH - gowide) / 2, ly = (LCD_PIXEL_HEIGHT + gohigh) / 2; if (PAGE_CONTAINS(ly - gohigh - 1, ly + 1)) { - u8g->setColorIndex(0); - u8g->drawBox(lx - 1, ly - gohigh - 1, gowide + 2, gohigh + 2); - u8g->setColorIndex(1); + u8g.setColorIndex(0); + u8g.drawBox(lx - 1, ly - gohigh - 1, gowide + 2, gohigh + 2); + u8g.setColorIndex(1); if (ui.get_blink()) lcd_put_u8str_P(lx, ly, PSTR("GAME OVER")); } } diff --git a/Marlin/src/lcd/menu/game/invaders.cpp b/Marlin/src/lcd/menu/game/invaders.cpp index 08128b6e4f97..56e4c224dd14 100644 --- a/Marlin/src/lcd/menu/game/invaders.cpp +++ b/Marlin/src/lcd/menu/game/invaders.cpp @@ -366,7 +366,7 @@ void InvadersGame::game_screen() { if (!idat.quit_count) exit_game(); - u8g->setColorIndex(1); + u8g.setColorIndex(1); // Draw invaders if (PAGE_CONTAINS(idat.pos.y, idat.pos.y + idat.botmost * (INVADER_ROW_H) - 2 - 1)) { @@ -377,7 +377,7 @@ void InvadersGame::game_screen() { int8_t xx = idat.pos.x; LOOP_L_N(x, INVADER_COLS) { if (TEST(idat.bugs[y], x)) - u8g->drawBitmapP(xx, yy, 2, INVADER_H, invader[type][idat.game_blink]); + u8g.drawBitmapP(xx, yy, 2, INVADER_H, invader[type][idat.game_blink]); xx += INVADER_COL_W; } } @@ -387,25 +387,25 @@ void InvadersGame::game_screen() { // Draw UFO if (idat.ufov && PAGE_UNDER(UFO_H + 2)) - u8g->drawBitmapP(idat.ufox, 2, 2, UFO_H, ufo); + u8g.drawBitmapP(idat.ufox, 2, 2, UFO_H, ufo); // Draw cannon if (game_state && PAGE_CONTAINS(CANNON_Y, CANNON_Y + CANNON_H - 1) && (game_state < 2 || (game_state & 0x02))) - u8g->drawBitmapP(idat.cannon_x, CANNON_Y, 2, CANNON_H, cannon); + u8g.drawBitmapP(idat.cannon_x, CANNON_Y, 2, CANNON_H, cannon); // Draw laser if (idat.laser.v && PAGE_CONTAINS(idat.laser.y, idat.laser.y + LASER_H - 1)) - u8g->drawVLine(idat.laser.x, idat.laser.y, LASER_H); + u8g.drawVLine(idat.laser.x, idat.laser.y, LASER_H); // Draw invader bullets LOOP_L_N (i, COUNT(idat.bullet)) { if (idat.bullet[i].v && PAGE_CONTAINS(idat.bullet[i].y - (SHOT_H - 1), idat.bullet[i].y)) - u8g->drawVLine(idat.bullet[i].x, idat.bullet[i].y - (SHOT_H - 1), SHOT_H); + u8g.drawVLine(idat.bullet[i].x, idat.bullet[i].y - (SHOT_H - 1), SHOT_H); } // Draw explosion if (idat.explod.v && PAGE_CONTAINS(idat.explod.y, idat.explod.y + 7 - 1)) { - u8g->drawBitmapP(idat.explod.x, idat.explod.y, 2, 7, explosion); + u8g.drawBitmapP(idat.explod.x, idat.explod.y, 2, 7, explosion); --idat.explod.v; } @@ -421,7 +421,7 @@ void InvadersGame::game_screen() { // Draw lives if (idat.cannons_left) for (uint8_t i = 1; i <= idat.cannons_left; ++i) - u8g->drawBitmapP(LCD_PIXEL_WIDTH - i * (LIFE_W), 6 - (LIFE_H), 1, LIFE_H, life); + u8g.drawBitmapP(LCD_PIXEL_WIDTH - i * (LIFE_W), 6 - (LIFE_H), 1, LIFE_H, life); } } diff --git a/Marlin/src/lcd/menu/game/maze.cpp b/Marlin/src/lcd/menu/game/maze.cpp index 99b8e292d97e..85f752ee7de5 100644 --- a/Marlin/src/lcd/menu/game/maze.cpp +++ b/Marlin/src/lcd/menu/game/maze.cpp @@ -77,7 +77,7 @@ void MazeGame::game_screen() { } while(0); - u8g->setColorIndex(1); + u8g.setColorIndex(1); // Draw Score if (PAGE_UNDER(HEADER_H)) lcd_put_int(0, HEADER_H - 1, score); @@ -88,11 +88,11 @@ void MazeGame::game_screen() { // if (p.x == q.x) { // const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y)); // if (PAGE_CONTAINS(y1, y2)) - // u8g->drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); + // u8g.drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); // } // else if (PAGE_CONTAINS(GAMEY(p.y), GAMEY(p.y))) { // const int8_t x1 = GAMEX(_MIN(p.x, q.x)), x2 = GAMEX(_MAX(p.x, q.x)); - // u8g->drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); + // u8g.drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); // } // } @@ -100,22 +100,22 @@ void MazeGame::game_screen() { // const int8_t fy = GAMEY(foody); // if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) { // const int8_t fx = GAMEX(foodx); - // u8g->drawFrame(fx, fy, FOOD_WH, FOOD_WH); - // if (FOOD_WH == 5) u8g->drawPixel(fx + 2, fy + 2); + // u8g.drawFrame(fx, fy, FOOD_WH, FOOD_WH); + // if (FOOD_WH == 5) u8g.drawPixel(fx + 2, fy + 2); // } // Draw Ghosts // const int8_t fy = GAMEY(foody); // if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) { // const int8_t fx = GAMEX(foodx); - // u8g->drawFrame(fx, fy, FOOD_WH, FOOD_WH); - // if (FOOD_WH == 5) u8g->drawPixel(fx + 2, fy + 2); + // u8g.drawFrame(fx, fy, FOOD_WH, FOOD_WH); + // if (FOOD_WH == 5) u8g.drawPixel(fx + 2, fy + 2); // } // Draw Prize // if (PAGE_CONTAINS(prizey, prizey + PRIZE_WH - 1)) { - // u8g->drawFrame(prizex, prizey, PRIZE_WH, PRIZE_WH); - // if (PRIZE_WH == 5) u8g->drawPixel(prizex + 2, prizey + 2); + // u8g.drawFrame(prizex, prizey, PRIZE_WH, PRIZE_WH); + // if (PRIZE_WH == 5) u8g.drawPixel(prizex + 2, prizey + 2); // } // Draw GAME OVER diff --git a/Marlin/src/lcd/menu/game/snake.cpp b/Marlin/src/lcd/menu/game/snake.cpp index 2e587fe55f64..f8892a4e7a39 100644 --- a/Marlin/src/lcd/menu/game/snake.cpp +++ b/Marlin/src/lcd/menu/game/snake.cpp @@ -228,13 +228,13 @@ void SnakeGame::game_screen() { } while(0); - u8g->setColorIndex(1); + u8g.setColorIndex(1); // Draw Score if (PAGE_UNDER(HEADER_H)) lcd_put_int(0, HEADER_H - 1, score); // DRAW THE PLAYFIELD BORDER - u8g->drawFrame(BOARD_L - 2, BOARD_T - 2, BOARD_R - BOARD_L + 4, BOARD_B - BOARD_T + 4); + u8g.drawFrame(BOARD_L - 2, BOARD_T - 2, BOARD_R - BOARD_L + 4, BOARD_B - BOARD_T + 4); // Draw the snake (tail) #if SNAKE_WH < 2 @@ -245,11 +245,11 @@ void SnakeGame::game_screen() { if (p.x == q.x) { const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y)); if (PAGE_CONTAINS(y1, y2)) - u8g->drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); + u8g.drawVLine(GAMEX(p.x), y1, y2 - y1 + 1); } else if (PAGE_CONTAINS(GAMEY(p.y), GAMEY(p.y))) { const int8_t x1 = GAMEX(_MIN(p.x, q.x)), x2 = GAMEX(_MAX(p.x, q.x)); - u8g->drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); + u8g.drawHLine(x1, GAMEY(p.y), x2 - x1 + 1); } } @@ -261,13 +261,13 @@ void SnakeGame::game_screen() { if (p.x == q.x) { const int8_t y1 = GAMEY(_MIN(p.y, q.y)), y2 = GAMEY(_MAX(p.y, q.y)); if (PAGE_CONTAINS(y1, y2 + 1)) - u8g->drawFrame(GAMEX(p.x), y1, 2, y2 - y1 + 1 + 1); + u8g.drawFrame(GAMEX(p.x), y1, 2, y2 - y1 + 1 + 1); } else { const int8_t py = GAMEY(p.y); if (PAGE_CONTAINS(py, py + 1)) { const int8_t x1 = GAMEX(_MIN(p.x, q.x)), x2 = GAMEX(_MAX(p.x, q.x)); - u8g->drawFrame(x1, py, x2 - x1 + 1 + 1, 2); + u8g.drawFrame(x1, py, x2 - x1 + 1 + 1, 2); } } } @@ -283,7 +283,7 @@ void SnakeGame::game_screen() { for (int8_t i = y1; i <= y2; ++i) { const int8_t y = GAMEY(i); if (PAGE_CONTAINS(y, y + SNAKE_SIZ - 1)) - u8g->drawBox(GAMEX(p.x), y, SNAKE_SIZ, SNAKE_SIZ); + u8g.drawBox(GAMEX(p.x), y, SNAKE_SIZ, SNAKE_SIZ); } } } @@ -292,7 +292,7 @@ void SnakeGame::game_screen() { if (PAGE_CONTAINS(py, py + SNAKE_SIZ - 1)) { const int8_t x1 = _MIN(p.x, q.x), x2 = _MAX(p.x, q.x); for (int8_t i = x1; i <= x2; ++i) - u8g->drawBox(GAMEX(i), py, SNAKE_SIZ, SNAKE_SIZ); + u8g.drawBox(GAMEX(i), py, SNAKE_SIZ, SNAKE_SIZ); } } } @@ -303,8 +303,8 @@ void SnakeGame::game_screen() { const int8_t fy = GAMEY(sdat.foody); if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) { const int8_t fx = GAMEX(sdat.foodx); - u8g->drawFrame(fx, fy, FOOD_WH, FOOD_WH); - if (FOOD_WH == 5) u8g->drawPixel(fx + 2, fy + 2); + u8g.drawFrame(fx, fy, FOOD_WH, FOOD_WH); + if (FOOD_WH == 5) u8g.drawPixel(fx + 2, fy + 2); } // Draw GAME OVER diff --git a/ini/features.ini b/ini/features.ini index 10eafdc559b1..75681f191385 100644 --- a/ini/features.ini +++ b/ini/features.ini @@ -35,7 +35,7 @@ USES_LIQUIDCRYSTAL_I2C = marcoschwartz/LiquidCrystal_I2C@1.1.4 USES_LIQUIDTWI2 = LiquidTWI2@1.2.7 HAS_WIRED_LCD = src_filter=+ HAS_MARLINUI_HD44780 = src_filter=+ -HAS_MARLINUI_U8GLIB = U8glib-HAL@~0.4.1 +HAS_MARLINUI_U8GLIB = U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip src_filter=+ HAS_(FSMC|SPI|LTDC)_TFT = src_filter=+ + + HAS_FSMC_TFT = src_filter=+ + From c188a4164c69d7d3aa9e2cc1971abbb20166e489 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 8 Apr 2021 13:36:47 -0500 Subject: [PATCH 4/4] Published U8glib-HAL 0.4.4 --- ini/features.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ini/features.ini b/ini/features.ini index 75681f191385..864befa7a803 100644 --- a/ini/features.ini +++ b/ini/features.ini @@ -35,7 +35,7 @@ USES_LIQUIDCRYSTAL_I2C = marcoschwartz/LiquidCrystal_I2C@1.1.4 USES_LIQUIDTWI2 = LiquidTWI2@1.2.7 HAS_WIRED_LCD = src_filter=+ HAS_MARLINUI_HD44780 = src_filter=+ -HAS_MARLINUI_U8GLIB = U8glib-HAL=https://github.com/MarlinFirmware/U8glib-HAL/archive/bugfix.zip +HAS_MARLINUI_U8GLIB = U8glib-HAL@~0.4.4 src_filter=+ HAS_(FSMC|SPI|LTDC)_TFT = src_filter=+ + + HAS_FSMC_TFT = src_filter=+ +