From 5051723c2e815ca9b166ceb7813b825570eb2960 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 8 Jul 2016 14:02:59 -0700 Subject: [PATCH 01/11] Redraw after cursor correction in STATIC_ITEM --- Marlin/ultralcd.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index d0a9a5dd73..f50dd32eb2 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -282,8 +282,10 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to // Used to print static text with no visible cursor. #define STATIC_ITEM(label, args...) \ if (_menuItemNr == _lineNr) { \ - if (encoderLine == _menuItemNr && _menuItemNr < LCD_HEIGHT - 1) \ + if (encoderLine == _menuItemNr && _menuItemNr < LCD_HEIGHT - 1) { \ encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \ + lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \ + } \ if (lcdDrawUpdate) \ lcd_implementation_drawmenu_static(_drawLineNr, PSTR(label), ## args); \ } \ From 13dc619f43354ef686f0f9bc3819795a338b4adb Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 8 Jul 2016 15:08:56 -0700 Subject: [PATCH 02/11] Scroll static screens more simply --- Marlin/ultralcd.cpp | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index f50dd32eb2..40717e2186 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -214,18 +214,18 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to * START_SCREEN generates the init code for a screen function * * encoderLine is the position based on the encoder - * currentMenuViewOffset is the top menu line to display + * encoderTopLine is the top menu line to display * _drawLineNr is the index of the LCD line (0-3) * _lineNr is the menu item to draw and process * _menuItemNr is the index of each MENU_ITEM */ - #define _START_SCREEN(CODE) do { \ + #define _START_SCREEN(CODE) \ ENCODER_DIRECTION_MENUS(); \ encoderRateMultiplierEnabled = false; \ if (encoderPosition > 0x8000) encoderPosition = 0; \ uint8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \ - NOMORE(currentMenuViewOffset, encoderLine); \ - uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \ + NOMORE(encoderTopLine, encoderLine); \ + uint8_t _lineNr = encoderTopLine, _menuItemNr; \ CODE; \ for (uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \ _menuItemNr = 0; @@ -292,19 +292,25 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to _menuItemNr++ #define END_SCREEN() \ - if (encoderLine >= _menuItemNr) { \ - encoderPosition = _menuItemNr * (ENCODER_STEPS_PER_MENU_ITEM) - 1; \ - encoderLine = _menuItemNr - 1; \ - } \ - if (encoderLine >= currentMenuViewOffset + LCD_HEIGHT) { \ - currentMenuViewOffset = encoderLine - (LCD_HEIGHT) + 1; \ - lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \ - _lineNr = currentMenuViewOffset - 1; \ - _drawLineNr = -1; \ - } \ - } } while(0) + } \ + NOMORE(encoderLine, _menuItemNr - LCD_HEIGHT); \ + NOLESS(encoderLine, 0); \ + encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \ + if (encoderTopLine != encoderLine) { \ + encoderTopLine = encoderLine; \ + lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \ + } - #define END_MENU() END_SCREEN() + #define END_MENU() \ + } \ + if (encoderLine >= _menuItemNr) { \ + encoderLine = _menuItemNr - 1; \ + encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \ + } \ + if (encoderLine >= encoderTopLine + LCD_HEIGHT) { \ + encoderTopLine = encoderLine - (LCD_HEIGHT - 1); \ + lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \ + } #if ENABLED(ENCODER_RATE_MULTIPLIER) @@ -342,7 +348,7 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to #if ENABLED(LCD_HAS_SLOW_BUTTONS) volatile uint8_t slow_buttons; // Bits of the pressed buttons. #endif - uint8_t currentMenuViewOffset; /* scroll offset in the current menu */ + int8_t encoderTopLine; /* scroll offset in the current menu */ millis_t next_button_update_ms; uint8_t lastEncoderBits; uint32_t encoderPosition; @@ -1888,13 +1894,13 @@ void kill_screen(const char* lcd_msg) { #if !PIN_EXISTS(SD_DETECT) static void lcd_sd_refresh() { card.initsd(); - currentMenuViewOffset = 0; + encoderTopLine = 0; } #endif static void lcd_sd_updir() { card.updir(); - currentMenuViewOffset = 0; + encoderTopLine = 0; } /** From 3a67fb77b08e6b7d51a5aae274f4a6b9ca79158a Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 8 Jul 2016 18:14:31 -0700 Subject: [PATCH 03/11] Concatenate LCD static strings --- Marlin/dogm_lcd_implementation.h | 8 ++++---- Marlin/ultralcd_implementation_hitachi_HD44780.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Marlin/dogm_lcd_implementation.h b/Marlin/dogm_lcd_implementation.h index 16c48e7be4..bfb18589e8 100644 --- a/Marlin/dogm_lcd_implementation.h +++ b/Marlin/dogm_lcd_implementation.h @@ -494,13 +494,13 @@ static void lcd_implementation_mark_as_selected(uint8_t row, bool isSelected) { int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2; while (--pad >= 0) { lcd_print(' '); n--; } } - while (c = pgm_read_byte(pstr)) { + while (n > 0 && (c = pgm_read_byte(pstr))) { n -= lcd_print(c); pstr++; } - if (valstr) { - lcd_print(valstr); - n -= lcd_strlen(valstr); + if (valstr) while (n > 0 && (c = *valstr)) { + n -= lcd_print(c); + valstr++; } while (n-- > 0) lcd_print(' '); } diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index 7f7bee5492..f1838a6f7d 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -838,13 +838,13 @@ static void lcd_implementation_status_screen() { int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2; while (--pad >= 0) { lcd.print(' '); n--; } } - while ((c = pgm_read_byte(pstr)) && n > 0) { + while (n > 0 && (c = pgm_read_byte(pstr))) { n -= lcd_print(c); pstr++; } - if (valstr) { - lcd_print(valstr); - n -= lcd_strlen(valstr); + if (valstr) while (n > 0 && (c = *valstr)) { + n -= lcd_print(c); + valstr++; } while (n-- > 0) lcd.print(' '); } From 85aeb02aa6efbc05bf3de6c5b4d800a02b221b61 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 8 Jul 2016 18:18:40 -0700 Subject: [PATCH 04/11] Invert headings on Graphical LCD --- Marlin/dogm_lcd_implementation.h | 8 ++++--- Marlin/ultralcd.cpp | 24 +++++++++---------- .../ultralcd_implementation_hitachi_HD44780.h | 3 ++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Marlin/dogm_lcd_implementation.h b/Marlin/dogm_lcd_implementation.h index bfb18589e8..10a52ba388 100644 --- a/Marlin/dogm_lcd_implementation.h +++ b/Marlin/dogm_lcd_implementation.h @@ -485,11 +485,13 @@ static void lcd_implementation_mark_as_selected(uint8_t row, bool isSelected) { #if ENABLED(LCD_INFO_MENU) || ENABLED(FILAMENT_CHANGE_FEATURE) - static void lcd_implementation_drawmenu_static(uint8_t row, const char* pstr, const char* valstr=NULL, bool center=true) { + static void lcd_implementation_drawmenu_static(uint8_t row, const char* pstr, bool center=true, bool invert=false, const char* valstr=NULL) { + + lcd_implementation_mark_as_selected(row, invert); + char c; int8_t n = LCD_WIDTH; - u8g.setPrintPos(0, (row + 1) * (DOG_CHAR_HEIGHT)); - u8g.setColorIndex(1); // normal text + if (center && !valstr) { int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2; while (--pad >= 0) { lcd_print(' '); n--; } diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 40717e2186..23e70d2451 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -1965,9 +1965,9 @@ void kill_screen(const char* lcd_msg) { if (LCD_CLICKED) lcd_goto_previous_menu(true); START_SCREEN(); - STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", itostr3left(stats.totalPrints)); // Print Count : 999 - STATIC_ITEM(MSG_INFO_FINISHED_PRINTS ": ", itostr3left(stats.finishedPrints)); // Finished : 666 - STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", printTime); // Total Time : 12:34 + STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count : 999 + STATIC_ITEM(MSG_INFO_FINISHED_PRINTS ": ", false, false, itostr3left(stats.finishedPrints)); // Finished : 666 + STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false, printTime); // Total Time : 12:34 END_SCREEN(); } #endif // PRINTCOUNTER @@ -2032,7 +2032,7 @@ void kill_screen(const char* lcd_msg) { static void lcd_info_board_menu() { if (LCD_CLICKED) lcd_goto_previous_menu(true); START_SCREEN(); - STATIC_ITEM(BOARD_NAME); // MyPrinterController + STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE)); // Baud: 250000 STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION); // Protocol: 1.0 #ifdef POWER_SUPPLY @@ -2053,7 +2053,7 @@ void kill_screen(const char* lcd_msg) { static void lcd_info_printer_menu() { if (LCD_CLICKED) lcd_goto_previous_menu(true); START_SCREEN(); - STATIC_ITEM(MSG_MARLIN); // Marlin + STATIC_ITEM(MSG_MARLIN, true, true); // Marlin STATIC_ITEM(SHORT_BUILD_VERSION); // x.x.x-Branch STATIC_ITEM(STRING_DISTRIBUTION_DATE); // YYYY-MM-DD HH:MM STATIC_ITEM(MACHINE_NAME); // My3DPrinter @@ -2095,7 +2095,7 @@ void kill_screen(const char* lcd_msg) { static void lcd_filament_change_option_menu() { START_MENU(); #if LCD_HEIGHT > 2 - STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER); + STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false); #endif MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_filament_change_resume_print); MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_filament_change_extrude_more); @@ -2104,7 +2104,7 @@ void kill_screen(const char* lcd_msg) { static void lcd_filament_change_init_message() { START_SCREEN(); - STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER); + STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true); STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1); #ifdef MSG_FILAMENT_CHANGE_INIT_2 STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2); @@ -2117,7 +2117,7 @@ void kill_screen(const char* lcd_msg) { static void lcd_filament_change_unload_message() { START_SCREEN(); - STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER); + STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true); STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1); #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2 STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2); @@ -2130,7 +2130,7 @@ void kill_screen(const char* lcd_msg) { static void lcd_filament_change_insert_message() { START_SCREEN(); - STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER); + STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true); STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1); #ifdef MSG_FILAMENT_CHANGE_INSERT_2 STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2); @@ -2143,7 +2143,7 @@ void kill_screen(const char* lcd_msg) { static void lcd_filament_change_load_message() { START_SCREEN(); - STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER); + STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true); STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1); #ifdef MSG_FILAMENT_CHANGE_LOAD_2 STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2); @@ -2156,7 +2156,7 @@ void kill_screen(const char* lcd_msg) { static void lcd_filament_change_extrude_message() { START_SCREEN(); - STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER); + STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true); STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1); #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2 STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2); @@ -2169,7 +2169,7 @@ void kill_screen(const char* lcd_msg) { static void lcd_filament_change_resume_message() { START_SCREEN(); - STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER); + STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true); STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1); #ifdef MSG_FILAMENT_CHANGE_RESUME_2 STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2); diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index f1838a6f7d..24d48b1a93 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -830,7 +830,8 @@ static void lcd_implementation_status_screen() { #if ENABLED(LCD_INFO_MENU) || ENABLED(FILAMENT_CHANGE_FEATURE) - static void lcd_implementation_drawmenu_static(uint8_t row, const char* pstr, const char *valstr=NULL, bool center=true) { + static void lcd_implementation_drawmenu_static(uint8_t row, const char* pstr, bool center=true, bool invert=false, const char *valstr=NULL) { + UNUSED(invert); char c; int8_t n = LCD_WIDTH; lcd.setCursor(0, row); From d2099fef0d57c40347126eb9156ed979217a75c9 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 8 Jul 2016 18:20:15 -0700 Subject: [PATCH 05/11] Left-justify thermistor info --- Marlin/ultralcd.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 23e70d2451..2aca7d9c11 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -1982,44 +1982,44 @@ void kill_screen(const char* lcd_msg) { START_SCREEN(); #define THERMISTOR_ID TEMP_SENSOR_0 #include "thermistornames.h" - STATIC_ITEM("T0: " THERMISTOR_NAME); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP)); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP)); + STATIC_ITEM("T0: " THERMISTOR_NAME, false, true); + STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false); + STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false); #if TEMP_SENSOR_1 != 0 #undef THERMISTOR_ID #define THERMISTOR_ID TEMP_SENSOR_1 #include "thermistornames.h" - STATIC_ITEM("T1: " THERMISTOR_NAME); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP)); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP)); + STATIC_ITEM("T1: " THERMISTOR_NAME, false, true); + STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false); + STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false); #endif #if TEMP_SENSOR_2 != 0 #undef THERMISTOR_ID #define THERMISTOR_ID TEMP_SENSOR_2 #include "thermistornames.h" - STATIC_ITEM("T2: " THERMISTOR_NAME); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP)); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP)); + STATIC_ITEM("T2: " THERMISTOR_NAME, false, true); + STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false); + STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false); #endif #if TEMP_SENSOR_3 != 0 #undef THERMISTOR_ID #define THERMISTOR_ID TEMP_SENSOR_3 #include "thermistornames.h" - STATIC_ITEM("T3: " THERMISTOR_NAME); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP)); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP)); + STATIC_ITEM("T3: " THERMISTOR_NAME, false, true); + STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false); + STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false); #endif #if TEMP_SENSOR_BED != 0 #undef THERMISTOR_ID #define THERMISTOR_ID TEMP_SENSOR_BED #include "thermistornames.h" - STATIC_ITEM("TBed:" THERMISTOR_NAME); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP)); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP)); + STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true); + STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false); + STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false); #endif END_SCREEN(); } From d9f75f62c07146d394ae0201675e55ce29c22e5d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 9 Jul 2016 12:06:47 -0700 Subject: [PATCH 06/11] START_ROW => START_COL --- Marlin/dogm_lcd_implementation.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Marlin/dogm_lcd_implementation.h b/Marlin/dogm_lcd_implementation.h index 10a52ba388..5cf08fd026 100644 --- a/Marlin/dogm_lcd_implementation.h +++ b/Marlin/dogm_lcd_implementation.h @@ -135,7 +135,7 @@ #define TALL_FONT_CORRECTION 0 #endif -#define START_ROW 0 +#define START_COL 0 // LCD selection #if ENABLED(U8GLIB_ST7920) @@ -480,7 +480,7 @@ static void lcd_implementation_mark_as_selected(uint8_t row, bool isSelected) { else { u8g.setColorIndex(1); // unmarked text is black on white } - u8g.setPrintPos((START_ROW) * (DOG_CHAR_WIDTH), (row + 1) * (DOG_CHAR_HEIGHT)); + u8g.setPrintPos((START_COL) * (DOG_CHAR_WIDTH), (row + 1) * (DOG_CHAR_HEIGHT)); } #if ENABLED(LCD_INFO_MENU) || ENABLED(FILAMENT_CHANGE_FEATURE) @@ -490,7 +490,7 @@ static void lcd_implementation_mark_as_selected(uint8_t row, bool isSelected) { lcd_implementation_mark_as_selected(row, invert); char c; - int8_t n = LCD_WIDTH; + int8_t n = LCD_WIDTH - (START_COL); if (center && !valstr) { int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2; @@ -513,7 +513,7 @@ static void lcd_implementation_drawmenu_generic(bool isSelected, uint8_t row, co UNUSED(pre_char); char c; - uint8_t n = LCD_WIDTH - 2; + uint8_t n = LCD_WIDTH - (START_COL) - 2; lcd_implementation_mark_as_selected(row, isSelected); @@ -530,7 +530,7 @@ static void lcd_implementation_drawmenu_generic(bool isSelected, uint8_t row, co static void _drawmenu_setting_edit_generic(bool isSelected, uint8_t row, const char* pstr, const char* data, bool pgm) { char c; uint8_t vallen = (pgm ? lcd_strlen_P(data) : (lcd_strlen((char*)data))); - uint8_t n = LCD_WIDTH - 2 - vallen; + uint8_t n = LCD_WIDTH - (START_COL) - 2 - vallen; lcd_implementation_mark_as_selected(row, isSelected); @@ -570,7 +570,7 @@ static void _drawmenu_setting_edit_generic(bool isSelected, uint8_t row, const c void lcd_implementation_drawedit(const char* pstr, const char* value=NULL) { uint8_t rows = 1; - uint8_t lcd_width = LCD_WIDTH, char_width = DOG_CHAR_WIDTH; + uint8_t lcd_width = LCD_WIDTH - (START_COL), char_width = DOG_CHAR_WIDTH; uint8_t vallen = lcd_strlen(value); #if ENABLED(USE_BIG_EDIT_FONT) @@ -604,7 +604,7 @@ void lcd_implementation_drawedit(const char* pstr, const char* value=NULL) { static void _drawmenu_sd(bool isSelected, uint8_t row, const char* pstr, const char* filename, char* const longFilename, bool isDir) { UNUSED(pstr); char c; - uint8_t n = LCD_WIDTH - 1; + uint8_t n = LCD_WIDTH - (START_COL) - 1; if (longFilename[0]) { filename = longFilename; From 31f2cf5f6f66d101f29a1ab4d1a6c3210d281527 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 9 Jul 2016 12:25:53 -0700 Subject: [PATCH 07/11] Make encoderLine signed for proper compares --- Marlin/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 2aca7d9c11..21ffdc1fe9 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -223,7 +223,7 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to ENCODER_DIRECTION_MENUS(); \ encoderRateMultiplierEnabled = false; \ if (encoderPosition > 0x8000) encoderPosition = 0; \ - uint8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \ + int8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \ NOMORE(encoderTopLine, encoderLine); \ uint8_t _lineNr = encoderTopLine, _menuItemNr; \ CODE; \ From 155af6b861e03c6a836fe083e60c9c708430c178 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 9 Jul 2016 12:26:20 -0700 Subject: [PATCH 08/11] Rename vars, add comments for menu macros --- Marlin/ultralcd.cpp | 66 +++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 21ffdc1fe9..bafe0ca3aa 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -215,9 +215,9 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to * * encoderLine is the position based on the encoder * encoderTopLine is the top menu line to display - * _drawLineNr is the index of the LCD line (0-3) - * _lineNr is the menu item to draw and process - * _menuItemNr is the index of each MENU_ITEM + * _lcdLineNr is the index of the LCD line (e.g., 0-3) + * _menuLineNr is the menu item to draw and process + * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM */ #define _START_SCREEN(CODE) \ ENCODER_DIRECTION_MENUS(); \ @@ -225,10 +225,10 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to if (encoderPosition > 0x8000) encoderPosition = 0; \ int8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \ NOMORE(encoderTopLine, encoderLine); \ - uint8_t _lineNr = encoderTopLine, _menuItemNr; \ + int8_t _menuLineNr = encoderTopLine, _thisItemNr; \ CODE; \ - for (uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \ - _menuItemNr = 0; + for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT; _lcdLineNr++, _menuLineNr++) { \ + _thisItemNr = 0; #define START_SCREEN() _START_SCREEN(0) @@ -260,40 +260,53 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999) * */ - #define _MENU_ITEM_PART_1(type, label, args...) \ - if (_menuItemNr == _lineNr) { \ + #define _MENU_ITEM_PART_1(TYPE, LABEL, ARGS...) \ + if (_menuLineNr == _thisItemNr) { \ if (lcdDrawUpdate) \ - lcd_implementation_drawmenu_ ## type(encoderLine == _menuItemNr, _drawLineNr, PSTR(label), ## args); \ - if (wasClicked && encoderLine == _menuItemNr) { \ + lcd_implementation_drawmenu_ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PSTR(LABEL), ## ARGS); \ + if (wasClicked && encoderLine == _thisItemNr) { \ lcd_quick_feedback() - #define _MENU_ITEM_PART_2(type, args...) \ - menu_action_ ## type(args); \ + #define _MENU_ITEM_PART_2(TYPE, ARGS...) \ + menu_action_ ## TYPE(ARGS); \ return; \ } \ } \ - _menuItemNr++ + _thisItemNr++ - #define MENU_ITEM(type, label, args...) do { \ - _MENU_ITEM_PART_1(type, label, ## args); \ - _MENU_ITEM_PART_2(type, ## args); \ + #define MENU_ITEM(TYPE, LABEL, ARGS...) do { \ + _MENU_ITEM_PART_1(TYPE, LABEL, ## ARGS); \ + _MENU_ITEM_PART_2(TYPE, ## ARGS); \ } while(0) // Used to print static text with no visible cursor. - #define STATIC_ITEM(label, args...) \ - if (_menuItemNr == _lineNr) { \ - if (encoderLine == _menuItemNr && _menuItemNr < LCD_HEIGHT - 1) { \ + #define STATIC_ITEM(LABEL, ARGS...) \ + if (_menuLineNr == _thisItemNr) { \ + if (encoderLine == _thisItemNr && _thisItemNr < LCD_HEIGHT - 1) { \ encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \ lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \ } \ if (lcdDrawUpdate) \ - lcd_implementation_drawmenu_static(_drawLineNr, PSTR(label), ## args); \ + lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(LABEL), ## ARGS); \ } \ - _menuItemNr++ + _thisItemNr++ + /** + * + * END_SCREEN Closing code for a screen having only static items. + * Do simplified scrolling of the entire screen. + * + * END_MENU Closing code for a screen with menu items. + * Scroll as-needed to keep the selected line in view. + * + * At this point _thisItemNr equals the total number of items. + * + */ + + // Simple-scroll by using encoderLine as encoderTopLine #define END_SCREEN() \ } \ - NOMORE(encoderLine, _menuItemNr - LCD_HEIGHT); \ + NOMORE(encoderLine, _thisItemNr - LCD_HEIGHT); \ NOLESS(encoderLine, 0); \ encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \ if (encoderTopLine != encoderLine) { \ @@ -301,10 +314,11 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \ } + // Scroll through menu items, scrolling as-needed to stay in view #define END_MENU() \ } \ - if (encoderLine >= _menuItemNr) { \ - encoderLine = _menuItemNr - 1; \ + if (encoderLine >= _thisItemNr) { \ + encoderLine = _thisItemNr - 1; \ encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \ } \ if (encoderLine >= encoderTopLine + LCD_HEIGHT) { \ @@ -328,7 +342,7 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to #endif //ENCODER_RATE_MULTIPLIER - #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0) + #define MENU_ITEM_DUMMY() do { _thisItemNr++; } while(0) #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## args) #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## args) #if ENABLED(ENCODER_RATE_MULTIPLIER) @@ -1925,7 +1939,7 @@ void kill_screen(const char* lcd_msg) { } for (uint16_t i = 0; i < fileCnt; i++) { - if (_menuItemNr == _lineNr) { + if (_menuLineNr == _thisItemNr) { card.getfilename( #if ENABLED(SDCARD_RATHERRECENTFIRST) fileCnt-1 - From 7ae84d768e14f4c7d710c6adf34e3ab9180b5be2 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 9 Jul 2016 14:16:57 -0700 Subject: [PATCH 09/11] Tweak conditionals for REPRAPWORLD_KEYPAD --- Marlin/Conditionals.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Marlin/Conditionals.h b/Marlin/Conditionals.h index 4108014509..ea73077779 100644 --- a/Marlin/Conditionals.h +++ b/Marlin/Conditionals.h @@ -118,12 +118,7 @@ #define REPRAP_DISCOUNT_SMART_CONTROLLER #endif - #if ENABLED(ULTIMAKERCONTROLLER) || ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) || ENABLED(G3D_PANEL) || ENABLED(RIGIDBOT_PANEL) - #define ULTIPANEL - #define NEWPANEL - #endif - - #if ENABLED(REPRAPWORLD_KEYPAD) + #if ENABLED(ULTIMAKERCONTROLLER) || ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) || ENABLED(G3D_PANEL) || ENABLED(RIGIDBOT_PANEL) || ENABLED(REPRAPWORLD_KEYPAD) #define ULTIPANEL #define NEWPANEL #endif From 096f9981d159cb24c56748ab36a998004abbe9a5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 10 Jul 2016 17:41:53 -0700 Subject: [PATCH 10/11] Scroll to the top when changing screens --- Marlin/ultralcd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index bafe0ca3aa..d3e8f26097 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -398,6 +398,7 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to if (currentScreen != screen) { currentScreen = screen; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; + encoderTopLine = 0; #if ENABLED(NEWPANEL) encoderPosition = encoder; if (feedback) lcd_quick_feedback(); From d17b161832db2227b534e48ae3a87b83497648ad Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 10 Jul 2016 17:53:11 -0700 Subject: [PATCH 11/11] Don't draw current screen if simply changing screens --- Marlin/ultralcd.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index d3e8f26097..bd412bab39 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -677,6 +677,7 @@ void kill_screen(const char* lcd_msg) { long babysteps_done = 0; static void _lcd_babystep(const AxisEnum axis, const char* msg) { + if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; } ENCODER_DIRECTION_NORMAL(); if (encoderPosition) { int babystep_increment = (int32_t)encoderPosition * BABYSTEP_MULTIPLICATOR; @@ -689,7 +690,6 @@ void kill_screen(const char* lcd_msg) { lcd_implementation_drawedit(msg, ftostr43sign( ((1000 * babysteps_done) / planner.axis_steps_per_mm[axis]) * 0.001f )); - if (LCD_CLICKED) lcd_goto_previous_menu(true); } #if ENABLED(BABYSTEP_XY) @@ -1344,6 +1344,7 @@ void kill_screen(const char* lcd_msg) { float move_menu_scale; static void _lcd_move_xyz(const char* name, AxisEnum axis, float min, float max) { + if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; } ENCODER_DIRECTION_NORMAL(); if (encoderPosition) { refresh_cmd_timeout(); @@ -1355,7 +1356,6 @@ void kill_screen(const char* lcd_msg) { lcdDrawUpdate = LCDVIEW_REDRAW_NOW; } if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr41sign(current_position[axis])); - if (LCD_CLICKED) lcd_goto_previous_menu(true); } #if ENABLED(DELTA) static float delta_clip_radius_2 = (DELTA_PRINTABLE_RADIUS) * (DELTA_PRINTABLE_RADIUS); @@ -1372,6 +1372,7 @@ void kill_screen(const char* lcd_msg) { int8_t eindex = -1 #endif ) { + if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; } ENCODER_DIRECTION_NORMAL(); if (encoderPosition) { current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale; @@ -1401,7 +1402,6 @@ void kill_screen(const char* lcd_msg) { #endif //EXTRUDERS > 1 lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS])); } - if (LCD_CLICKED) lcd_goto_previous_menu(true); } #if EXTRUDERS > 1 @@ -1860,6 +1860,7 @@ void kill_screen(const char* lcd_msg) { */ #if HAS_LCD_CONTRAST static void lcd_set_contrast() { + if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; } ENCODER_DIRECTION_NORMAL(); if (encoderPosition) { set_lcd_contrast(lcd_contrast + encoderPosition); @@ -1875,7 +1876,6 @@ void kill_screen(const char* lcd_msg) { #endif ); } - if (LCD_CLICKED) lcd_goto_previous_menu(true); } #endif // HAS_LCD_CONTRAST @@ -1967,10 +1967,12 @@ void kill_screen(const char* lcd_msg) { #if ENABLED(PRINTCOUNTER) /** * - * About Printer > Stastics submenu + * About Printer > Statistics submenu * */ static void lcd_info_stats_menu() { + if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; } + PrintCounter print_job_counter = PrintCounter(); print_job_counter.loadStats(); printStatistics stats = print_job_counter.getStats(); @@ -1978,7 +1980,6 @@ void kill_screen(const char* lcd_msg) { char printTime[6]; sprintf(printTime, "%02d:%02d", int(stats.printTime / 60), int(stats.printTime % 60)); - if (LCD_CLICKED) lcd_goto_previous_menu(true); START_SCREEN(); STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count : 999 STATIC_ITEM(MSG_INFO_FINISHED_PRINTS ": ", false, false, itostr3left(stats.finishedPrints)); // Finished : 666 @@ -1993,7 +1994,7 @@ void kill_screen(const char* lcd_msg) { * */ static void lcd_info_thermistors_menu() { - if (LCD_CLICKED) lcd_goto_previous_menu(true); + if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; } START_SCREEN(); #define THERMISTOR_ID TEMP_SENSOR_0 #include "thermistornames.h" @@ -2045,7 +2046,7 @@ void kill_screen(const char* lcd_msg) { * */ static void lcd_info_board_menu() { - if (LCD_CLICKED) lcd_goto_previous_menu(true); + if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; } START_SCREEN(); STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE)); // Baud: 250000 @@ -2066,7 +2067,7 @@ void kill_screen(const char* lcd_msg) { * */ static void lcd_info_printer_menu() { - if (LCD_CLICKED) lcd_goto_previous_menu(true); + if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; } START_SCREEN(); STATIC_ITEM(MSG_MARLIN, true, true); // Marlin STATIC_ITEM(SHORT_BUILD_VERSION); // x.x.x-Branch