diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index a1b6fe4eb..cc2766b44 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -377,7 +377,7 @@ extern uint16_t gcode_in_progress; extern LongTimer safetyTimer; #define PRINT_PERCENT_DONE_INIT 0xff -#define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing || (lcd_commands_type == LcdCommands::Layer1Cal) || mmu_print_saved) +#define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing || (lcd_commands_type == LcdCommands::Layer1Cal) || mmu_print_saved || homing_flag || mesh_bed_leveling_flag) //! 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 d5b4ff106..23a734d77 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2722,8 +2722,7 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon current_position[Z_AXIS] = st_get_position_mm(Z_AXIS); #endif - // Reset baby stepping to zero, if the babystepping has already been loaded before. The babystepsTodo value will be - // consumed during the first movements following this statement. + // Reset baby stepping to zero, if the babystepping has already been loaded before. if (home_z) babystep_undo(); @@ -4754,6 +4753,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) */ case 30: { + homing_flag = true; st_synchronize(); // TODO: make sure the bed_level_rotation_matrix is identity or the planner will get set incorectly int l_feedmultiply = setup_for_endstop_move(); @@ -4765,6 +4765,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) printf_P(_N("%S X: %.5f Y: %.5f Z: %.5f\n"), _T(MSG_BED), _x, _y, _z); clean_up_after_endstop_move(l_feedmultiply); + homing_flag = false; } break; @@ -4855,6 +4856,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; } } + + homing_flag = true; // keep homing on to avoid babystepping while the LCD is enabled lcd_update_enable(true); KEEPALIVE_STATE(NOT_BUSY); //no need to print busy messages as we print current temperatures periodicaly SERIAL_ECHOLNPGM("PINDA probe calibration start"); @@ -4899,6 +4902,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) bool find_z_result = find_bed_induction_sensor_point_z(-1.f); if (find_z_result == false) { lcd_temp_cal_show_result(find_z_result); + homing_flag = false; break; } zero_z = current_position[Z_AXIS]; @@ -4949,9 +4953,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) printf_P(_N("\nPINDA temperature: %.1f Z shift (mm): %.3f"), current_temperature_pinda, current_position[Z_AXIS] - zero_z); EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &z_shift); - } lcd_temp_cal_show_result(true); + homing_flag = false; #else //PINDA_THERMISTOR @@ -5161,8 +5165,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) mbl.reset(); //reset mesh bed leveling - // Reset baby stepping to zero, if the babystepping has already been loaded before. The babystepsTodo value will be - // consumed during the first movements following this statement. + // Reset baby stepping to zero, if the babystepping has already been loaded before. babystep_undo(); // Cycle through all points and probe them diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index fb79022ff..b4490e93f 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -3030,8 +3030,6 @@ static void shift_z(float delta) plan_set_z_position(current_position[Z_AXIS]); } -#define BABYSTEP_LOADZ_BY_PLANNER - // Number of baby steps applied static int babystepLoadZ = 0; @@ -3062,20 +3060,12 @@ void babystep_load() void babystep_apply() { babystep_load(); -#ifdef BABYSTEP_LOADZ_BY_PLANNER shift_z(- float(babystepLoadZ) / float(cs.axis_steps_per_unit[Z_AXIS])); -#else - babystepsTodoZadd(babystepLoadZ); -#endif /* BABYSTEP_LOADZ_BY_PLANNER */ } void babystep_undo() { -#ifdef BABYSTEP_LOADZ_BY_PLANNER shift_z(float(babystepLoadZ) / float(cs.axis_steps_per_unit[Z_AXIS])); -#else - babystepsTodoZsubtract(babystepLoadZ); -#endif /* BABYSTEP_LOADZ_BY_PLANNER */ babystepLoadZ = 0; } diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 3a70da21a..35b05f0e8 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -2047,18 +2047,18 @@ FORCE_INLINE static void temperature_isr() if(curTodo>0) { - asm("cli"); + CRITICAL_SECTION_START; babystep(axis,/*fwd*/true); babystepsTodo[axis]--; //less to do next time - asm("sei"); + CRITICAL_SECTION_END; } else if(curTodo<0) { - asm("cli"); + CRITICAL_SECTION_START; babystep(axis,/*fwd*/false); babystepsTodo[axis]++; //less to do next time - asm("sei"); + CRITICAL_SECTION_END; } } #endif //BABYSTEPPING diff --git a/Firmware/temperature.h b/Firmware/temperature.h index da88a53c0..0bf944724 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -99,13 +99,10 @@ extern bool bedPWMDisabled; float unscalePID_d(float d); #endif - - -#ifdef BABYSTEPPING - extern volatile int babystepsTodo[3]; -#endif -void resetPID(uint8_t extruder); + +#ifdef BABYSTEPPING +extern volatile int babystepsTodo[3]; inline void babystepsTodoZadd(int n) { @@ -115,15 +112,9 @@ inline void babystepsTodoZadd(int n) CRITICAL_SECTION_END } } +#endif -inline void babystepsTodoZsubtract(int n) -{ - if (n != 0) { - CRITICAL_SECTION_START - babystepsTodo[Z_AXIS] -= n; - CRITICAL_SECTION_END - } -} +void resetPID(uint8_t extruder); //high level conversion routines, for use outside of temperature.cpp //inline so that there is no performance decrease. diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 7f4cfa648..0117cca8a 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -2850,6 +2850,13 @@ void lcd_menu_statistics() static void _lcd_move(const char *name, int axis, int min, int max) { + if (homing_flag || mesh_bed_leveling_flag) + { + // printer entered a new state where axis move is forbidden + menu_back(); + return; + } + typedef struct { // 2bytes total bool initialized; // 1byte @@ -3071,6 +3078,13 @@ 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; @@ -3106,19 +3120,13 @@ static void lcd_babystep_z() lcd_timeoutToStatus.start(); } - if (lcd_encoder != 0) + if (lcd_encoder != 0) { - if (homing_flag) lcd_encoder = 0; _md->babystepMemZ += (int)lcd_encoder; if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm else if (_md->babystepMemZ > Z_BABYSTEP_MAX) _md->babystepMemZ = Z_BABYSTEP_MAX; //0 - else - { - CRITICAL_SECTION_START - babystepsTodo[Z_AXIS] += (int)lcd_encoder; - CRITICAL_SECTION_END - } + else babystepsTodoZadd(lcd_encoder); _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS]; _delay(50); @@ -5752,10 +5760,12 @@ static void lcd_settings_menu() MENU_ITEM_BACK_P(_T(MSG_MAIN)); MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE - if (!homing_flag) + + if (!PRINTER_ACTIVE || isPrintPaused) + { MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS - if (!isPrintPaused) MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS + } SETTINGS_FILAMENT_SENSOR; @@ -5789,7 +5799,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) + if (!isPrintPaused && !homing_flag && !mesh_bed_leveling_flag) MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z); #if (LANG_MODE != 0)