From 7a569ad4d06d2d5541b76f03942cf4d7ab5bc119 Mon Sep 17 00:00:00 2001 From: Marcio Teixeira Date: Mon, 16 Sep 2019 15:49:46 -0600 Subject: [PATCH] LULZBOT_TOUCH_UI fixes. Fix some warnings. (#15276) --- Marlin/src/core/macros.h | 2 +- Marlin/src/feature/pause.cpp | 2 ++ .../lcd/dogm/status_screen_lite_ST7920.cpp | 2 ++ .../ftdi_eve_lib/extended/command_processor.h | 32 ++++++++++++++--- .../ftdi_eve_lib/extended/unicode/unicode.cpp | 2 +- .../lib/lulzbot/screens/base_screen.cpp | 7 ++-- .../lulzbot/screens/bio_advanced_settings.cpp | 12 +++---- .../screens/bio_printing_dialog_box.cpp | 4 +-- .../lib/lulzbot/screens/bio_status_screen.cpp | 35 ++++++++++--------- .../lulzbot/screens/dialog_box_base_class.cpp | 4 +++ .../lulzbot/screens/endstop_state_screen.cpp | 3 +- .../lib/lulzbot/screens/files_screen.cpp | 10 ++++-- .../lib/lulzbot/screens/screens.h | 3 +- .../lulzbot/screens/spinner_dialog_box.cpp | 1 + .../lib/lulzbot/screens/status_screen.cpp | 7 ++-- Marlin/src/lcd/extensible_ui/ui_api.cpp | 7 ++++ 16 files changed, 92 insertions(+), 41 deletions(-) diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index d65b8221f3..d092de9ca2 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -63,7 +63,7 @@ // Macros for bit masks #undef _BV #define _BV(n) (1<<(n)) -#define TEST(n,b) !!((n)&_BV(b)) +#define TEST(n,b) (!!((n)&_BV(b))) #define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0) #ifndef SBI diff --git a/Marlin/src/feature/pause.cpp b/Marlin/src/feature/pause.cpp index fb3177d8f4..d8642cf362 100644 --- a/Marlin/src/feature/pause.cpp +++ b/Marlin/src/feature/pause.cpp @@ -500,6 +500,8 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep #if HAS_BUZZER filament_change_beep(max_beep_count, true); + #else + UNUSED(max_beep_count); #endif // Start the heater idle timers diff --git a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp index 287e8d2582..660cf07673 100644 --- a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp +++ b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp @@ -612,6 +612,8 @@ void ST7920_Lite_Status_Screen::draw_feedrate_percentage(const uint16_t percenta begin_data(); write_number(percentage, 3); write_byte('%'); + #else + UNUSED(percentage); #endif } diff --git a/Marlin/src/lcd/extensible_ui/lib/lulzbot/ftdi_eve_lib/extended/command_processor.h b/Marlin/src/lcd/extensible_ui/lib/lulzbot/ftdi_eve_lib/extended/command_processor.h index 0fd7889a17..3d31328ae1 100644 --- a/Marlin/src/lcd/extensible_ui/lib/lulzbot/ftdi_eve_lib/extended/command_processor.h +++ b/Marlin/src/lcd/extensible_ui/lib/lulzbot/ftdi_eve_lib/extended/command_processor.h @@ -28,6 +28,11 @@ typedef struct { uint32_t rgb; } btn_colors; +// Disable TOUCH_UI_FIT_TEXT on a case-by-case basis +namespace FTDI { + constexpr uint16_t OPT_NOFIT = OPT_NOTICKS; +} + /**************************** Enhanced Command Processor **************************/ /* The CommandProcessor class wraps the CommandFifo with several features to make @@ -305,7 +310,7 @@ class CommandProcessor : public CLCD::CommandFifo { int8_t apply_fit_text(int16_t w, int16_t h, T text) { using namespace FTDI; int8_t font = _font; - for (;;) { + for (;font >= 26;) { #ifdef TOUCH_UI_USE_UTF8 const int16_t width = get_utf8_text_width(text, font_size_t::from_romfont(font)); const int16_t height = font_size_t::from_romfont(font).get_height(); @@ -314,7 +319,7 @@ class CommandProcessor : public CLCD::CommandFifo { const int16_t width = fm.get_text_width(text); const int16_t height = fm.height; #endif - if ((width < w && height < h) || font == 26) break; + if (width < w && height < h) break; font--; } return font; @@ -327,12 +332,23 @@ class CommandProcessor : public CLCD::CommandFifo { return *this; } + template + uint16_t text_width(T text) { + using namespace FTDI; + #ifdef TOUCH_UI_USE_UTF8 + return get_utf8_text_width(text, font_size_t::from_romfont(_font)); + #else + CLCD::FontMetrics fm(_font); + return fm.get_text_width(text); + #endif + } + template CommandProcessor& text(int16_t x, int16_t y, int16_t w, int16_t h, T text, uint16_t options = FTDI::OPT_CENTER) { using namespace FTDI; apply_text_alignment(x, y, w, h, options); #ifdef TOUCH_UI_FIT_TEXT - const int8_t font = apply_fit_text(w, h, text); + const int8_t font = (options & OPT_NOFIT) ? _font : apply_fit_text(w, h, text); #else const int8_t font = _font; #endif @@ -367,7 +383,7 @@ class CommandProcessor : public CLCD::CommandFifo { bool styleModified = false; if (_btn_style_callback) styleModified = _btn_style_callback(*this, _tag, _style, options, false); #ifdef TOUCH_UI_FIT_TEXT - const int8_t font = apply_fit_text(w, h, text); + const int8_t font = (options & OPT_NOFIT) ? _font : apply_fit_text(w, h, text); #else const int8_t font = _font; #endif @@ -375,6 +391,14 @@ class CommandProcessor : public CLCD::CommandFifo { #ifdef TOUCH_UI_USE_UTF8 apply_text_alignment(x, y, w, h, OPT_CENTER); CLCD::CommandFifo::str(F("")); + if (!(options & FTDI::OPT_FLAT)) { + // Reproduce the black "shadow" the FTDI adds to the button label + CLCD::CommandFifo::cmd(SAVE_CONTEXT()); + CLCD::CommandFifo::cmd(COLOR_RGB(0x00000)); + draw_utf8_text(*this, x-1, y-1, text, font_size_t::from_romfont(font), OPT_CENTER); + CLCD::CommandFifo::cmd(RESTORE_CONTEXT()); + } + // Draw the button label draw_utf8_text(*this, x, y, text, font_size_t::from_romfont(font), OPT_CENTER); #else CLCD::CommandFifo::str(text); diff --git a/Marlin/src/lcd/extensible_ui/lib/lulzbot/ftdi_eve_lib/extended/unicode/unicode.cpp b/Marlin/src/lcd/extensible_ui/lib/lulzbot/ftdi_eve_lib/extended/unicode/unicode.cpp index 48b0883fa7..7900b18870 100644 --- a/Marlin/src/lcd/extensible_ui/lib/lulzbot/ftdi_eve_lib/extended/unicode/unicode.cpp +++ b/Marlin/src/lcd/extensible_ui/lib/lulzbot/ftdi_eve_lib/extended/unicode/unicode.cpp @@ -142,7 +142,7 @@ uint16_t FTDI::get_utf8_text_width(progmem_str pstr, font_size_t fs) { char str[strlen_P((const char*)pstr) + 1]; strcpy_P(str, (const char*)pstr); - return get_utf8_text_width((const char*) pstr, fs); + return get_utf8_text_width(str, fs); } /** diff --git a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/base_screen.cpp b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/base_screen.cpp index 3dc356c530..662a55439a 100644 --- a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/base_screen.cpp +++ b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/base_screen.cpp @@ -32,6 +32,7 @@ using namespace Theme; void BaseScreen::onEntry() { CommandProcessor cmd; cmd.set_button_style_callback(buttonStyleCallback); + reset_menu_timeout(); UIScreen::onEntry(); } @@ -62,9 +63,11 @@ bool BaseScreen::buttonStyleCallback(CommandProcessor &cmd, uint8_t tag, uint8_t void BaseScreen::onIdle() { #ifdef LCD_TIMEOUT_TO_STATUS - const uint32_t elapsed = millis() - last_interaction; - if (elapsed > uint32_t(LCD_TIMEOUT_TO_STATUS)) { + if ((millis() - last_interaction) > LCD_TIMEOUT_TO_STATUS) { reset_menu_timeout(); + #ifdef UI_FRAMEWORK_DEBUG + SERIAL_ECHO_MSG("Returning to status due to menu timeout"); + #endif GOTO_SCREEN(StatusScreen); } #endif diff --git a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_advanced_settings.cpp b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_advanced_settings.cpp index da02d24f18..c42cbe2e54 100644 --- a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_advanced_settings.cpp +++ b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_advanced_settings.cpp @@ -55,23 +55,23 @@ void AdvancedSettingsMenu::onRedraw(draw_mode_t what) { #else .enabled(0) #endif - .tag(4) .button( BTN_POS(1,3), BTN_SIZE(1,1), GET_TEXTF(BUMP_SENSE)) + .tag(4) .button( BTN_POS(1,3), BTN_SIZE(1,1), GET_TEXTF(HOME_SENSE)) .tag(5) .button( BTN_POS(1,4), BTN_SIZE(1,1), GET_TEXTF(ENDSTOPS)) #if HOTENDS > 1 .enabled(1) #else .enabled(0) #endif - .tag(6) .button( BTN_POS(1,5), BTN_SIZE(1,1), GET_TEXTF(NOZZLE_OFFSETS)) + .tag(6) .button( BTN_POS(1,5), BTN_SIZE(1,1), GET_TEXTF(TOOL_OFFSETS)) .tag(7) .button( BTN_POS(2,1), BTN_SIZE(1,1), GET_TEXTF(STEPS_PER_MM)) - .tag(8) .button( BTN_POS(2,2), BTN_SIZE(1,1), GET_TEXTF(MAX_VELOCITY)) - .tag(9) .button( BTN_POS(2,3), BTN_SIZE(1,1), GET_TEXTF(MAX_ACCELERATION)) + .tag(8) .button( BTN_POS(2,2), BTN_SIZE(1,1), GET_TEXTF(VELOCITY)) + .tag(9) .button( BTN_POS(2,3), BTN_SIZE(1,1), GET_TEXTF(ACCELERATION)) #if ENABLED(JUNCTION_DEVIATION) .tag(10) .button( BTN_POS(2,4), BTN_SIZE(1,1), GET_TEXTF(JUNCTION_DEVIATION)) #else - .tag(10) .button( BTN_POS(2,4), BTN_SIZE(1,1), GET_TEXTF(MAX_JERK)) + .tag(10) .button( BTN_POS(2,4), BTN_SIZE(1,1), GET_TEXTF(JERK)) #endif #if ENABLED(BACKLASH_GCODE) .enabled(1) @@ -86,7 +86,7 @@ void AdvancedSettingsMenu::onRedraw(draw_mode_t what) { #endif .tag(12) .button( BTN_POS(1,6), BTN_SIZE(2,1), GET_TEXTF(LINEAR_ADVANCE)) .tag(13) .button( BTN_POS(1,7), BTN_SIZE(2,1), GET_TEXTF(INTERFACE_SETTINGS)) - .tag(14) .button( BTN_POS(1,8), BTN_SIZE(2,1), GET_TEXTF(RESTORE_FAILSAFE)) + .tag(14) .button( BTN_POS(1,8), BTN_SIZE(2,1), GET_TEXTF(RESTORE_DEFAULTS)) .colors(action_btn) .tag(1). button( BTN_POS(1,9), BTN_SIZE(2,1), GET_TEXTF(BACK)); #undef GRID_COLS diff --git a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_printing_dialog_box.cpp b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_printing_dialog_box.cpp index e77f047848..93e3335574 100644 --- a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_printing_dialog_box.cpp +++ b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_printing_dialog_box.cpp @@ -113,8 +113,8 @@ bool BioPrintingDialogBox::onTouchEnd(uint8_t tag) { } void BioPrintingDialogBox::setStatusMessage(progmem_str message) { - char buff[strlen_P((const char * const)message)+1]; - strcpy_P(buff, (const char * const) message); + char buff[strlen_P((const char*)message)+1]; + strcpy_P(buff, (const char*) message); setStatusMessage(buff); } diff --git a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_status_screen.cpp b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_status_screen.cpp index 7c55d962c4..a2779e22dd 100644 --- a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_status_screen.cpp +++ b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_status_screen.cpp @@ -82,6 +82,10 @@ void StatusScreen::draw_temperature(draw_mode_t what) { .icon (x + 2, y + 2, h, v, Bed_Heat_Icon_Info, icon_scale * 2) .cmd(COLOR_RGB(bg_text_enabled)) .icon (x, y, h, v, Bed_Heat_Icon_Info, icon_scale * 2); + + #ifdef TOUCH_UI_USE_UTF8 + load_utf8_bitmaps(cmd); // Restore font bitmap handles + #endif } if (what & FOREGROUND) { @@ -91,12 +95,12 @@ void StatusScreen::draw_temperature(draw_mode_t what) { .cmd(COLOR_RGB(bg_text_enabled)); if (!isHeaterIdle(BED) && getTargetTemp_celsius(BED) > 0) { - sprintf_P(bed_str, F("%3d%S"), ROUND(getTargetTemp_celsius(BED), GET_TEXT(UNITS_C))); + sprintf_P(bed_str, PSTR("%3d%S"), ROUND(getTargetTemp_celsius(BED)), GET_TEXT(UNITS_C)); ui.bounds(POLY(target_temp), x, y, h, v); cmd.text(x, y, h, v, bed_str); } - sprintf_P(bed_str, F("%3d%S"), ROUND(getActualTemp_celsius(BED)), GET_TEXT(UNITS_C)); + sprintf_P(bed_str, PSTR("%3d%S"), ROUND(getActualTemp_celsius(BED)), GET_TEXT(UNITS_C)); ui.bounds(POLY(actual_temp), x, y, h, v); cmd.text(x, y, h, v, bed_str); } @@ -197,17 +201,9 @@ void StatusScreen::draw_overlay_icons(draw_mode_t what) { ui.button_stroke(stroke_rgb, 28); ui.button_shadow(shadow_rgb, shadow_depth); - if (!jog_xy) { - ui.button(12, POLY(padlock)); - } - - if (!e_homed) { - ui.button(13, POLY(home_e)); - } - - if (!z_homed) { - ui.button(14, POLY(home_z)); - } + if (!jog_xy) ui.button(12, POLY(padlock)); + if (!e_homed) ui.button(13, POLY(home_e)); + if (!z_homed) ui.button(14, POLY(home_z)); } } @@ -228,19 +224,24 @@ void StatusScreen::draw_buttons(draw_mode_t) { isPrintingFromMedia() ? GET_TEXTF(PRINTING) : #ifdef LULZBOT_MANUAL_USB_STARTUP - (Sd2Card::ready() ? GET_TEXTF(MEDIA) : GET_TEXTF(ENABLE_MEDIA)) + (Sd2Card::ready() ? GET_TEXTF(MEDIA) : GET_TEXTF(ENABLE_MEDIA)) #else - GET_TEXTF(MEDIA) + GET_TEXTF(MEDIA) #endif ); - cmd.colors(!has_media ? action_btn : normal_btn).tag(10).button(BTN_POS(2,9), BTN_SIZE(1,1), F("Menu")); + cmd.colors(!has_media ? action_btn : normal_btn).tag(10).button(BTN_POS(2,9), BTN_SIZE(1,1), GET_TEXTF(MENU)); } -void StatusScreen::onStartup() { +void StatusScreen::loadBitmaps() { // Load the bitmaps for the status screen constexpr uint32_t base = ftdi_memory_map::RAM_G; CLCD::mem_write_pgm(base + Bed_Heat_Icon_Info.RAMG_offset, Bed_Heat_Icon, sizeof(Bed_Heat_Icon)); + + // Load fonts for internationalization + #ifdef TOUCH_UI_USE_UTF8 + load_utf8_data(base + UTF8_FONT_OFFSET); + #endif } void StatusScreen::onRedraw(draw_mode_t what) { diff --git a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/dialog_box_base_class.cpp b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/dialog_box_base_class.cpp index 09075b2c54..7d2d2e51ea 100644 --- a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/dialog_box_base_class.cpp +++ b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/dialog_box_base_class.cpp @@ -80,4 +80,8 @@ bool DialogBoxBaseClass::onTouchEnd(uint8_t tag) { } } +void DialogBoxBaseClass::onIdle() { + reset_menu_timeout(); +} + #endif // LULZBOT_TOUCH_UI diff --git a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/endstop_state_screen.cpp b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/endstop_state_screen.cpp index b474b0c168..ce5cd0b4d5 100644 --- a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/endstop_state_screen.cpp +++ b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/endstop_state_screen.cpp @@ -108,7 +108,8 @@ void EndstopStatesScreen::onRedraw(draw_mode_t) { #if HAS_SOFTWARE_ENDSTOPS #undef EDGE_R #define EDGE_R 30 - cmd.font(font_small) + cmd.cmd(COLOR_RGB(bg_text_enabled)) + .font(font_small) .text (BTN_POS(1,5), BTN_SIZE(3,1), GET_TEXTF(SOFT_ENDSTOPS), OPT_RIGHTX | OPT_CENTERY) .colors(ui_toggle) .tag(2).toggle2(BTN_POS(4,5), BTN_SIZE(3,1), GET_TEXTF(NO), GET_TEXTF(YES), getSoftEndstopState()); diff --git a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/files_screen.cpp b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/files_screen.cpp index fac80d1f77..f562573bfd 100644 --- a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/files_screen.cpp +++ b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/files_screen.cpp @@ -91,7 +91,11 @@ void FilesScreen::drawFileButton(const char* filename, uint8_t tag, bool is_dir, cmd.cmd(MACRO(0)); } #endif - cmd.text (BTN_POS(1,header_h+line), BTN_SIZE(6,1), filename, OPT_CENTERY); + cmd.text (BTN_POS(1,header_h+line), BTN_SIZE(6,1), filename, OPT_CENTERY + #if ENABLED(SCROLL_LONG_FILENAMES) + | OPT_NOFIT + #endif + ); if (is_dir) { cmd.text(BTN_POS(1,header_h+line), BTN_SIZE(6,1), F("> "), OPT_CENTERY | OPT_RIGHTX); } @@ -234,8 +238,8 @@ bool FilesScreen::onTouchEnd(uint8_t tag) { if (FTDI::ftdi_chip >= 810) { const char *longFilename = getSelectedLongFilename(); if (longFilename[0]) { - CLCD::FontMetrics fm(font_medium); - uint16_t text_width = fm.get_text_width(longFilename); + CommandProcessor cmd; + uint16_t text_width = cmd.font(font_medium).text_width(longFilename); screen_data.FilesScreen.scroll_pos = 0; if (text_width > display_width) screen_data.FilesScreen.scroll_max = text_width - display_width + MARGIN_L + MARGIN_R; diff --git a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/screens.h b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/screens.h index f7552d200e..2041036bcb 100644 --- a/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/screens.h +++ b/Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/screens.h @@ -148,6 +148,7 @@ class DialogBoxBaseClass : public BaseScreen { static void onRedraw(draw_mode_t) {}; public: static bool onTouchEnd(uint8_t tag); + static void onIdle(); }; class AlertDialogBox : public DialogBoxBaseClass, public CachedScreen { @@ -243,12 +244,12 @@ class StatusScreen : public BaseScreen, public CachedScreen