Merge pull request #4063 from gudnimg/PFW-1503

PFW-1503 Improve live Z babystep menu handling
This commit is contained in:
3d-gussner 2023-03-24 14:01:15 +01:00 committed by GitHub
commit 6959b372ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 34 deletions

View File

@ -4,7 +4,6 @@
#include "Filament_sensor.h" #include "Filament_sensor.h"
#include "Timer.h" #include "Timer.h"
#include "cardreader.h"
#include "eeprom.h" #include "eeprom.h"
#include "menu.h" #include "menu.h"
#include "planner.h" #include "planner.h"
@ -113,8 +112,7 @@ void Filament_sensor::triggerFilamentInserted() {
&& (! MMU2::mmu2.Enabled() ) // quick and dirty hack to prevent spurious runouts while the MMU is in charge && (! MMU2::mmu2.Enabled() ) // quick and dirty hack to prevent spurious runouts while the MMU is in charge
&& !( && !(
moves_planned() != 0 moves_planned() != 0
|| IS_SD_PRINTING || printJobOngoing()
|| usb_timer.running()
|| (lcd_commands_type == LcdCommands::Layer1Cal) || (lcd_commands_type == LcdCommands::Layer1Cal)
|| eeprom_read_byte((uint8_t *)EEPROM_WIZARD_ACTIVE) || eeprom_read_byte((uint8_t *)EEPROM_WIZARD_ACTIVE)
) )
@ -131,8 +129,7 @@ void Filament_sensor::triggerFilamentRemoved() {
&& !saved_printing && !saved_printing
&& ( && (
moves_planned() != 0 moves_planned() != 0
|| IS_SD_PRINTING || printJobOngoing()
|| usb_timer.running()
|| (lcd_commands_type == LcdCommands::Layer1Cal) || (lcd_commands_type == LcdCommands::Layer1Cal)
|| eeprom_read_byte((uint8_t *)EEPROM_WIZARD_ACTIVE) || eeprom_read_byte((uint8_t *)EEPROM_WIZARD_ACTIVE)
) )

View File

@ -354,7 +354,11 @@ extern LongTimer safetyTimer;
#define PRINT_PERCENT_DONE_INIT 0xff #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, //! 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 //! which is not the same as posting the M600 command into the command queue
@ -365,6 +369,15 @@ extern bool printer_active();
//! I'd normally change this macro, but who knows what would happen in the MMU :) //! I'd normally change this macro, but who knows what would happen in the MMU :)
bool check_fsensor(); bool check_fsensor();
//! Condition where Babystepping is allowed:
//! 1) Z-axis position is less than 2.0mm (only allowed during the first couple of layers)
//! 2) Not allowed during Homing (printer busy)
//! 3) Not allowed during Mesh Bed Leveling (printer busy)
//! 4) Allowed if:
//! - First Layer Calibration is running
//! - OR there are queued blocks, printJob is running and it's not paused, and Z-axis position is less than 2.0mm (only allowed during the first couple of layers)
bool babystep_allowed();
extern void calculate_extruder_multipliers(); extern void calculate_extruder_multipliers();
// Similar to the default Arduino delay function, // Similar to the default Arduino delay function,

View File

@ -524,9 +524,12 @@ void servo_init()
#endif #endif
} }
bool __attribute__((noinline)) printJobOngoing() {
return (IS_SD_PRINTING || usb_timer.running());
}
bool __attribute__((noinline)) printer_active() { bool __attribute__((noinline)) printer_active() {
return IS_SD_PRINTING return printJobOngoing()
|| usb_timer.running()
|| isPrintPaused || isPrintPaused
|| (custom_message_type == CustomMsg::TempCal) || (custom_message_type == CustomMsg::TempCal)
|| saved_printing || saved_printing
@ -538,12 +541,19 @@ bool __attribute__((noinline)) printer_active() {
// Currently only used in one place, allowed to be inlined // Currently only used in one place, allowed to be inlined
bool check_fsensor() { bool check_fsensor() {
return (IS_SD_PRINTING || usb_timer.running()) return printJobOngoing()
&& mcode_in_progress != 600 && mcode_in_progress != 600
&& !saved_printing && !saved_printing
&& e_active(); && e_active();
} }
bool __attribute__((noinline)) babystep_allowed() {
return ( !homing_flag
&& !mesh_bed_leveling_flag
&& ( lcd_commands_type == LcdCommands::Layer1Cal || ( blocks_queued() && !isPrintPaused && printJobOngoing() && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU)))
);
}
bool fans_check_enabled = true; bool fans_check_enabled = true;
#ifdef TMC2130 #ifdef TMC2130
@ -9566,7 +9576,7 @@ void ThermalStop(bool allow_recovery)
Stopped = true; Stopped = true;
// Either pause or stop the print // Either pause or stop the print
if(allow_recovery && (IS_SD_PRINTING || usb_timer.running())) { if(allow_recovery && printJobOngoing()) {
if (!isPrintPaused) { if (!isPrintPaused) {
lcd_setalertstatuspgm(_T(MSG_PAUSED_THERMAL_ERROR), LCD_STATUS_CRITICAL); lcd_setalertstatuspgm(_T(MSG_PAUSED_THERMAL_ERROR), LCD_STATUS_CRITICAL);

View File

@ -1,6 +1,5 @@
// fan control and check // fan control and check
#include "fancheck.h" #include "fancheck.h"
#include "cardreader.h"
#include "ultralcd.h" #include "ultralcd.h"
#include "sound.h" #include "sound.h"
#include "messages.h" #include "messages.h"
@ -85,7 +84,7 @@ void fanSpeedError(unsigned char _fan) {
if (fan_check_error == EFCE_REPORTED) return; if (fan_check_error == EFCE_REPORTED) return;
fan_check_error = EFCE_REPORTED; fan_check_error = EFCE_REPORTED;
if (IS_SD_PRINTING || usb_timer.running()) { if (printJobOngoing()) {
// A print is ongoing, pause the print normally // A print is ongoing, pause the print normally
if(!isPrintPaused) { if(!isPrintPaused) {
if (usb_timer.running()) if (usb_timer.running())

View File

@ -833,8 +833,6 @@ void lcd_commands()
const float extrusion_width = (nozzle_dia + 20)/1000.0f; const float extrusion_width = (nozzle_dia + 20)/1000.0f;
const float layer_height = 0.2f; const float layer_height = 0.2f;
if(lcd_commands_step>1) lcd_timeoutToStatus.start(); //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
if (!blocks_queued() && cmd_buffer_empty() && !saved_printing) if (!blocks_queued() && cmd_buffer_empty() && !saved_printing)
{ {
if (lcd_commands_step == 0) if (lcd_commands_step == 0)
@ -879,7 +877,6 @@ void lcd_commands()
break; break;
case 2: case 2:
lay1cal_finish(MMU2::mmu2.Enabled()); lay1cal_finish(MMU2::mmu2.Enabled());
menu_leaving = 1; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
break; break;
case 1: case 1:
lcd_setstatuspgm(MSG_WELCOME); lcd_setstatuspgm(MSG_WELCOME);
@ -2596,13 +2593,6 @@ static void lcd_move_z() {
*/ */
static void lcd_babystep_z() static void lcd_babystep_z()
{ {
if (homing_flag || mesh_bed_leveling_flag)
{
// printer changed to a new state where live Z is forbidden
menu_back();
return;
}
typedef struct typedef struct
{ {
int8_t status; int8_t status;
@ -3508,7 +3498,7 @@ static void crash_mode_switch()
{ {
lcd_crash_detect_enable(); 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); else menu_goto(lcd_settings_menu, 9, true, true);
} }
#endif //TMC2130 #endif //TMC2130
@ -4641,7 +4631,7 @@ static void lcd_settings_menu()
MENU_ITEM_TOGGLE_P(_T(MSG_RPI_PORT), (selectedSerialPort == 0) ? _T(MSG_OFF) : _T(MSG_ON), lcd_second_serial_set); MENU_ITEM_TOGGLE_P(_T(MSG_RPI_PORT), (selectedSerialPort == 0) ? _T(MSG_OFF) : _T(MSG_ON), lcd_second_serial_set);
#endif //HAS_SECOND_SERIAL #endif //HAS_SECOND_SERIAL
if (!isPrintPaused && !homing_flag && !mesh_bed_leveling_flag) if ( babystep_allowed() )
MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z); MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
#if (LANG_MODE != 0) #if (LANG_MODE != 0)
@ -5350,9 +5340,8 @@ static void lcd_main_menu()
MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_); MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
#endif //TMC2130_DEBUG #endif //TMC2130_DEBUG
if ( ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag) { if ( babystep_allowed() )
MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8 MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
}
if (farm_mode) if (farm_mode)
MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8 MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
@ -5385,7 +5374,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); MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
} }
#ifdef TEMP_MODEL #ifdef TEMP_MODEL
@ -5413,7 +5402,7 @@ static void lcd_main_menu()
} }
#endif //SDSUPPORT #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) { if (!farm_mode) {
const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)); const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
const int8_t nextSheet = eeprom_next_initialized_sheet(sheet); const int8_t nextSheet = eeprom_next_initialized_sheet(sheet);
@ -5423,7 +5412,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()) { if (MMU2::mmu2.Enabled()) {
MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), mmu_load_filament_menu); 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 MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), mmu_load_to_nozzle_menu);////MSG_LOAD_TO_NOZZLE c=18
@ -7470,13 +7459,11 @@ void menu_lcd_longpress_func(void)
// explicitely listed menus which are allowed to rise the move-z or live-adj-z functions // explicitely listed menus which are allowed to rise the move-z or live-adj-z functions
// The lists are not the same for both functions, so first decide which function is to be performed // The lists are not the same for both functions, so first decide which function is to be performed
if ( (moves_planned() || IS_SD_PRINTING || usb_timer.running() )){ // long press as live-adj-z if (babystep_allowed()){ // long press as live-adj-z
if (( current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU ) // only allow live-adj-z up to 2mm of print height if ( menu_menu == lcd_status_screen // and in listed menus...
&& ( menu_menu == lcd_status_screen // and in listed menus...
|| menu_menu == lcd_main_menu || menu_menu == lcd_main_menu
|| menu_menu == lcd_tune_menu || menu_menu == lcd_tune_menu
|| menu_menu == lcd_support_menu || menu_menu == lcd_support_menu
)
){ ){
lcd_clear(); lcd_clear();
menu_submenu(lcd_babystep_z); menu_submenu(lcd_babystep_z);
@ -7502,10 +7489,13 @@ void menu_lcd_longpress_func(void)
} }
} }
// Note: When lcd_commands_type is not LcdCommands::Idle
// we should ignore lcd_timeoutToStatus. Example use case is
// when running first layer calibration.
static inline bool z_menu_expired() static inline bool z_menu_expired()
{ {
return (menu_menu == lcd_babystep_z return (menu_menu == lcd_babystep_z
&& lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z)); && (!babystep_allowed() || (lcd_commands_type == LcdCommands::Idle && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z))));
} }
static inline bool other_menu_expired() static inline bool other_menu_expired()
{ {