From 09cb9c6ecd3b787a1ba1a3212b548945901bb059 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Thu, 28 Jul 2022 10:10:52 +0200 Subject: [PATCH] Fixup after rebase + discussion --- Firmware/Marlin_main.cpp | 8 +-- Firmware/Tcodes.cpp | 6 +- Firmware/eeprom.h | 1 - Firmware/lcd.h | 24 ++++++++ Firmware/menu.cpp | 2 + Firmware/messages.cpp | 12 ++-- Firmware/ultralcd.cpp | 123 ++++++++++++++++++++------------------- Firmware/ultralcd.h | 6 +- 8 files changed, 104 insertions(+), 78 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index a5d73e68e..d0592beb4 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -647,12 +647,12 @@ void crashdet_detected(uint8_t mask) lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_RESUME_PRINT)); lcd_putc('?'); - bool yesno = lcd_show_yes_no_and_wait(false); + int8_t yesno = lcd_show_yes_no_and_wait(false); if (yesno == LCD_LEFT_BUTTON_CHOICE) { enquecommand_P(PSTR("CRASH_RECOVER")); } - else // MIDDLE_BUTTON_CHOICE + else // LCD_MIDDLE_BUTTON_CHOICE { enquecommand_P(PSTR("CRASH_CANCEL")); } @@ -3292,7 +3292,7 @@ bool gcode_M45(bool onlyZ, int8_t verbosity_level) { KEEPALIVE_STATE(PAUSED_FOR_USER); #ifdef STEEL_SHEET - bool result = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false); + int8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false); if(result == LCD_LEFT_BUTTON_CHOICE) { lcd_show_fullscreen_message_and_wait_P(_T(MSG_REMOVE_STEEL_SHEET)); } @@ -4924,7 +4924,7 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF); break; } lcd_show_fullscreen_message_and_wait_P(_i("Stable ambient temperature 21-26C is needed a rigid stand is required."));////MSG_TEMP_CAL_WARNING c=20 r=4 - bool result = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false); + int8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false); if (result == LCD_LEFT_BUTTON_CHOICE) { diff --git a/Firmware/Tcodes.cpp b/Firmware/Tcodes.cpp index b0f4730e8..3231648f0 100644 --- a/Firmware/Tcodes.cpp +++ b/Firmware/Tcodes.cpp @@ -30,9 +30,9 @@ struct SChooseFromMenu { SChooseFromMenu TCodeChooseFromMenu() { if (MMU2::mmu2.Enabled()) { - return SChooseFromMenu( choose_menu_P(_T(MSG_CHOOSE_FILAMENT), _T(MSG_FILAMENT)), true ); + return SChooseFromMenu( choose_menu_P(_T(MSG_SELECT_FILAMENT), _T(MSG_FILAMENT)), true ); } else { - return SChooseFromMenu( choose_menu_P(_T(MSG_CHOOSE_EXTRUDER), _T(MSG_EXTRUDER)), false ); + return SChooseFromMenu( choose_menu_P(_T(MSG_SELECT_EXTRUDER), _T(MSG_EXTRUDER)), false ); } } @@ -48,7 +48,7 @@ void TCodes(char *const strchr_pointer, uint8_t codeValue) { } else if (strchr_pointer[index] == 'x'){ // load to bondtech gears; if mmu is not present do nothing if (MMU2::mmu2.Enabled()) { - MMU2::mmu2.tool_change(strchr_pointer[index], choose_menu_P(_T(MSG_CHOOSE_EXTRUDER), _T(MSG_EXTRUDER))); + MMU2::mmu2.tool_change(strchr_pointer[index], choose_menu_P(_T(MSG_SELECT_EXTRUDER), _T(MSG_EXTRUDER))); } } else if (strchr_pointer[index] == 'c'){ // load from bondtech gears to nozzle (nozzle should be preheated) diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index f78acc259..edb7b0680 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -333,7 +333,6 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP | ^ | ^ | ^ | 03h 3 | ^ | bad_isr | ^ | ^ | ^ | ^ | ^ | 04h 4 | ^ | bad_pullup_temp_isr | ^ | ^ | ^ | ^ | ^ | 05h 5 | ^ | bad_pullup_step_isr | ^ | ^ -| 0x0D03 3321 | uint8_t | EEPROM_FW_CRASH_FLAG | 01h 1 | ff/00 | Last FW crash reason (dump_crash_reason) | D21/D22 | D3 Ax0d03 C1 | 0x0D02 3320 | uint8_t | EEPROM_FSENSOR_JAM_DETECTION | 01h 1 | ff/01 | fsensor pat9125 jam detection feature | LCD menu | D3 Ax0d02 C1 | 0x0D01 3319 | uint8_t | EEPROM_MMU_ENABLED | 01h 1 | ff/01 | MMU enabled | LCD menu | D3 Ax0d01 C1 diff --git a/Firmware/lcd.h b/Firmware/lcd.h index 8ac643f58..9b6b667ca 100644 --- a/Firmware/lcd.h +++ b/Firmware/lcd.h @@ -127,6 +127,30 @@ extern void lcd_update_enable(uint8_t enabled); extern void lcd_buttons_update(void); +//! @brief Helper class to temporarily disable LCD updates +//! +//! When constructed (on stack), original state state of lcd_update_enabled is stored +//! and LCD updates are disabled. +//! When destroyed (gone out of scope), original state of LCD update is restored. +//! It has zero overhead compared to storing bool saved = lcd_update_enabled +//! and calling lcd_update_enable(false) and lcd_update_enable(saved). +class LcdUpdateDisabler +{ +public: + LcdUpdateDisabler(): m_updateEnabled(lcd_update_enabled) + { + lcd_update_enable(false); + } + ~LcdUpdateDisabler() + { + lcd_update_enable(m_updateEnabled); + } + +private: + bool m_updateEnabled; +}; + + //////////////////////////////////// // Setup button and encode mappings for each panel (into 'lcd_buttons' variable // diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 712a74686..b4761304f 100755 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -384,7 +384,9 @@ uint8_t menu_item_function_P(const char* str, char number, void (*func)(uint8_t) { menu_clicked = false; lcd_consume_click(); + lcd_update_enabled = 0; if (func) func(fn_par); + lcd_update_enabled = 1; return menu_item_ret(); } } diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index a36e25b44..0bdfa685e 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -41,9 +41,9 @@ const char MSG_FIND_BED_OFFSET_AND_SKEW_LINE1[] PROGMEM_I1 = ISTR("Searching bed const char MSG_FINISHING_MOVEMENTS[] PROGMEM_I1 = ISTR("Finishing movements"); ////MSG_FINISHING_MOVEMENTS c=20 const char MSG_FOLLOW_CALIBRATION_FLOW[] PROGMEM_I1 = ISTR("Printer has not been calibrated yet. Please follow the manual, chapter First steps, section Calibration flow."); ////MSG_FOLLOW_CALIBRATION_FLOW c=20 r=8 const char MSG_FOLLOW_Z_CALIBRATION_FLOW[] PROGMEM_I1 = ISTR("There is still a need to make Z calibration. Please follow the manual, chapter First steps, section Calibration flow."); ////MSG_FOLLOW_Z_CALIBRATION_FLOW c=20 r=9 -const char MSG_FSENSOR_RUNOUT[] PROGMEM_I1 = ISTR("F. runout"); ////c=13 +const char MSG_FSENSOR_RUNOUT[] PROGMEM_I1 = ISTR("F. runout"); ////MSG_FSENSOR_RUNOUT c=13 const char MSG_FSENSOR_AUTOLOAD[] PROGMEM_I1 = ISTR("F. autoload"); ////MSG_FSENSOR_AUTOLOAD c=13 -const char MSG_FSENSOR_JAM_DETECTION[] PROGMEM_I1 = ISTR("F. jam detect"); ////c=13 +const char MSG_FSENSOR_JAM_DETECTION[] PROGMEM_I1 = ISTR("F. jam detect"); ////MSG_FSENSOR_JAM_DETECTION c=13 const char MSG_FSENSOR[] PROGMEM_I1 = ISTR("Fil. sensor"); ////MSG_FSENSOR c=12 const char MSG_HEATING[] PROGMEM_I1 = ISTR("Heating"); ////MSG_HEATING c=20 const char MSG_HEATING_COMPLETE[] PROGMEM_I1 = ISTR("Heating done."); ////MSG_HEATING_COMPLETE c=20 @@ -54,9 +54,9 @@ const char MSG_SELECT_FILAMENT[] PROGMEM_I1 = ISTR("Select filament:"); ////MSG_ const char MSG_LAST_PRINT[] PROGMEM_I1 = ISTR("Last print"); ////MSG_LAST_PRINT c=18 const char MSG_LAST_PRINT_FAILURES[] PROGMEM_I1 = ISTR("Last print failures"); ////MSG_LAST_PRINT_FAILURES c=20 const char MSG_LOAD_FILAMENT[] PROGMEM_I1 = ISTR("Load filament"); ////MSG_LOAD_FILAMENT c=17 -const char MSG_LOAD_TO_BONDTECH[] PROGMEM_I1 = ISTR("Load to Bondtech"); ////c=18 +const char MSG_LOAD_TO_BONDTECH[] PROGMEM_I1 = ISTR("Load to Bondtech"); ////MSG_LOAD_TO_BONDTECH c=18 const char MSG_LOADING_FILAMENT[] PROGMEM_I1 = ISTR("Loading filament"); ////MSG_LOADING_FILAMENT c=20 -const char MSG_TESTING_FILAMENT[] PROGMEM_I1 = ISTR("Testing filament"); ////c=20 +const char MSG_TESTING_FILAMENT[] PROGMEM_I1 = ISTR("Testing filament"); ////MSG_TESTING_FILAMENT c=20 const char MSG_EJECT_FILAMENT[] PROGMEM_I1 = ISTR("Eject filament"); ////MSG_EJECT_FILAMENT c=17 const char MSG_CUT_FILAMENT[] PROGMEM_I1 = ISTR("Cut filament"); ////MSG_CUT_FILAMENT c=17 const char MSG_MAIN[] PROGMEM_I1 = ISTR("Main"); ////MSG_MAIN c=18 @@ -159,8 +159,8 @@ const char MSG_TIMEOUT[] PROGMEM_I1 = ISTR("Timeout"); ////MSG_TIMEOUT c=12 const char MSG_BRIGHT[] PROGMEM_I1 = ISTR("Bright"); ////MSG_BRIGHT c=6 const char MSG_DIM[] PROGMEM_I1 = ISTR("Dim"); ////MSG_DIM c=6 const char MSG_AUTO[] PROGMEM_I1 = ISTR("Auto"); ////MSG_AUTO c=6 -const char MSG_FS_V_03_OR_OLDER[] PROGMEM_I1 = ISTR("FS v0.3 or older"); ////c=18 -const char MSG_FS_V_04_OR_NEWER[] PROGMEM_I1 = ISTR("FS v0.4 or newer"); ////c=18 +const char MSG_FS_V_03_OR_OLDER[] PROGMEM_I1 = ISTR("FS v0.3 or older"); ////MSG_FS_V_03_OR_OLDER c=18 +const char MSG_FS_V_04_OR_NEWER[] PROGMEM_I1 = ISTR("FS v0.4 or newer"); ////MSG_FS_V_04_OR_NEWER c=18 #ifdef IR_SENSOR_ANALOG // Beware - the space at the beginning is necessary since it is reused in LCD menu items which are to be with a space const char MSG_IR_04_OR_NEWER[] PROGMEM_I1 = ISTR(" 0.4 or newer");////MSG_IR_04_OR_NEWER c=18 diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 6d9864597..dd88c7a3d 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1268,6 +1268,7 @@ static void lcd_menu_fails_stats_total() //! @endcode //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations. +//! @todo leptun refactor this piece of code please static void lcd_menu_fails_stats_print() { lcd_timeoutToStatus.stop(); //infinite timeout @@ -1854,6 +1855,7 @@ switch(eFilamentAction) } if(lcd_clicked() #ifdef FILAMENT_SENSOR +/// @todo leptun - add this as a specific retest item || (((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad)) && fsensor.getFilamentLoadEvent()) #endif //FILAMENT_SENSOR ) { @@ -2324,7 +2326,7 @@ void show_preheat_nozzle_warning() void lcd_load_filament_color_check() { - bool clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, LCD_LEFT_BUTTON_CHOICE); + int8_t clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, LCD_LEFT_BUTTON_CHOICE); while (clean == LCD_MIDDLE_BUTTON_CHOICE) { load_filament_final_feed(); st_synchronize(); @@ -2340,14 +2342,13 @@ static void lcd_menu_AutoLoadFilament() } #endif //FILAMENT_SENSOR -static void preheat_or_continue() -{ - if (target_temperature[0] >= extrude_min_temp) - { +static void preheat_or_continue() { + if (target_temperature[0] >= extrude_min_temp) { bFilamentPreheatState = true; mFilamentItem(target_temperature[0], target_temperature_bed); + } else { + lcd_generic_preheat_menu(); } - else lcd_generic_preheat_menu(); } static void lcd_LoadFilament() @@ -3131,7 +3132,7 @@ const char* lcd_display_message_fullscreen_P(const char *msg) */ void lcd_show_fullscreen_message_and_wait_P(const char *msg) { - lcd_update_enable(false); + LcdUpdateDisabler lcdUpdateDisabler; const char *msg_next = lcd_display_message_fullscreen_P(msg); bool multi_screen = msg_next != NULL; lcd_set_custom_characters_nextpage(); @@ -3151,7 +3152,6 @@ void lcd_show_fullscreen_message_and_wait_P(const char *msg) if (msg_next == NULL) { KEEPALIVE_STATE(IN_HANDLER); lcd_set_custom_characters(); - lcd_update_enable(true); return; } else { @@ -3275,60 +3275,60 @@ int8_t lcd_show_multiscreen_message_with_choices_and_wait_P(const char * const m manage_heater(); manage_inactivity(true); - if (multiscreen_cb) - { - multiscreen_cb(); - } - + if (multiscreen_cb) { + multiscreen_cb(); + } - if (abs(enc_dif - lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) { - if (msg_next == NULL) { + + + if (abs(enc_dif - lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) { + if (msg_next == NULL) { if (third_choice) { // third_choice is not nullptr, safe to dereference - if (enc_dif > lcd_encoder_diff && current_selection != LCD_LEFT_BUTTON_CHOICE) { - // Rotating knob counter clockwise - current_selection--; - } else if (enc_dif < lcd_encoder_diff && current_selection != LCD_RIGHT_BUTTON_CHOICE) { - // Rotating knob clockwise - current_selection++; - } - } else { - if (enc_dif > lcd_encoder_diff && current_selection != LCD_LEFT_BUTTON_CHOICE) { - // Rotating knob counter clockwise - current_selection = LCD_LEFT_BUTTON_CHOICE; - } else if (enc_dif < lcd_encoder_diff && current_selection != LCD_MIDDLE_BUTTON_CHOICE) { - // Rotating knob clockwise - current_selection = LCD_MIDDLE_BUTTON_CHOICE; - } - } - lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice); - enc_dif = lcd_encoder_diff; - Sound_MakeSound(e_SOUND_TYPE_EncoderMove); + if (enc_dif > lcd_encoder_diff && current_selection != LCD_LEFT_BUTTON_CHOICE) { + // Rotating knob counter clockwise + current_selection--; + } else if (enc_dif < lcd_encoder_diff && current_selection != LCD_RIGHT_BUTTON_CHOICE) { + // Rotating knob clockwise + current_selection++; + } + } else { + if (enc_dif > lcd_encoder_diff && current_selection != LCD_LEFT_BUTTON_CHOICE) { + // Rotating knob counter clockwise + current_selection = LCD_LEFT_BUTTON_CHOICE; + } else if (enc_dif < lcd_encoder_diff && current_selection != LCD_MIDDLE_BUTTON_CHOICE) { + // Rotating knob clockwise + current_selection = LCD_MIDDLE_BUTTON_CHOICE; + } + } + lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice); + enc_dif = lcd_encoder_diff; + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); } else { - Sound_MakeSound(e_SOUND_TYPE_BlindAlert); - break; //turning knob skips waiting loop - } - } - if (lcd_clicked()) { - Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); - if (msg_next == NULL) { - KEEPALIVE_STATE(IN_HANDLER); - lcd_set_custom_characters(); - lcd_update_enable(true); - return current_selection; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); + break; // turning knob skips waiting loop + } + } + if (lcd_clicked()) { + Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); + if (msg_next == NULL) { + KEEPALIVE_STATE(IN_HANDLER); + lcd_set_custom_characters(); + lcd_update_enable(true); + return current_selection; } else break; - } - } - if (multi_screen) { - if (msg_next == NULL) { - msg_next = msg; - } - msg_next = lcd_display_message_fullscreen_P(msg_next); - } - if (msg_next == NULL) { - lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice); - } - } + } + } + if (multi_screen) { + if (msg_next == NULL) { + msg_next = msg; + } + msg_next = lcd_display_message_fullscreen_P(msg_next); + } + if (msg_next == NULL) { + lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice); + } + } } //! @brief Display and wait for a Yes/No choice using the last line of the LCD @@ -3970,7 +3970,7 @@ static void lcd_wizard_load() { bool lcd_autoDepleteEnabled() { return (lcd_autoDeplete -#ifdef FILAMENT_SENSOR ///should be removed during mmu2 refactoring +#ifdef FILAMENT_SENSOR // @todo leptun: should be removed during mmu2 refactoring - needs checking && fsensor.isReady() #endif ); @@ -4296,10 +4296,10 @@ static void lcd_fsensor_settings_menu() { switch(fsensor.getActionOnError()) { case Filament_sensor::SensorActionOnError::_Continue: - MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_CONTINUE), lcd_fsensor_actionNA_set); + MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_CONTINUE_SHORT), lcd_fsensor_actionNA_set); break; case Filament_sensor::SensorActionOnError::_Pause: - MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_PAUSE), lcd_fsensor_actionNA_set); + MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_PAUSE), lcd_fsensor_actionNA_set); break; default: lcd_fsensor_actionNA_set(); @@ -7520,6 +7520,7 @@ static void menu_action_sdfile(const char* filename) //to open a file. Instead, the cached filename in cmd is used as that one is static for the whole lifetime of this function. if (!check_file(cmd + 4)) { result = !lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false);////MSG_FILE_INCOMPLETE c=20 r=3 + lcd_update_enable(true); } if (result) { enquecommand(cmd); @@ -7776,7 +7777,7 @@ void menu_lcd_lcdupdate_func(void) } #endif//CARDINSERTED backlight_update(); - if (lcd_next_update_millis < _millis() || lcd_draw_update) + if (lcd_next_update_millis < _millis()) { if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) { diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 5441198a3..767c2c952 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -80,11 +80,11 @@ extern void lcd_show_fullscreen_message_and_wait_P(const char *msg); // 1: no, 0: yes, -1: timeouted extern int8_t lcd_show_yes_no_and_wait(bool allow_timeouting = true, uint8_t default_selection = LCD_MIDDLE_BUTTON_CHOICE); // 1: no, 0: yes, -1: timeouted -extern int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting = true, uint8_t default_selection = MIDDLE_BUTTON_CHOICE); +extern int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting = true, uint8_t default_selection = LCD_MIDDLE_BUTTON_CHOICE); extern int8_t lcd_show_multiscreen_message_with_choices_and_wait_P(const char * const msg, bool allow_timeouting, uint8_t default_selection, const char * const first_choice, const char * const second_choice, const char * const third_choice = nullptr, uint8_t second_col = 7, void (*multiscreen_cb)(void) = nullptr); -extern int8_t lcd_show_multiscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting = true, uint8_t default_selection = MIDDLE_BUTTON_CHOICE); +extern int8_t lcd_show_multiscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting = true, uint8_t default_selection = LCD_MIDDLE_BUTTON_CHOICE); // Ask the user to move the Z axis up to the end stoppers and let // the user confirm that it has been done. @@ -129,7 +129,7 @@ enum class CustomMsg : uint_least8_t TempCompPreheat, //!< Temperature compensation preheat M0Wait, //!< M0/M1 Wait command working even from SD M117, //!< M117 Set the status line message on the LCD - Resuming, //!< Resuming message + Resuming, //!< Resuming message MMUProgress, ///< MMU progress message };