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..069eb5bbc 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2436,38 +2436,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() { @@ -2722,8 +2728,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(); @@ -4383,21 +4388,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(); } @@ -4465,9 +4471,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` @@ -4480,7 +4486,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) retract(true); #endif break; - + /*! ### G11 - Retract recover G11: Unretract @@ -4493,8 +4499,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) retract(false); #endif break; - #endif //FWRETRACT - +#endif //FWRETRACT + /*! ### G21 - Sets Units to Millimters G21: Set Units to Millimeters @@ -4754,6 +4760,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 +4772,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 +4863,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 +4909,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 +4960,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 +5172,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 @@ -7314,8 +7324,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 @@ -7413,7 +7424,9 @@ Sigma_Exit: } }break; - #endif // FWRETRACT +#endif // FWRETRACT + + #if EXTRUDERS > 1 /*! 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 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/optiboot_w25x20cl.cpp b/Firmware/optiboot_w25x20cl.cpp index dce4074e1..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 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. 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 32a6b624e..63f6181b5 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; } @@ -2850,6 +2830,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 +3058,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 +3100,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); @@ -5023,10 +5011,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); @@ -5779,10 +5767,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; @@ -5816,7 +5806,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)