From 1c026f0e4d0062160aaeb9b887b81c57db48c155 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 1 Apr 2020 20:38:46 +0200 Subject: [PATCH 01/14] Always sync before manipulating the planner position in FWRETRACT Calling plan_set_*_position should never be done without a sync, since the current_position can be (and usually is) several steps ahead. In retract() and inside the autoretract support, call st_synchronize() prior to calling any of these functions so that we don't corrupt the position of the backend! When unretracting, split the Z and E moves in two steps so that the E unretraction is not slowed down by the Z axis. Fix the indentation of the affected code. --- Firmware/Marlin_main.cpp | 108 +++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 49 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 8dbc0d840..0621399a3 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2377,38 +2377,44 @@ void refresh_cmd_timeout(void) } #ifdef FWRETRACT - void retract(bool retracting, bool swapretract = false) { +void retract(bool retracting, bool swapretract = false) { + // Perform FW retraction, just if needed, but behave as if the move has never took place in + // order to keep E/Z coordinates unchanged. This is done by manipulating the internal planner + // position, which requires a sync if(retracting && !retracted[active_extruder]) { - destination[X_AXIS]=current_position[X_AXIS]; - destination[Y_AXIS]=current_position[Y_AXIS]; - destination[Z_AXIS]=current_position[Z_AXIS]; - destination[E_AXIS]=current_position[E_AXIS]; - current_position[E_AXIS]+=(swapretract?retract_length_swap:cs.retract_length)*float(extrudemultiply)*0.01f; - plan_set_e_position(current_position[E_AXIS]); - float oldFeedrate = feedrate; - feedrate=cs.retract_feedrate*60; - retracted[active_extruder]=true; - prepare_move(); - current_position[Z_AXIS]-=cs.retract_zlift; - plan_set_position_curposXYZE(); - prepare_move(); - feedrate = oldFeedrate; + st_synchronize(); + set_destination_to_current(); + current_position[E_AXIS]+=(swapretract?retract_length_swap:cs.retract_length)*float(extrudemultiply)*0.01f; + plan_set_e_position(current_position[E_AXIS]); + float oldFeedrate = feedrate; + feedrate=cs.retract_feedrate*60; + retracted[active_extruder]=true; + prepare_move(); + if(cs.retract_zlift) { + st_synchronize(); + current_position[Z_AXIS]-=cs.retract_zlift; + plan_set_position_curposXYZE(); + prepare_move(); + } + feedrate = oldFeedrate; } else if(!retracting && retracted[active_extruder]) { - destination[X_AXIS]=current_position[X_AXIS]; - destination[Y_AXIS]=current_position[Y_AXIS]; - destination[Z_AXIS]=current_position[Z_AXIS]; - destination[E_AXIS]=current_position[E_AXIS]; - current_position[Z_AXIS]+=cs.retract_zlift; - plan_set_position_curposXYZE(); - current_position[E_AXIS]-=(swapretract?(retract_length_swap+retract_recover_length_swap):(cs.retract_length+cs.retract_recover_length))*float(extrudemultiply)*0.01f; - plan_set_e_position(current_position[E_AXIS]); - float oldFeedrate = feedrate; - feedrate=cs.retract_recover_feedrate*60; - retracted[active_extruder]=false; - prepare_move(); - feedrate = oldFeedrate; + st_synchronize(); + set_destination_to_current(); + float oldFeedrate = feedrate; + feedrate=cs.retract_recover_feedrate*60; + if(cs.retract_zlift) { + current_position[Z_AXIS]+=cs.retract_zlift; + plan_set_position_curposXYZE(); + prepare_move(); + st_synchronize(); + } + current_position[E_AXIS]-=(swapretract?(retract_length_swap+retract_recover_length_swap):(cs.retract_length+cs.retract_recover_length))*float(extrudemultiply)*0.01f; + plan_set_e_position(current_position[E_AXIS]); + retracted[active_extruder]=false; + prepare_move(); + feedrate = oldFeedrate; } - } //retract +} //retract #endif //FWRETRACT void trace() { @@ -4170,21 +4176,22 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) if (total_filament_used > ((current_position[E_AXIS] - destination[E_AXIS]) * 100)) { //protection against total_filament_used overflow total_filament_used = total_filament_used + ((destination[E_AXIS] - current_position[E_AXIS]) * 100); } - #ifdef FWRETRACT - if(cs.autoretract_enabled) + +#ifdef FWRETRACT + if(cs.autoretract_enabled) { if( !(code_seen('X') || code_seen('Y') || code_seen('Z')) && code_seen('E')) { - float echange=destination[E_AXIS]-current_position[E_AXIS]; - - if((echange<-MIN_RETRACT && !retracted[active_extruder]) || (echange>MIN_RETRACT && retracted[active_extruder])) { //move appears to be an attempt to retract or recover - current_position[E_AXIS] = destination[E_AXIS]; //hide the slicer-generated retract/recover from calculations - plan_set_e_position(current_position[E_AXIS]); //AND from the planner - retract(!retracted[active_extruder]); - return; - } - - + float echange=destination[E_AXIS]-current_position[E_AXIS]; + if((echange<-MIN_RETRACT && !retracted[active_extruder]) || (echange>MIN_RETRACT && retracted[active_extruder])) { //move appears to be an attempt to retract or recover + st_synchronize(); + current_position[E_AXIS] = destination[E_AXIS]; //hide the slicer-generated retract/recover from calculations + plan_set_e_position(current_position[E_AXIS]); //AND from the planner + retract(!retracted[active_extruder]); + return; + } } - #endif //FWRETRACT + } +#endif //FWRETRACT + prepare_move(); //ClearToSend(); } @@ -4252,9 +4259,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) lcd_update(0); } break; - #ifdef FWRETRACT - + +#ifdef FWRETRACT /*! ### G10 - Retract G10: Retract Retracts filament according to settings of `M207` @@ -4267,7 +4274,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) retract(true); #endif break; - + /*! ### G11 - Retract recover G11: Unretract @@ -4280,8 +4287,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) retract(false); #endif break; - #endif //FWRETRACT - +#endif //FWRETRACT + /*! ### G28 - Home all Axes one at a time G28: Move to Origin (Home) @@ -7147,8 +7154,9 @@ Sigma_Exit: if(code_seen(axis_codes[i])) cs.add_homing[i] = code_value(); } break; - #ifdef FWRETRACT + +#ifdef FWRETRACT /*! ### M207 - Set firmware retraction M207: Set retract length #### Usage @@ -7246,7 +7254,9 @@ Sigma_Exit: } }break; - #endif // FWRETRACT +#endif // FWRETRACT + + #if EXTRUDERS > 1 /*! From a456c4a52df5b78fac43455888f2c7708cc372ca Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Wed, 17 Feb 2021 13:04:46 +0100 Subject: [PATCH 02/14] Make watchdogReset() force_inline It makes no sense keeping watchdogReset as a separate function which must be called, since it only contains one instruction: "wdr". Not only was the code larger by 32 bytes in total, but also much slower (call+ret take 4 cycles together for no reason in this case). Surprisingly, doing just this on FW 3.9.3 solves issue #2954 on the one affected EINSY board, even though it makes not much sense (there must be some other timing issue). --- Firmware/optiboot_w25x20cl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/optiboot_w25x20cl.cpp b/Firmware/optiboot_w25x20cl.cpp index dce4074e1..2d3a76c72 100644 --- a/Firmware/optiboot_w25x20cl.cpp +++ b/Firmware/optiboot_w25x20cl.cpp @@ -43,7 +43,7 @@ static void watchdogConfig(uint8_t x) { WDTCSR = x; } -static void watchdogReset() { +static FORCE_INLINE void watchdogReset() { __asm__ __volatile__ ( "wdr\n" ); From 4e768057e7cc5449677220b5bddd41acb6ee073b Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Wed, 17 Feb 2021 15:59:52 +0100 Subject: [PATCH 03/14] Use standard wdt_reset() from AVR lib which translates to the one `wdr` instruction like before + wrap configuration of watchdog into cli/sei --- Firmware/optiboot_w25x20cl.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Firmware/optiboot_w25x20cl.cpp b/Firmware/optiboot_w25x20cl.cpp index 2d3a76c72..a18c8832d 100644 --- a/Firmware/optiboot_w25x20cl.cpp +++ b/Firmware/optiboot_w25x20cl.cpp @@ -7,6 +7,7 @@ #include "w25x20cl.h" #include "stk500.h" #include "bootapp.h" +#include #define OPTIBOOT_MAJVER 6 #define OPTIBOOT_CUSTOMVER 0 @@ -39,14 +40,10 @@ static unsigned const int __attribute__((section(".version"))) #endif static void watchdogConfig(uint8_t x) { + CRITICAL_SECTION_START WDTCSR = _BV(WDCE) | _BV(WDE); WDTCSR = x; -} - -static FORCE_INLINE void watchdogReset() { - __asm__ __volatile__ ( - "wdr\n" - ); + CRITICAL_SECTION_END } #define RECV_READY ((UCSR0A & _BV(RXC0)) != 0) @@ -63,7 +60,7 @@ static uint8_t getch(void) { * the application "soon", if it keeps happening. (Note that we * don't care that an invalid char is returned...) */ - watchdogReset(); + wdt_reset(); } ch = UDR0; return ch; @@ -117,7 +114,7 @@ uint8_t optiboot_w25x20cl_enter() // Handshake sequence: Initialize the serial line, flush serial line, send magic, receive magic. // If the magic is not received on time, or it is not received correctly, continue to the application. { - watchdogReset(); + wdt_reset(); unsigned long boot_timeout = 2000000; unsigned long boot_timer = 0; const char *ptr = entry_magic_send; @@ -125,7 +122,7 @@ uint8_t optiboot_w25x20cl_enter() const uint8_t selectedSerialPort_bak = selectedSerialPort; // Flush the serial line. while (RECV_READY) { - watchdogReset(); + wdt_reset(); // Dummy register read (discard) (void)(*(char *)UDR0); } @@ -135,14 +132,14 @@ uint8_t optiboot_w25x20cl_enter() // Send the initial magic string. while (ptr != end) putch(pgm_read_byte(ptr ++)); - watchdogReset(); + wdt_reset(); // Wait for two seconds until a magic string (constant entry_magic) is received // from the serial line. ptr = entry_magic_receive; end = strlen_P(entry_magic_receive) + ptr; while (ptr != end) { while (rx_buffer.head == SerialHead) { - watchdogReset(); + wdt_reset(); delayMicroseconds(1); if (++ boot_timer > boot_timeout) { @@ -159,7 +156,7 @@ uint8_t optiboot_w25x20cl_enter() selectedSerialPort = selectedSerialPort_bak; //revert Serial setting return 0; } - watchdogReset(); + wdt_reset(); } cbi(UCSR0B, RXCIE0); //disable the MarlinSerial0 interrupt // Send the cfm magic string. From cbe207eb59ac685ce43a76654feda5d6c3640459 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Sat, 20 Feb 2021 13:18:53 +0100 Subject: [PATCH 04/14] Fix issue #3037 `starttime` is only set for SD prints via gcode `M24 and M32` --- Firmware/ultralcd.cpp | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 422566f18..5776e93c8 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -673,8 +673,7 @@ void lcdui_print_time(void) { //if remaining print time estimation is available print it else print elapsed time int chars = 0; - if ((PRINTER_ACTIVE) && (starttime != 0)) - { + if (PRINTER_ACTIVE) { uint16_t print_t = 0; uint16_t print_tr = 0; uint16_t print_tc = 0; @@ -682,31 +681,20 @@ void lcdui_print_time(void) char suff_doubt = ' '; #ifdef TMC2130 - if (SilentModeMenu != SILENT_MODE_OFF) - { + if (SilentModeMenu != SILENT_MODE_OFF) { if (print_time_remaining_silent != PRINT_TIME_REMAINING_INIT) - { print_tr = print_time_remaining_silent; - } //#ifdef CLOCK_INTERVAL_TIME if (print_time_to_change_silent != PRINT_TIME_REMAINING_INIT) - { print_tc = print_time_to_change_silent; - } //#endif //CLOCK_INTERVAL_TIME - } - else - { + } else { #endif //TMC2130 if (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT) - { print_tr = print_time_remaining_normal; - } //#ifdef CLOCK_INTERVAL_TIME if (print_time_to_change_normal != PRINT_TIME_REMAINING_INIT) - { print_tc = print_time_to_change_normal; - } //#endif //CLOCK_INTERVAL_TIME #ifdef TMC2130 } @@ -714,30 +702,22 @@ void lcdui_print_time(void) //#ifdef CLOCK_INTERVAL_TIME if (clock_interval == CLOCK_INTERVAL_TIME*2) - { clock_interval = 0; - } + clock_interval++; - if (print_tc != 0 && clock_interval > CLOCK_INTERVAL_TIME) - { + if (print_tc != 0 && clock_interval > CLOCK_INTERVAL_TIME) { print_t = print_tc; suff = 'C'; - } - else + } else //#endif //CLOCK_INTERVAL_TIME - if (print_tr != 0) - { + if (print_tr != 0) { print_t = print_tr; suff = 'R'; - } - else - { - print_t = _millis() / 60000 - starttime / 60000; - } + } else + print_t = _millis() / 60000 - starttime / 60000; - if (feedmultiply != 100 && (print_t == print_tr || print_t == print_tc)) - { + if (feedmultiply != 100 && (print_t == print_tr || print_t == print_tc)) { suff_doubt = '?'; print_t = 100ul * print_t / feedmultiply; } From c241adec5f732a6592f3899dbd8fc5c871dec426 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 16 Jul 2019 16:17:52 +0200 Subject: [PATCH 05/14] Ensure babystep_apply|undo always uses the planner The code around these calls _requires_ that the steps are immediately processed and/or added to the subsequent planner moves. The only part that doesn't care about immediate insertion is the direct user-insertion though the lcd encoder. --- Firmware/Marlin_main.cpp | 6 ++---- Firmware/mesh_bed_calibration.cpp | 10 ---------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index d5b4ff106..fc470f604 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(); @@ -5161,8 +5160,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; } From ff4e53d2d11a614045e111f10d8fcba900c311dc Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 16 Jul 2019 17:28:28 +0200 Subject: [PATCH 06/14] Prevent babysteps in more unsafe situations through homing_flag Further restrict babystep insertion when the lcd_update is enabled by toggling homing_flag when probing Z (where Z shouldn't be touched anyway as it would disrupt the measurement) Also reset the encoder value during mesh leveling. --- Firmware/Marlin_main.cpp | 7 ++++++- Firmware/ultralcd.cpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index fc470f604..23a734d77 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4753,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(); @@ -4764,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; @@ -4854,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"); @@ -4898,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]; @@ -4948,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 diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 7f4cfa648..684ec5178 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3108,7 +3108,7 @@ static void lcd_babystep_z() if (lcd_encoder != 0) { - if (homing_flag) lcd_encoder = 0; + if (homing_flag || mesh_bed_leveling_flag) lcd_encoder = 0; _md->babystepMemZ += (int)lcd_encoder; if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm From f5e419530b9bbce689eb2aa7320d85360eb019dd Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 16 Jul 2019 21:17:37 +0200 Subject: [PATCH 07/14] Inhibit LiveZ from the settings menu during mesh bed leveling --- Firmware/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 684ec5178..25cd55d93 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5789,7 +5789,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) From 019c818c05466ea9d8ce66bbd5e1d8cc660cc650 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 2 Aug 2020 01:36:24 +0200 Subject: [PATCH 08/14] Insert babysteps using CRITICAL_SECTION instead of cli/sei --- Firmware/temperature.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 From 28e9c814fc4392a2a99a32ecd84e66b3c98f4656 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Fri, 29 Jan 2021 19:05:32 +0100 Subject: [PATCH 09/14] Remove code duplication for babystep insertion --- Firmware/temperature.h | 19 +++++-------------- Firmware/ultralcd.cpp | 7 +------ 2 files changed, 6 insertions(+), 20 deletions(-) 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 25cd55d93..d7c7a25d9 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3113,12 +3113,7 @@ static void lcd_babystep_z() 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); From 14a1a93bc84fcccf5aa7ee793f809b10c54006c5 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 24 Feb 2021 16:57:33 +0100 Subject: [PATCH 10/14] Include probing/MBL in the PRINTER_ACTIVE check This prevents to perform disruptive actions during homing or between MBL probes, which would result in a failure. --- Firmware/Marlin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From b4f5633bde4d73105bc9ad9dba746353afc81b59 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 24 Feb 2021 16:59:22 +0100 Subject: [PATCH 11/14] Enable "Move axis" and "Disable steppers" only when idle Move axis queues movements, which disrupts a normal print, homing (when XY is combined) or MBL. Likewise, "Disable steppers" only makes sense when the printer is fully idle. Only allow such actions when the printer is not active and/or in the paused state. --- Firmware/ultralcd.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index d7c7a25d9..833eddc39 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5747,10 +5747,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; From e8f6c9fac91f0ad808ef8a8ee62f5b5466f5aeab Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 24 Feb 2021 17:01:45 +0100 Subject: [PATCH 12/14] Exit the _lcd_move* menus when homing/leveling Instead of resetting the encoder status when homing or leveling, simply exit the move/liveZ menu. When transitioning from idle->printing, axis move shouldn't be allowed as it would insert moves during a print. This is always wrong. The menu must be always dismissed. Instead of checking all places where the menu could be active, automatically dimiss the menu from within _lcd_move when homing/MBL is happening. The long-push function and the settings menu checks if "axis move" is possible, and thus prevent the user to re-enter the menu already. When doing the first layer calibration, the _lcd_babystep_z is automatically brought back after MBL has completed. Technically we should do the same when entering/exiting the paused state in _lcd_move. However, it's better to dismiss _any_ menu in stop_and_save_print_to_ram/restore_print_from_ram_and_continue instead. To be done later... --- Firmware/ultralcd.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 833eddc39..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,9 +3120,8 @@ static void lcd_babystep_z() lcd_timeoutToStatus.start(); } - if (lcd_encoder != 0) + if (lcd_encoder != 0) { - if (homing_flag || mesh_bed_leveling_flag) lcd_encoder = 0; _md->babystepMemZ += (int)lcd_encoder; if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm From 3e06a17810e22623e9712e49cf37191fdb885b05 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Sun, 28 Feb 2021 18:04:07 +0100 Subject: [PATCH 13/14] Fix LCD output --- Firmware/ultralcd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index ec74bf4b5..c4a24d3de 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4984,10 +4984,10 @@ void lcd_wizard(WizState state) saved_printing = false; if( eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)==2){ - lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_WELCOME_SHIPPING); + lcd_show_fullscreen_message_and_wait_P(_T(MSG_WIZARD_WELCOME_SHIPPING)); state = S::Restore; } else { - wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(MSG_WIZARD_WELCOME, false, true); + wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_T(MSG_WIZARD_WELCOME), false, true); if (wizard_event) { state = S::Restore; eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1); From d0d42982492fbcefbea59b4ecbf69b743bb780c5 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Sun, 28 Feb 2021 18:18:06 +0100 Subject: [PATCH 14/14] Update EEPROM documentation for Service prep --- Firmware/eeprom.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 6fa80aa4c..2590d0f23 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -53,6 +53,7 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP - __L__ Language - __S__ Statistics - __P__ Shipping prep + - __M__ Service/Maintenance prep - __S/P__ Statistics and Shipping prep will overwrite existing values to 0 or default. @@ -157,6 +158,7 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP | 0x0F60h 3936 | float | EEPROM_XYZ_CAL_SKEW | ??? | ff ff ff ffh | XYZ skew value | ??? | D3 Ax0f60 C4 | 0x0F5Fh 3935 | uint8 | EEPROM_WIZARD_ACTIVE | 01h 1 | 01h 1 __P__ | Wizard __active__ | ??? | D3 Ax0f5f C1 | ^ | ^ | ^ | 00h 0 | ^ | Wizard __inactive__ | ^ | ^ +| ^ | ^ | ^ | 02h 2 | 02h 2 __M__ | Wizard active - Z cal after shipping/service prep | ^ | ^ | 0x0F5Dh 3933 | uint16 | EEPROM_BELTSTATUS_X | ??? | ff ffh | X Beltstatus | ??? | D3 Ax0f5d C2 | 0x0F5Bh 3931 | uint16 | EEPROM_BELTSTATUS_Y | ??? | ff ffh | Y Beltstatus | ??? | D3 Ax0f5b C2 | 0x0F5Ah 3930 | uint8 | EEPROM_DIR_DEPTH | 00h-ffh 0-255 | ffh 255 | Directory depth | ??? | D3 Ax0f5a C1