Skip to content

Commit

Permalink
Merge pull request MarlinFirmware#4063 from gudnimg/PFW-1503
Browse files Browse the repository at this point in the history
PFW-1503 Improve live Z babystep menu handling
  • Loading branch information
3d-gussner authored Mar 24, 2023
2 parents 7bbd561 + 178c1f4 commit 6959b37
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 34 deletions.
7 changes: 2 additions & 5 deletions Firmware/Filament_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "Filament_sensor.h"
#include "Timer.h"
#include "cardreader.h"
#include "eeprom.h"
#include "menu.h"
#include "planner.h"
Expand Down Expand Up @@ -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
&& !(
moves_planned() != 0
|| IS_SD_PRINTING
|| usb_timer.running()
|| printJobOngoing()
|| (lcd_commands_type == LcdCommands::Layer1Cal)
|| eeprom_read_byte((uint8_t *)EEPROM_WIZARD_ACTIVE)
)
Expand All @@ -131,8 +129,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)
)
Expand Down
15 changes: 14 additions & 1 deletion Firmware/Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -365,6 +369,15 @@ extern bool printer_active();
//! I'd normally change this macro, but who knows what would happen in the MMU :)
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();

// Similar to the default Arduino delay function,
Expand Down
18 changes: 14 additions & 4 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,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
Expand All @@ -538,12 +541,19 @@ 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();
}

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;

#ifdef TMC2130
Expand Down Expand Up @@ -9566,7 +9576,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);

Expand Down
3 changes: 1 addition & 2 deletions Firmware/fancheck.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// fan control and check
#include "fancheck.h"
#include "cardreader.h"
#include "ultralcd.h"
#include "sound.h"
#include "messages.h"
Expand Down Expand Up @@ -85,7 +84,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())
Expand Down
34 changes: 12 additions & 22 deletions Firmware/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,6 @@ void lcd_commands()
const float extrusion_width = (nozzle_dia + 20)/1000.0f;
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 (lcd_commands_step == 0)
Expand Down Expand Up @@ -879,7 +877,6 @@ void lcd_commands()
break;
case 2:
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;
case 1:
lcd_setstatuspgm(MSG_WELCOME);
Expand Down Expand Up @@ -2596,13 +2593,6 @@ static void lcd_move_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
{
int8_t status;
Expand Down Expand Up @@ -3508,7 +3498,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
Expand Down Expand Up @@ -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);
#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);

#if (LANG_MODE != 0)
Expand Down Expand Up @@ -5350,9 +5340,8 @@ static void lcd_main_menu()
MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
#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
}

if (farm_mode)
MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
Expand Down Expand Up @@ -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);
}
#ifdef TEMP_MODEL
Expand Down Expand Up @@ -5413,7 +5402,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);
Expand All @@ -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()) {
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
Expand Down Expand Up @@ -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
// 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 (( current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU ) // only allow live-adj-z up to 2mm of print height
&& ( menu_menu == lcd_status_screen // and in listed menus...
if (babystep_allowed()){ // long press as live-adj-z
if ( menu_menu == lcd_status_screen // and in listed menus...
|| menu_menu == lcd_main_menu
|| menu_menu == lcd_tune_menu
|| menu_menu == lcd_support_menu
)
){
lcd_clear();
menu_submenu(lcd_babystep_z);
Expand All @@ -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()
{
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()
{
Expand Down

0 comments on commit 6959b37

Please sign in to comment.