PFW-1503 Improve live Z babystep menu handling

Fixes an issue with running first layer calibration twice in a row.

Improvements:
Now the Z baby step menu closes automatically when first layer calibration is done.
No need to wait for a timeout or close the menu manually by setting a variable

If the baby stepping menu is open, and suddenly
the printer enters a state where baby stepping
is not allowed.
The printer will save the last value before closing the menu.

When LcdCommands != Idle, don't dismiss
the Z baby step menu. This saves 20B

Change in memory:
Flash: -130 bytes
SRAM: 0 bytes
This commit is contained in:
Guðni Már Gilbert 2023-03-04 15:25:06 +00:00
parent 16ec3e376f
commit bc2366cd8d
3 changed files with 22 additions and 17 deletions

View File

@ -365,6 +365,13 @@ 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) Axis are trusted: Z-axis position must be known
//! 2) Not allowed during Homing (printer busy)
//! 3) Not allowed during Mesh Bed Leveling (printer busy)
//! 4) Allowed if there are queued blocks OR there is a print job running
bool BABYSTEP_ALLOWED();
extern void calculate_extruder_multipliers();
// Similar to the default Arduino delay function,

View File

@ -545,6 +545,13 @@ bool check_fsensor() {
&& e_active();
}
bool __attribute__((noinline)) BABYSTEP_ALLOWED() {
return (axis_known_position[Z_AXIS]
&& !homing_flag && !mesh_bed_leveling_flag
&& ( blocks_queued() || ( !isPrintPaused && (IS_SD_PRINTING || usb_timer.running()) ))
);
}
bool fans_check_enabled = true;
#ifdef TMC2130

View File

@ -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)
@ -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);
@ -2593,13 +2590,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;
@ -4638,7 +4628,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)
@ -5347,7 +5337,7 @@ 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
}
@ -7467,13 +7457,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);
@ -7499,10 +7487,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()
{