From e40d8ebbcc68e213bd698d96024df2506a7331ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 18 Mar 2023 12:15:44 +0000 Subject: [PATCH] Implement printJobOngoing() This makes the if statments a little bit more readable Change in memory: Flash: -88 bytes SRAM: 0 bytes --- Firmware/Filament_sensor.cpp | 6 ++---- Firmware/Marlin.h | 6 +++++- Firmware/Marlin_main.cpp | 13 ++++++++----- Firmware/fancheck.cpp | 2 +- Firmware/ultralcd.cpp | 8 ++++---- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Firmware/Filament_sensor.cpp b/Firmware/Filament_sensor.cpp index dbccf2760..9fb9c881c 100644 --- a/Firmware/Filament_sensor.cpp +++ b/Firmware/Filament_sensor.cpp @@ -113,8 +113,7 @@ void Filament_sensor::triggerFilamentInserted() { && (! MMU2::mmu2.Enabled() ) // quick and dirty hack to prevent spurious runouts while the MMU is in charge && !( moves_planned() != 0 - || IS_SD_PRINTING - || usb_timer.running() + || printJobOngoing() || (lcd_commands_type == LcdCommands::Layer1Cal) || eeprom_read_byte((uint8_t *)EEPROM_WIZARD_ACTIVE) ) @@ -131,8 +130,7 @@ void Filament_sensor::triggerFilamentRemoved() { && !saved_printing && ( moves_planned() != 0 - || IS_SD_PRINTING - || usb_timer.running() + || printJobOngoing() || (lcd_commands_type == LcdCommands::Layer1Cal) || eeprom_read_byte((uint8_t *)EEPROM_WIZARD_ACTIVE) ) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index c4ac86a93..b7d376255 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -354,7 +354,11 @@ extern LongTimer safetyTimer; #define PRINT_PERCENT_DONE_INIT 0xff -extern bool printer_active(); +// Returns true if there is a print running. It does not matter if +// the print is paused, that still counts as a "running" print. +bool printJobOngoing(); + +bool printer_active(); //! Beware - mcode_in_progress is set as soon as the command gets really processed, //! which is not the same as posting the M600 command into the command queue diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 12268663c..1d71c3f01 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -525,9 +525,12 @@ void servo_init() #endif } +bool __attribute__((noinline)) printJobOngoing() { + return (IS_SD_PRINTING || usb_timer.running()); +} + bool __attribute__((noinline)) printer_active() { - return IS_SD_PRINTING - || usb_timer.running() + return printJobOngoing() || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing @@ -539,7 +542,7 @@ bool __attribute__((noinline)) printer_active() { // Currently only used in one place, allowed to be inlined bool check_fsensor() { - return (IS_SD_PRINTING || usb_timer.running()) + return printJobOngoing() && mcode_in_progress != 600 && !saved_printing && e_active(); @@ -548,7 +551,7 @@ bool check_fsensor() { bool __attribute__((noinline)) babystep_allowed() { return ( (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag - && ( blocks_queued() || lcd_commands_type == LcdCommands::Layer1Cal || ( !isPrintPaused && (IS_SD_PRINTING || usb_timer.running()) )) + && ( blocks_queued() || lcd_commands_type == LcdCommands::Layer1Cal || ( !isPrintPaused && printJobOngoing() )) ); } @@ -9574,7 +9577,7 @@ void ThermalStop(bool allow_recovery) Stopped = true; // Either pause or stop the print - if(allow_recovery && (IS_SD_PRINTING || usb_timer.running())) { + if(allow_recovery && printJobOngoing()) { if (!isPrintPaused) { lcd_setalertstatuspgm(_T(MSG_PAUSED_THERMAL_ERROR), LCD_STATUS_CRITICAL); diff --git a/Firmware/fancheck.cpp b/Firmware/fancheck.cpp index 3bf2a6c1f..d3f7e55d6 100755 --- a/Firmware/fancheck.cpp +++ b/Firmware/fancheck.cpp @@ -85,7 +85,7 @@ void fanSpeedError(unsigned char _fan) { if (fan_check_error == EFCE_REPORTED) return; fan_check_error = EFCE_REPORTED; - if (IS_SD_PRINTING || usb_timer.running()) { + if (printJobOngoing()) { // A print is ongoing, pause the print normally if(!isPrintPaused) { if (usb_timer.running()) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 3bb330bb0..7fb60f668 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3495,7 +3495,7 @@ static void crash_mode_switch() { lcd_crash_detect_enable(); } - if (IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal)) menu_goto(lcd_tune_menu, 9, true, true); + if (printJobOngoing() || (lcd_commands_type == LcdCommands::Layer1Cal)) menu_goto(lcd_tune_menu, 9, true, true); else menu_goto(lcd_settings_menu, 9, true, true); } #endif //TMC2130 @@ -5371,7 +5371,7 @@ static void lcd_main_menu() } } } - if((IS_SD_PRINTING || usb_timer.running() || isPrintPaused) && (custom_message_type != CustomMsg::MeshBedLeveling) && !processing_tcode) { + if((printJobOngoing() || isPrintPaused) && (custom_message_type != CustomMsg::MeshBedLeveling) && !processing_tcode) { MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop); } #ifdef TEMP_MODEL @@ -5399,7 +5399,7 @@ static void lcd_main_menu() } #endif //SDSUPPORT - if(!isPrintPaused && !IS_SD_PRINTING && !usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) { + if(!isPrintPaused && !printJobOngoing() && (lcd_commands_type != LcdCommands::Layer1Cal)) { if (!farm_mode) { const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)); const int8_t nextSheet = eeprom_next_initialized_sheet(sheet); @@ -5409,7 +5409,7 @@ static void lcd_main_menu() } } - if ( ! ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal || Stopped) ) ) { + if ( ! ( printJobOngoing() || (lcd_commands_type == LcdCommands::Layer1Cal || Stopped) ) ) { if (MMU2::mmu2.Enabled()) { MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), mmu_load_filament_menu); MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), mmu_load_to_nozzle_menu);////MSG_LOAD_TO_NOZZLE c=18