From dece5d268f4c4a77e2b2e54ea252d7a4444663ea Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 20 Aug 2022 16:00:03 +0200 Subject: [PATCH 1/6] Consider any lcd_custom_command to be "ACTIVE" All custom commands are transitory and eventually switch back to Idle state by themselves. It doesn't make any sense to explicitly check for Layer1Cal: any non-idle state is active by design. Fix this check in the main menu. This is probably incomplete (Layer1Cal is incorrectly used in several other places). --- Firmware/Marlin_main.cpp | 3 +-- Firmware/ultralcd.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index f9d6680fd..cf72c0bf3 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -513,9 +513,8 @@ bool __attribute__((noinline)) printJobOngoing() { bool __attribute__((noinline)) printer_active() { return printJobOngoing() || isPrintPaused - || (custom_message_type == CustomMsg::TempCal) || saved_printing - || (lcd_commands_type == LcdCommands::Layer1Cal) + || (lcd_commands_type != LcdCommands::Idle) || MMU2::mmu2.MMU_PRINT_SAVED() || homing_flag || mesh_bed_leveling_flag; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 4bfc26538..25a193f3a 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5179,9 +5179,9 @@ static void lcd_main_menu() } #endif #ifdef SDSUPPORT //!@todo SDSUPPORT undefined creates several issues in source code - if (card.cardOK || lcd_commands_type == LcdCommands::Layer1Cal) { + if (card.cardOK || lcd_commands_type != LcdCommands::Idle) { if (!card.isFileOpen()) { - if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) { + if (!usb_timer.running() && (lcd_commands_type == LcdCommands::Idle)) { bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu); } @@ -5198,7 +5198,7 @@ static void lcd_main_menu() } #endif //SDSUPPORT - if(!isPrintPaused && !printJobOngoing() && (lcd_commands_type != LcdCommands::Layer1Cal)) { + if(!isPrintPaused && !printJobOngoing() && (lcd_commands_type == LcdCommands::Idle)) { if (!farm_mode) { const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)); const int8_t nextSheet = eeprom_next_initialized_sheet(sheet); @@ -5208,7 +5208,7 @@ static void lcd_main_menu() } } - if ( ! ( printJobOngoing() || (lcd_commands_type == LcdCommands::Layer1Cal || Stopped) ) ) { + if ( ! ( printJobOngoing() || (lcd_commands_type != LcdCommands::Idle) || Stopped) ) { if (MMU2::mmu2.Enabled()) { if(!MMU2::mmu2.FindaDetectsFilament() && !fsensor.getFilamentPresent()) { // The MMU 'Load filament' state machine will reject the command if any @@ -5239,7 +5239,7 @@ static void lcd_main_menu() if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_CALIBRATION), lcd_calibration_menu); } - if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) { + if (!usb_timer.running() && (lcd_commands_type == LcdCommands::Idle)) { MENU_ITEM_SUBMENU_P(_i("Statistics"), lcd_menu_statistics);////MSG_STATISTICS c=18 } From 170dddfd7174ed3320571b54fc751d1d3445b128 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 20 Aug 2022 16:04:29 +0200 Subject: [PATCH 2/6] Set/clear loading_flag also during unload --- Firmware/ultralcd.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 25a193f3a..e193a30f7 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1867,7 +1867,10 @@ void mFilamentItem(uint16_t nTemp, uint16_t nTempBed) if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad } if (eFilamentAction == FilamentAction::UnLoad) - enquecommand_P(MSG_M702); // unload filament + { + loading_flag = true; + enquecommand_P(MSG_M702); // unload filament + } } break; case FilamentAction::MmuLoad: @@ -4886,6 +4889,7 @@ void unload_filament(float unloadLength) lcd_setstatuspgm(MSG_WELCOME); custom_message_type = CustomMsg::Status; eFilamentAction = FilamentAction::None; + loading_flag = false; } /// @brief Set print fan speed From e3fd6a4902d2c5315a79bed2778a45a89bfc27c0 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 20 Aug 2022 16:04:57 +0200 Subject: [PATCH 3/6] Do not allow filament actions while an existing one is taking place --- Firmware/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index e193a30f7..1bd2e47d9 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5212,7 +5212,7 @@ static void lcd_main_menu() } } - if ( ! ( printJobOngoing() || (lcd_commands_type != LcdCommands::Idle) || Stopped) ) { + if ( ! ( printJobOngoing() || (lcd_commands_type != LcdCommands::Idle) || loading_flag || Stopped ) ) { if (MMU2::mmu2.Enabled()) { if(!MMU2::mmu2.FindaDetectsFilament() && !fsensor.getFilamentPresent()) { // The MMU 'Load filament' state machine will reject the command if any From 05b536947b6c8f65cdca68297be105a0337f31c4 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 20 Aug 2022 16:09:10 +0200 Subject: [PATCH 4/6] Refuse to start a SD print until filament loading is complete Do not blidnly clear the loading_flag, check for it! Just disallowing the SD menu while loading is being performed is not sufficient, since the menu can be entered also by inserting card while loading is taking place. This is also nicer in behavior, as we allow to navigate the SD card while loading. --- Firmware/ultralcd.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 1bd2e47d9..f6b9b244c 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6917,7 +6917,8 @@ static bool check_file(const char* filename) { static void menu_action_sdfile(const char* filename) { - loading_flag = false; + if(loading_flag) return; + char cmd[30]; char* c; bool result = true; From 074b5d380f98ccdd3bea1f169c9df6c7ebebd3b6 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 13 Dec 2022 13:35:45 +0100 Subject: [PATCH 5/6] Consistently replace loading_flag with eFilamentAction Remove loading_flag and check for eFilamentAction instead which already flags both load/unload (in addition to mmu actions). Correctly transition from AutoLoad to Load as soon as the operation cannot be cancelled anymore as opposed to resetting it. --- Firmware/Marlin.h | 1 - Firmware/Marlin_main.cpp | 4 +--- Firmware/Prusa_farm.cpp | 6 ++--- Firmware/ultralcd.cpp | 52 ++++++++++++++++++++-------------------- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 66abdaf12..24ce1c9bb 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -278,7 +278,6 @@ extern uint32_t start_pause_print; // milliseconds extern ShortTimer usb_timer; extern bool processing_tcode; extern bool homing_flag; -extern bool loading_flag; extern uint32_t total_filament_used; // mm/100 or 10um /// @brief Save print statistics to EEPROM diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index cf72c0bf3..fa2d3b8e8 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -179,7 +179,6 @@ bool mesh_bed_leveling_flag = false; uint32_t total_filament_used; HeatingStatus heating_status; -bool loading_flag = false; int fan_edge_counter[2]; int fan_speed[2]; @@ -3579,13 +3578,12 @@ void gcode_M701(float fastLoadLength, uint8_t mmuSlotIndex){ Sound_MakeCustom(50, 500, false); - if (!farm_mode && loading_flag) { + if (!farm_mode && (eFilamentAction != FilamentAction::None)) { lcd_load_filament_color_check(); } lcd_update_enable(true); lcd_update(2); lcd_setstatuspgm(MSG_WELCOME); - loading_flag = false; custom_message_type = CustomMsg::Status; } diff --git a/Firmware/Prusa_farm.cpp b/Firmware/Prusa_farm.cpp index 5ff6a8c66..88a3ba481 100644 --- a/Firmware/Prusa_farm.cpp +++ b/Firmware/Prusa_farm.cpp @@ -242,7 +242,7 @@ void prusa_statistics(uint8_t _message) { else if (isPrintPaused) { prusa_statistics_case0(14); } - else if (IS_SD_PRINTING || loading_flag) { + else if (IS_SD_PRINTING || (eFilamentAction != FilamentAction::None)) { prusa_statistics_case0(4); } else { @@ -270,7 +270,7 @@ void prusa_statistics(uint8_t _message) { status_number = 3; farm_timer = 1; - if (IS_SD_PRINTING || loading_flag) { + if (IS_SD_PRINTING || (eFilamentAction != FilamentAction::None)) { SERIAL_ECHO('{'); prusa_stat_printerstatus(4); prusa_stat_farm_number(); @@ -374,7 +374,7 @@ void prusa_statistics_update_from_status_screen() { switch (farm_timer) { case 8: prusa_statistics(21); - if(loading_flag) + if(eFilamentAction != FilamentAction::None) prusa_statistics(22); break; case 5: diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f6b9b244c..00d02349c 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1796,10 +1796,10 @@ switch(eFilamentAction) switch(eFilamentAction) { case FilamentAction::AutoLoad: - eFilamentAction=FilamentAction::None; // i.e. non-autoLoad + // loading no longer cancellable + eFilamentAction = FilamentAction::Load; // FALLTHRU case FilamentAction::Load: - loading_flag=true; enquecommand_P(MSG_M701); // load filament break; case FilamentAction::UnLoad: @@ -1818,6 +1818,17 @@ switch(eFilamentAction) } } +void mFilamentBack() +{ + if (eFilamentAction == FilamentAction::AutoLoad || + eFilamentAction == FilamentAction::Preheat || + eFilamentAction == FilamentAction::Lay1Cal) + { + // filament action has been cancelled + eFilamentAction = FilamentAction::None; + } +} + void mFilamentItem(uint16_t nTemp, uint16_t nTempBed) { uint8_t nLevel; @@ -1860,17 +1871,16 @@ void mFilamentItem(uint16_t nTemp, uint16_t nTempBed) { nLevel = bFilamentPreheatState ? 1 : 2; menu_back(nLevel); - if ((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad)) - { - loading_flag = true; + + if (eFilamentAction == FilamentAction::AutoLoad) { + // loading no longer cancellable + eFilamentAction = FilamentAction::Load; + } + + if (eFilamentAction == FilamentAction::Load) enquecommand_P(MSG_M701); // load filament - if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad - } - if (eFilamentAction == FilamentAction::UnLoad) - { - loading_flag = true; + else if (eFilamentAction == FilamentAction::UnLoad) enquecommand_P(MSG_M702); // unload filament - } } break; case FilamentAction::MmuLoad: @@ -1971,7 +1981,7 @@ void mFilamentItem(uint16_t nTemp, uint16_t nTempBed) menu_back(); } menu_back(); - if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad + mFilamentBack(); } } } @@ -2047,16 +2057,6 @@ static void mFilamentItem_PVB() mFilamentItem(PVB_PREHEAT_HOTEND_TEMP, PVB_PREHEAT_HPB_TEMP); } -void mFilamentBack() -{ - if (eFilamentAction == FilamentAction::AutoLoad || - eFilamentAction == FilamentAction::Preheat || - eFilamentAction == FilamentAction::Lay1Cal) - { - eFilamentAction = FilamentAction::None; // i.e. non-autoLoad - } -} - void lcd_generic_preheat_menu() { MENU_BEGIN(); @@ -3681,13 +3681,14 @@ static void lcd_wizard_load() { // NOTE: a full screen message showing which filament is being inserted // is performed by M701. For this reason MSG_LOADING_FILAMENT is not // used here when a MMU is used. + eFilamentAction = FilamentAction::MmuLoad; } else { lcd_show_fullscreen_message_and_wait_P( _i("Please insert filament into the extruder, then press the knob to load it.")); ////MSG_WIZARD_LOAD_FILAMENT c=20 r=6 lcd_update_enable(false); lcd_clear(); lcd_puts_at_P(0, 2, _T(MSG_LOADING_FILAMENT)); - loading_flag = true; + eFilamentAction = FilamentAction::Load; } // When MMU is disabled P parameter is ignored @@ -4889,7 +4890,6 @@ void unload_filament(float unloadLength) lcd_setstatuspgm(MSG_WELCOME); custom_message_type = CustomMsg::Status; eFilamentAction = FilamentAction::None; - loading_flag = false; } /// @brief Set print fan speed @@ -5212,7 +5212,7 @@ static void lcd_main_menu() } } - if ( ! ( printJobOngoing() || (lcd_commands_type != LcdCommands::Idle) || loading_flag || Stopped ) ) { + if ( ! ( printJobOngoing() || (lcd_commands_type != LcdCommands::Idle) || (eFilamentAction != FilamentAction::None) || Stopped ) ) { if (MMU2::mmu2.Enabled()) { if(!MMU2::mmu2.FindaDetectsFilament() && !fsensor.getFilamentPresent()) { // The MMU 'Load filament' state machine will reject the command if any @@ -6917,7 +6917,7 @@ static bool check_file(const char* filename) { static void menu_action_sdfile(const char* filename) { - if(loading_flag) return; + if(eFilamentAction != FilamentAction::None) return; char cmd[30]; char* c; From 3485c2046484d6f622bb48a0319db7e3e1e87bf6 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 13 Dec 2022 13:42:34 +0100 Subject: [PATCH 6/6] Improve FilamentAction comments --- Firmware/ultralcd.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 541215853..a2ae49cee 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -175,17 +175,17 @@ void lcd_hw_setup_menu(void); // NOT static due to using ins enum class FilamentAction : uint_least8_t { - None, //!< 'none' state is used as flag for (filament) autoLoad (i.e. opposite for 'autoLoad' state) + None, // no filament action is taking place Load, - AutoLoad, + AutoLoad, // triggered by insertion, cancellable until it transitions to Load UnLoad, MmuLoad, MmuUnLoad, MmuEject, MmuCut, MmuLoadingTest, - Preheat, - Lay1Cal, + Preheat, // triggered by preheat (cancellable) + Lay1Cal, // triggered by 1st layer calibration (cancellable) }; extern FilamentAction eFilamentAction;