|
@@ -3001,6 +3001,32 @@ void gcode_M114()
|
|
|
SERIAL_PROTOCOLLN("");
|
|
|
}
|
|
|
|
|
|
+//! extracted code to compute z_shift for M600 in case of filament change operation
|
|
|
+//! requested from fsensors.
|
|
|
+//! The function ensures, that the printhead lifts to at least 25mm above the heat bed
|
|
|
+//! unlike the previous implementation, which was adding 25mm even when the head was
|
|
|
+//! printing at e.g. 24mm height.
|
|
|
+//! A safety margin of FILAMENTCHANGE_ZADD is added in all cases to avoid touching
|
|
|
+//! the printout.
|
|
|
+//! This function is templated to enable fast change of computation data type.
|
|
|
+//! @return new z_shift value
|
|
|
+template<typename T>
|
|
|
+static T gcode_M600_filament_change_z_shift()
|
|
|
+{
|
|
|
+#ifdef FILAMENTCHANGE_ZADD
|
|
|
+ static_assert(Z_MAX_POS < (255 - FILAMENTCHANGE_ZADD), "Z-range too high, change the T type from uint8_t to uint16_t");
|
|
|
+ // avoid floating point arithmetics when not necessary - results in shorter code
|
|
|
+ T ztmp = T( current_position[Z_AXIS] );
|
|
|
+ T z_shift = 0;
|
|
|
+ if(ztmp < T(25)){
|
|
|
+ z_shift = T(25) - ztmp; // make sure to be at least 25mm above the heat bed
|
|
|
+ }
|
|
|
+ return z_shift + T(FILAMENTCHANGE_ZADD); // always move above printout
|
|
|
+#else
|
|
|
+ return T(0);
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
static void gcode_M600(bool automatic, float x_position, float y_position, float z_shift, float e_shift, float /*e_shift_late*/)
|
|
|
{
|
|
|
st_synchronize();
|
|
@@ -3390,8 +3416,10 @@ void process_commands()
|
|
|
{
|
|
|
#ifdef FANCHECK
|
|
|
if (fan_check_error){
|
|
|
- fan_check_error = false;
|
|
|
- lcd_pause_print();
|
|
|
+ if( fan_check_error == EFCE_DETECTED ){
|
|
|
+ fan_check_error = EFCE_REPORTED;
|
|
|
+ lcd_pause_print();
|
|
|
+ } // otherwise it has already been reported, so just ignore further processing
|
|
|
return;
|
|
|
}
|
|
|
#endif
|
|
@@ -3552,10 +3580,6 @@ void process_commands()
|
|
|
enquecommand_P(PSTR("M24"));
|
|
|
}
|
|
|
#ifdef FILAMENT_SENSOR
|
|
|
- else if (code_seen("fsensor_recover_IR")) //! PRUSA fsensor_recover_IR
|
|
|
- {
|
|
|
- fsensor_restore_print_and_continue_IR();
|
|
|
- }
|
|
|
else if (code_seen("fsensor_recover")) //! PRUSA fsensor_recover
|
|
|
{
|
|
|
fsensor_restore_print_and_continue();
|
|
@@ -6590,7 +6614,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
|
|
|
|
|
|
float x_position = current_position[X_AXIS];
|
|
|
float y_position = current_position[Y_AXIS];
|
|
|
- float z_shift = 0;
|
|
|
+ float z_shift = 0; // is it necessary to be a float?
|
|
|
float e_shift_init = 0;
|
|
|
float e_shift_late = 0;
|
|
|
bool automatic = false;
|
|
@@ -6626,10 +6650,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- #ifdef FILAMENTCHANGE_ZADD
|
|
|
- z_shift= FILAMENTCHANGE_ZADD ;
|
|
|
- if(current_position[Z_AXIS] < 25) z_shift+= 25 ;
|
|
|
- #endif
|
|
|
+ z_shift = gcode_M600_filament_change_z_shift<uint8_t>();
|
|
|
}
|
|
|
//Move XY to side
|
|
|
if(code_seen('X'))
|
|
@@ -9307,22 +9328,20 @@ void stop_and_save_print_to_ram(float z_move, float e_move)
|
|
|
|
|
|
// First unretract (relative extrusion)
|
|
|
if(!saved_extruder_relative_mode){
|
|
|
- strcpy_P(buf, PSTR("M83"));
|
|
|
- enquecommand(buf, false);
|
|
|
+ enquecommand(PSTR("M83"), true);
|
|
|
}
|
|
|
|
|
|
//retract 45mm/s
|
|
|
- strcpy_P(buf, PSTR("G1 E"));
|
|
|
- dtostrf(e_move, 6, 3, buf + strlen(buf));
|
|
|
- strcat_P(buf, PSTR(" F"));
|
|
|
- dtostrf(2700, 8, 3, buf + strlen(buf));
|
|
|
+ // A single sprintf may not be faster, but is definitely 20B shorter
|
|
|
+ // than a sequence of commands building the string piece by piece
|
|
|
+ // A snprintf would have been a safer call, but since it is not used
|
|
|
+ // in the whole program, its implementation would bring more bytes to the total size
|
|
|
+ // The behavior of dtostrf 8,3 should be roughly the same as %-0.3
|
|
|
+ sprintf_P(buf, PSTR("G1 E%-0.3f F2700"), e_move);
|
|
|
enquecommand(buf, false);
|
|
|
|
|
|
// Then lift Z axis
|
|
|
- strcpy_P(buf, PSTR("G1 Z"));
|
|
|
- dtostrf(saved_pos[Z_AXIS] + z_move, 8, 3, buf + strlen(buf));
|
|
|
- strcat_P(buf, PSTR(" F"));
|
|
|
- dtostrf(homing_feedrate[Z_AXIS], 8, 3, buf + strlen(buf));
|
|
|
+ sprintf_P(buf, PSTR("G1 Z%-0.3f F%-0.3f"), saved_pos[Z_AXIS] + z_move, homing_feedrate[Z_AXIS]);
|
|
|
// At this point the command queue is empty.
|
|
|
enquecommand(buf, false);
|
|
|
// If this call is invoked from the main Arduino loop() function, let the caller know that the command
|
|
@@ -9348,6 +9367,12 @@ void stop_and_save_print_to_ram(float z_move, float e_move)
|
|
|
void restore_print_from_ram_and_continue(float e_move)
|
|
|
{
|
|
|
if (!saved_printing) return;
|
|
|
+
|
|
|
+#ifdef FANCHECK
|
|
|
+ // Do not allow resume printing if fans are still not ok
|
|
|
+ if( fan_check_error != EFCE_OK )return;
|
|
|
+#endif
|
|
|
+
|
|
|
// for (int axis = X_AXIS; axis <= E_AXIS; axis++)
|
|
|
// current_position[axis] = st_get_position_mm(axis);
|
|
|
active_extruder = saved_active_extruder; //restore active_extruder
|