@ -211,72 +211,37 @@ bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					int  feedmultiply  =  100 ;  //100->1 200->2
 
 
					 
					 
					 
					int  feedmultiply  =  100 ;  //100->1 200->2
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					int  saved_feedmultiply ; 
 
					 
					 
					 
					int  saved_feedmultiply ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					int  extrudemultiply  =  100 ;  //100->1 200->2
 
 
					 
					 
					 
					int  extrudemultiply  =  100 ;  //100->1 200->2
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					int  extruder_multiply [ EXTRUDERS ]  =  {  100 
 
					 
					 
					 
					int  extruder_multiply [ EXTRUDERS ]  =  ARRAY_BY_EXTRUDERS ( 100 ,  100 ,  100 ,  100 ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  # if EXTRUDERS > 1 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    ,  100 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # if EXTRUDERS > 2 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      ,  100 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # if EXTRUDERS > 3 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        ,  100 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					bool  volumetric_enabled  =  false ; 
 
					 
					 
					 
					bool  volumetric_enabled  =  false ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					float  filament_size [ EXTRUDERS ]  =  {  DEFAULT_NOMINAL_FILAMENT_DIA 
 
					 
					 
					 
					float  filament_size [ EXTRUDERS ]  =  ARRAY_BY_EXTRUDERS ( DEFAULT_NOMINAL_FILAMENT_DIA ,  DEFAULT_NOMINAL_FILAMENT_DIA ,  DEFAULT_NOMINAL_FILAMENT_DIA ,  DEFAULT_NOMINAL_FILAMENT_DIA ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  # if EXTRUDERS > 1 
 
					 
					 
					 
					float  volumetric_multiplier [ EXTRUDERS ]  =  ARRAY_BY_EXTRUDERS ( 1.0 ,  1.0 ,  1.0 ,  1.0 ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      ,  DEFAULT_NOMINAL_FILAMENT_DIA 
 
					 
					 
					 
					float  current_position [ NUM_AXIS ]  =  {  0.0  } ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    # if EXTRUDERS > 2 
 
					 
					 
					 
					float  home_offset [ 3 ]  =  {  0  } ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					       ,  DEFAULT_NOMINAL_FILAMENT_DIA 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # if EXTRUDERS > 3 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        ,  DEFAULT_NOMINAL_FILAMENT_DIA 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					float  volumetric_multiplier [ EXTRUDERS ]  =  { 1.0 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # if EXTRUDERS > 1 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    ,  1.0 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # if EXTRUDERS > 2 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      ,  1.0 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # if EXTRUDERS > 3 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        ,  1.0 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					float  current_position [ NUM_AXIS ]  =  {  0.0 ,  0.0 ,  0.0 ,  0.0  } ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					float  home_offset [ 3 ]  =  {  0 ,  0 ,  0  } ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					# ifdef DELTA 
 
					 
					 
					 
					# ifdef DELTA 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  float  endstop_adj [ 3 ]  =  {  0 ,  0 ,  0   } ; 
 
					 
					 
					 
					  float  endstop_adj [ 3 ]  =  {  0  } ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					# elif defined(Z_DUAL_ENDSTOPS) 
 
					 
					 
					 
					# elif defined(Z_DUAL_ENDSTOPS) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  float  z_endstop_adj  =  0 ; 
 
					 
					 
					 
					  float  z_endstop_adj  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# endif 
 
					 
					 
					 
					# endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					float  min_pos [ 3 ]  =  {  X_MIN_POS ,  Y_MIN_POS ,  Z_MIN_POS  } ; 
 
					 
					 
					 
					float  min_pos [ 3 ]  =  {  X_MIN_POS ,  Y_MIN_POS ,  Z_MIN_POS  } ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					float  max_pos [ 3 ]  =  {  X_MAX_POS ,  Y_MAX_POS ,  Z_MAX_POS  } ; 
 
					 
					 
					 
					float  max_pos [ 3 ]  =  {  X_MAX_POS ,  Y_MAX_POS ,  Z_MAX_POS  } ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					bool  axis_known_position [ 3 ]  =  {  false ,  false ,  false   } ; 
 
					 
					 
					 
					bool  axis_known_position [ 3 ]  =  {  false  } ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					// Extruder offset
 
 
					 
					 
					 
					// Extruder offset
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# if EXTRUDERS > 1 
 
					 
					 
					 
					# if EXTRUDERS > 1 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# ifndef DUAL_X_CARRIAGE 
 
					 
					 
					 
					  # ifndef EXTRUDER_OFFSET_X 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  # define NUM_EXTRUDER_OFFSETS 2  // only in XY plane
 
 
					 
					 
					 
					    # define EXTRUDER_OFFSET_X 0 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					# else 
 
					 
					 
					 
					  # endif 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  # define NUM_EXTRUDER_OFFSETS 3  // supports offsets in XYZ plane
 
 
					 
					 
					 
					  # ifndef EXTRUDER_OFFSET_Y 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					# endif 
 
					 
					 
					 
					    # define EXTRUDER_OFFSET_Y 0 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					float  extruder_offset [ NUM_EXTRUDER_OFFSETS ] [ EXTRUDERS ]  =  { 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # if defined(EXTRUDER_OFFSET_X) 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    EXTRUDER_OFFSET_X 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # else 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    0 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					  # endif 
 
					 
					 
					 
					  # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  , 
 
					 
					 
					 
					  # ifndef DUAL_X_CARRIAGE 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  # if defined(EXTRUDER_OFFSET_Y) 
 
					 
					 
					 
					    # define NUM_EXTRUDER_OFFSETS 2  // only in XY plane
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    EXTRUDER_OFFSET_Y 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					  # else 
 
					 
					 
					 
					  # else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    0 
 
					 
					 
					 
					    # define NUM_EXTRUDER_OFFSETS 3  // supports offsets in XYZ plane
 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					  # endif 
 
					 
					 
					 
					  # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} ; 
 
					 
					 
					 
					  # define _EXY { EXTRUDER_OFFSET_X, EXTRUDER_OFFSET_Y } 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  float  extruder_offset [ EXTRUDERS ] [ NUM_EXTRUDER_OFFSETS ]  =  ARRAY_BY_EXTRUDERS ( _EXY ,  _EXY ,  _EXY ,  _EXY ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# endif 
 
					 
					 
					 
					# endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					uint8_t  active_extruder  =  0 ; 
 
					 
					 
					 
					uint8_t  active_extruder  =  0 ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -295,28 +260,8 @@ int fanSpeed = 0;
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# ifdef FWRETRACT 
 
					 
					 
					 
					# ifdef FWRETRACT 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  bool  autoretract_enabled  =  false ; 
 
					 
					 
					 
					  bool  autoretract_enabled  =  false ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  bool  retracted [ EXTRUDERS ]  =  {  false 
 
					 
					 
					 
					  bool  retracted [ EXTRUDERS ]  =  {  false  } ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    # if EXTRUDERS > 1 
 
					 
					 
					 
					  bool  retracted_swap [ EXTRUDERS ]  =  {  false  } ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      ,  false 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # if EXTRUDERS > 2 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        ,  false 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # if EXTRUDERS > 3 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          ,  false 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  } ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  bool  retracted_swap [ EXTRUDERS ]  =  {  false 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # if EXTRUDERS > 1 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      ,  false 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # if EXTRUDERS > 2 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        ,  false 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # if EXTRUDERS > 3 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          ,  false 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # endif 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  } ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  float  retract_length  =  RETRACT_LENGTH ; 
 
					 
					 
					 
					  float  retract_length  =  RETRACT_LENGTH ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  float  retract_length_swap  =  RETRACT_LENGTH_SWAP ; 
 
					 
					 
					 
					  float  retract_length_swap  =  RETRACT_LENGTH_SWAP ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -385,10 +330,14 @@ const char errormagic[] PROGMEM = "Error:";
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					const  char  echomagic [ ]  PROGMEM  =  " echo: " ; 
 
					 
					 
					 
					const  char  echomagic [ ]  PROGMEM  =  " echo: " ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					const  char  axis_codes [ NUM_AXIS ]  =  { ' X ' ,  ' Y ' ,  ' Z ' ,  ' E ' } ; 
 
					 
					 
					 
					const  char  axis_codes [ NUM_AXIS ]  =  { ' X ' ,  ' Y ' ,  ' Z ' ,  ' E ' } ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  float  destination [ NUM_AXIS ]  =  {  0 ,  0 ,  0 ,  0  } ; 
 
					 
					 
					 
					static  float  destination [ NUM_AXIS ]  =  {  0  } ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					static  float  offset [ 3 ]  =  {  0  } ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					# ifndef DELTA 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  static  bool  home_all_axis  =  true ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					# endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  float  offset [ 3 ]  =  {  0 ,  0 ,  0  } ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  bool  home_all_axis  =  true ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  float  feedrate  =  1500.0 ,  next_feedrate ,  saved_feedrate ; 
 
					 
					 
					 
					static  float  feedrate  =  1500.0 ,  next_feedrate ,  saved_feedrate ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  long  gcode_N ,  gcode_LastN ,  Stopped_gcode_LastN  =  0 ; 
 
					 
					 
					 
					static  long  gcode_N ,  gcode_LastN ,  Stopped_gcode_LastN  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -396,8 +345,8 @@ static bool relative_mode = false;  //Determines Absolute or Relative Coordinate
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  char  cmdbuffer [ BUFSIZE ] [ MAX_CMD_SIZE ] ; 
 
					 
					 
					 
					static  char  cmdbuffer [ BUFSIZE ] [ MAX_CMD_SIZE ] ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# ifdef SDSUPPORT 
 
					 
					 
					 
					# ifdef SDSUPPORT 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  bool  fromsd [ BUFSIZE ] ; 
 
					 
					 
					 
					   static  bool  fromsd [ BUFSIZE ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					# endif  //!SDSUPPORT
  
 
					 
					 
					 
					# endif 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					static  int  bufindr  =  0 ; 
 
					 
					 
					 
					static  int  bufindr  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  int  bufindw  =  0 ; 
 
					 
					 
					 
					static  int  bufindw  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  int  buflen  =  0 ; 
 
					 
					 
					 
					static  int  buflen  =  0 ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -933,24 +882,22 @@ void get_command()
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					float  code_value ( )  { 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					float  code_value ( ) 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					{ 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					  float  ret ; 
 
					 
					 
					 
					  float  ret ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  char  * e  =  strchr ( strchr_pointer ,  ' E ' ) ; 
 
					 
					 
					 
					  char  * e  =  strchr ( strchr_pointer ,  ' E ' ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  if  ( e  ! =  NULL )  * e  =  0 ; 
 
					 
					 
					 
					  if  ( e )  { 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  ret  =  strtod ( strchr_pointer + 1 ,  NULL ) ; 
 
					 
					 
					 
					    * e  =  0 ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  if  ( e  ! =  NULL )  * e  =  ' E ' ; 
 
					 
					 
					 
					    ret  =  strtod ( strchr_pointer + 1 ,  NULL ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    * e  =  ' E ' ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    ret  =  strtod ( strchr_pointer + 1 ,  NULL ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  return  ret ; 
 
					 
					 
					 
					  return  ret ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					long  code_value_long ( ) 
 
					 
					 
					 
					long  code_value_long ( )  {  return  ( strtol ( strchr_pointer  +  1 ,  NULL ,  10 ) ) ;  } 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					{ 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  return  ( strtol ( strchr_pointer  +  1 ,  NULL ,  10 ) ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					bool  code_seen ( char  code ) 
 
					 
					 
					 
					bool  code_seen ( char  code )  { 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					{ 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					  strchr_pointer  =  strchr ( cmdbuffer [ bufindr ] ,  code ) ; 
 
					 
					 
					 
					  strchr_pointer  =  strchr ( cmdbuffer [ bufindr ] ,  code ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  return  ( strchr_pointer  ! =  NULL ) ;   //Return True if a character was found
 
 
					 
					 
					 
					  return  ( strchr_pointer  ! =  NULL ) ;   //Return True if a character was found
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					} 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -991,7 +938,7 @@ XYZ_CONSTS_FROM_CONFIG(signed char, home_dir,  HOME_DIR);
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      // second X-carriage offset when homed - otherwise X2_HOME_POS is used.
 
 
					 
					 
					 
					      // second X-carriage offset when homed - otherwise X2_HOME_POS is used.
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      // This allow soft recalibration of the second extruder offset position without firmware reflash
 
 
					 
					 
					 
					      // This allow soft recalibration of the second extruder offset position without firmware reflash
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      // (through the M218 command).
 
 
					 
					 
					 
					      // (through the M218 command).
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      return  ( extruder_offset [ X_AXIS ] [ 1 ]  >  0 )  ?  extruder_offset [ X_AXIS ] [ 1 ]  :  X2_HOME_POS ; 
 
					 
					 
					 
					      return  ( extruder_offset [ 1 ] [ X_AXIS ]  >  0 )  ?  extruder_offset [ 1 ] [ X_AXIS ]  :  X2_HOME_POS ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					  } 
 
					 
					 
					 
					  } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  static  int  x_home_dir ( int  extruder )  { 
 
					 
					 
					 
					  static  int  x_home_dir ( int  extruder )  { 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1009,84 +956,84 @@ XYZ_CONSTS_FROM_CONFIG(signed char, home_dir,  HOME_DIR);
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# endif  //DUAL_X_CARRIAGE
 
 
					 
					 
					 
					# endif  //DUAL_X_CARRIAGE
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  void  axis_is_at_home ( int  axis )  { 
 
					 
					 
					 
					static  void  axis_is_at_home ( int  axis )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# ifdef DUAL_X_CARRIAGE 
 
					 
					 
					 
					
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  if  ( axis  = =  X_AXIS )  { 
 
					 
					 
					 
					  # ifdef DUAL_X_CARRIAGE 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( active_extruder  ! =  0 )  { 
 
					 
					 
					 
					    if  ( axis  = =  X_AXIS )  { 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      current_position [ X_AXIS ]  =  x_home_pos ( active_extruder ) ; 
 
					 
					 
					 
					      if  ( active_extruder  ! =  0 )  { 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      min_pos [ X_AXIS ]  =           X2_MIN_POS ; 
 
					 
					 
					 
					        current_position [ X_AXIS ]  =  x_home_pos ( active_extruder ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      max_pos [ X_AXIS ]  =           max ( extruder_offset [ X_AXIS ] [ 1 ] ,  X2_MAX_POS ) ; 
 
					 
					 
					 
					        min_pos [ X_AXIS ]  =  X2_MIN_POS ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      return ; 
 
					 
					 
					 
					        max_pos [ X_AXIS ]  =  max ( extruder_offset [ 1 ] [ X_AXIS ] ,  X2_MAX_POS ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					        return ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    else  if  ( dual_x_carriage_mode  = =  DXC_DUPLICATION_MODE  & &  active_extruder  = =  0 )  { 
 
					 
					 
					 
					      } 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      current_position [ X_AXIS ]  =  base_home_pos ( X_AXIS )  +  home_offset [ X_AXIS ] ; 
 
					 
					 
					 
					      else  if  ( dual_x_carriage_mode  = =  DXC_DUPLICATION_MODE )  { 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      min_pos [ X_AXIS ]  =           base_min_pos ( X_AXIS )  +  home_offset [ X_AXIS ] ; 
 
					 
					 
					 
					        current_position [ X_AXIS ]  =  base_home_pos ( X_AXIS )  +  home_offset [ X_AXIS ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      max_pos [ X_AXIS ]  =           min ( base_max_pos ( X_AXIS )  +  home_offset [ X_AXIS ] , 
 
					 
					 
					 
					        min_pos [ X_AXIS ]  =  base_min_pos ( X_AXIS )  +  home_offset [ X_AXIS ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					                                  max ( extruder_offset [ X_AXIS ] [ 1 ] ,  X2_MAX_POS )  -  duplicate_extruder_x_offset ) ; 
 
					 
					 
					 
					        max_pos [ X_AXIS ]  =  min ( base_max_pos ( X_AXIS )  +  home_offset [ X_AXIS ] , 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      return ; 
 
					 
					 
					 
					                                max ( extruder_offset [ 1 ] [ X_AXIS ] ,  X2_MAX_POS )  -  duplicate_extruder_x_offset ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        return ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  } 
 
					 
					 
					 
					  # endif 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					# endif 
 
					 
					 
					 
					
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					# ifdef SCARA 
 
					 
					 
					 
					  # ifdef SCARA 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					   float  homeposition [ 3 ] ; 
 
					 
					 
					 
					    float  homeposition [ 3 ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					   char  i ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   if  ( axis  <  2 ) 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   { 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					   
 
					 
					 
					 
					   
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     for  ( i = 0 ;  i < 3 ;  i + + )  
 
					 
					 
					 
					    if  ( axis  <  2 )  { 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					     {  
 
					 
					 
					 
					
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        homeposition [ i ]  =  base_home_pos ( i ) ;   
 
					 
					 
					 
					      for  ( int  i  =  0 ;  i  <  3 ;  i + + )  homeposition [ i ]  =  base_home_pos ( i ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					     }    
 
					 
					 
					 
					
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  // SERIAL_ECHOPGM("homeposition[x]= "); SERIAL_ECHO(homeposition[0]);
 
 
					 
					 
					 
					       // SERIAL_ECHOPGM("homeposition[x]= "); SERIAL_ECHO(homeposition[0]);
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					   //    SERIAL_ECHOPGM("homeposition[y]= "); SERIAL_ECHOLN(homeposition[1]);
 
					 
					 
					 
					       //  SERIAL_ECHOPGM("homeposition[y]= "); SERIAL_ECHOLN(homeposition[1]);
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					   // Works out real Homeposition angles using inverse kinematics, 
 
 
					 
					 
					 
					       // Works out real Homeposition angles using inverse kinematics, 
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					   // and calculates homing offset using forward kinematics
 
 
					 
					 
					 
					       // and calculates homing offset using forward kinematics
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					     calculate_delta ( homeposition ) ; 
 
					 
					 
					 
					       calculate_delta ( homeposition ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					     
 
					 
					 
					 
					     
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    // SERIAL_ECHOPGM("base Theta= "); SERIAL_ECHO(delta[X_AXIS]);
 
 
					 
					 
					 
					       // SERIAL_ECHOPGM("base Theta= "); SERIAL_ECHO(delta[X_AXIS]);
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    // SERIAL_ECHOPGM(" base Psi+Theta="); SERIAL_ECHOLN(delta[Y_AXIS]);
 
 
					 
					 
					 
					       // SERIAL_ECHOPGM(" base Psi+Theta="); SERIAL_ECHOLN(delta[Y_AXIS]);
 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					     
 
					 
					 
					 
					     
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     for  ( i = 0 ;  i < 2 ;  i + + ) 
 
					 
					 
					 
					      for  ( int  i  =  0 ;  i  <  2 ;  i + + )  delta [ i ]  - =  home_offset [ i ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					     { 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        delta [ i ]  - =  home_offset [ i ] ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     }  
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					     
 
					 
					 
					 
					     
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    // SERIAL_ECHOPGM("addhome X="); SERIAL_ECHO(home_offset[X_AXIS]);
 
 
					 
					 
					 
					      // SERIAL_ECHOPGM("addhome X="); SERIAL_ECHO(home_offset[X_AXIS]);
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  // SERIAL_ECHOPGM(" addhome Y="); SERIAL_ECHO(home_offset[Y_AXIS]);
 
 
					 
					 
					 
					      // SERIAL_ECHOPGM(" addhome Y="); SERIAL_ECHO(home_offset[Y_AXIS]);
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    // SERIAL_ECHOPGM(" addhome Theta="); SERIAL_ECHO(delta[X_AXIS]);
 
 
					 
					 
					 
					       // SERIAL_ECHOPGM(" addhome Theta="); SERIAL_ECHO(delta[X_AXIS]);
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    // SERIAL_ECHOPGM(" addhome Psi+Theta="); SERIAL_ECHOLN(delta[Y_AXIS]);
 
 
					 
					 
					 
					       // SERIAL_ECHOPGM(" addhome Psi+Theta="); SERIAL_ECHOLN(delta[Y_AXIS]);
 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      
 
					 
					 
					 
					      
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     calculate_SCARA_forward_Transform ( delta ) ; 
 
					 
					 
					 
					       calculate_SCARA_forward_Transform ( delta ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					     
 
					 
					 
					 
					     
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    // SERIAL_ECHOPGM("Delta X="); SERIAL_ECHO(delta[X_AXIS]);
 
 
					 
					 
					 
					       // SERIAL_ECHOPGM("Delta X="); SERIAL_ECHO(delta[X_AXIS]);
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    // SERIAL_ECHOPGM(" Delta Y="); SERIAL_ECHOLN(delta[Y_AXIS]);
 
 
					 
					 
					 
					       // SERIAL_ECHOPGM(" Delta Y="); SERIAL_ECHOLN(delta[Y_AXIS]);
 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					     
 
					 
					 
					 
					     
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    current_position [ axis ]  =  delta [ axis ] ; 
 
					 
					 
					 
					       current_position [ axis ]  =  delta [ axis ] ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    
 
					 
					 
					 
					    
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    // SCARA home positions are based on configuration since the actual limits are determined by the 
 
 
					 
					 
					 
					      // SCARA home positions are based on configuration since the actual limits are determined by the 
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    // inverse kinematic transform.
 
 
					 
					 
					 
					      // inverse kinematic transform.
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    min_pos [ axis ]  =           base_min_pos ( axis ) ;  // + (delta[axis] - base_home_pos(axis));
 
 
					 
					 
					 
					      min_pos [ axis ]  =  base_min_pos ( axis ) ;  // + (delta[axis] - base_home_pos(axis));
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    max_pos [ axis ]  =           base_max_pos ( axis ) ;  // + (delta[axis] - base_home_pos(axis));
 
 
					 
					 
					 
					      max_pos [ axis ]  =  base_max_pos ( axis ) ;  // + (delta[axis] - base_home_pos(axis));
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					   }  
 
					 
					 
					 
					    }  
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					   else 
 
					 
					 
					 
					    else  { 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					   { 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      current_position [ axis ]  =  base_home_pos ( axis )  +  home_offset [ axis ] ; 
 
					 
					 
					 
					      current_position [ axis ]  =  base_home_pos ( axis )  +  home_offset [ axis ] ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      min_pos [ axis ]  =           base_min_pos ( axis )  +  home_offset [ axis ] ; 
 
					 
					 
					 
					      min_pos [ axis ]  =  base_min_pos ( axis )  +  home_offset [ axis ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      max_pos [ axis ]  =           base_max_pos ( axis )  +  home_offset [ axis ] ; 
 
					 
					 
					 
					      max_pos [ axis ]  =  base_max_pos ( axis )  +  home_offset [ axis ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					   } 
 
					 
					 
					 
					    } 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					# else 
 
					 
					 
					 
					  # else 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  current_position [ axis ]  =  base_home_pos ( axis )  +  home_offset [ axis ] ; 
 
					 
					 
					 
					    current_position [ axis ]  =  base_home_pos ( axis )  +  home_offset [ axis ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  min_pos [ axis ]  =           base_min_pos ( axis )  +  home_offset [ axis ] ; 
 
					 
					 
					 
					    min_pos [ axis ]  =  base_min_pos ( axis )  +  home_offset [ axis ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  max_pos [ axis ]  =           base_max_pos ( axis )  +  home_offset [ axis ] ; 
 
					 
					 
					 
					    max_pos [ axis ]  =  base_max_pos ( axis )  +  home_offset [ axis ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					# endif 
 
					 
					 
					 
					  # endif 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					/**
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *  Shorthand  to  tell  the  planner  our  current  position  ( in  mm ) . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					inline  void  sync_plan_position ( )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  plan_set_position ( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ] ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# ifdef ENABLE_AUTO_BED_LEVELING 
 
					 
					 
					 
					# ifdef ENABLE_AUTO_BED_LEVELING 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# ifdef AUTO_BED_LEVELING_GRID 
 
					 
					 
					 
					# ifdef AUTO_BED_LEVELING_GRID 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# ifndef DELTA 
 
					 
					 
					 
					# ifndef DELTA 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  void  set_bed_level_equation_lsq ( double  * plane_equation_coefficients ) 
 
					 
					 
					 
					  static  void  set_bed_level_equation_lsq ( double  * plane_equation_coefficients )  { 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					{ 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    vector_3  planeNormal  =  vector_3 ( - plane_equation_coefficients [ 0 ] ,  - plane_equation_coefficients [ 1 ] ,  1 ) ; 
 
					 
					 
					 
					    vector_3  planeNormal  =  vector_3 ( - plane_equation_coefficients [ 0 ] ,  - plane_equation_coefficients [ 1 ] ,  1 ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    planeNormal . debug ( " planeNormal " ) ; 
 
					 
					 
					 
					    planeNormal . debug ( " planeNormal " ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    plan_bed_level_matrix  =  matrix_3x3 : : create_look_at ( planeNormal ) ; 
 
					 
					 
					 
					    plan_bed_level_matrix  =  matrix_3x3 : : create_look_at ( planeNormal ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1097,13 +1044,13 @@ static void set_bed_level_equation_lsq(double *plane_equation_coefficients)
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    //uncorrected_position.debug("position before");
 
 
					 
					 
					 
					    //uncorrected_position.debug("position before");
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    vector_3  corrected_position  =  plan_get_position ( ) ; 
 
					 
					 
					 
					    vector_3  corrected_position  =  plan_get_position ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					//      corrected_position.debug("position after");
 
					 
					 
					 
					    //  corrected_position.debug("position after");
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    current_position [ X_AXIS ]  =  corrected_position . x ; 
 
					 
					 
					 
					    current_position [ X_AXIS ]  =  corrected_position . x ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    current_position [ Y_AXIS ]  =  corrected_position . y ; 
 
					 
					 
					 
					    current_position [ Y_AXIS ]  =  corrected_position . y ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    current_position [ Z_AXIS ]  =  corrected_position. z ;  
 
					 
					 
					 
					    current_position [ Z_AXIS ]  =  zprobe_zoffset;  // was: corrected_position.z
  
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					    sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					   } 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					# endif 
 
					 
					 
					 
					# endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# else  // not AUTO_BED_LEVELING_GRID
 
 
					 
					 
					 
					# else  // not AUTO_BED_LEVELING_GRID
 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1128,9 +1075,9 @@ static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    vector_3  corrected_position  =  plan_get_position ( ) ; 
 
					 
					 
					 
					    vector_3  corrected_position  =  plan_get_position ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    current_position [ X_AXIS ]  =  corrected_position . x ; 
 
					 
					 
					 
					    current_position [ X_AXIS ]  =  corrected_position . x ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    current_position [ Y_AXIS ]  =  corrected_position . y ; 
 
					 
					 
					 
					    current_position [ Y_AXIS ]  =  corrected_position . y ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    current_position [ Z_AXIS ]  =  corrected_position. z ;  
 
					 
					 
					 
					    current_position [ Z_AXIS ]  =  zprobe_zoffset;  // was: corrected_position.z
  
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					    sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# endif  // AUTO_BED_LEVELING_GRID
 
 
					 
					 
					 
					# endif  // AUTO_BED_LEVELING_GRID
 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -1176,18 +1123,14 @@ static void run_z_probe() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    endstops_hit_on_purpose ( ) ; 
 
					 
					 
					 
					    endstops_hit_on_purpose ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    // move back down slowly to find bed
 
 
					 
					 
					 
					    // move back down slowly to find bed
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    
 
					 
					 
					 
					    if  ( homing_bump_divisor [ Z_AXIS ]  > =  1 )  { 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( homing_bump_divisor [ Z_AXIS ]  > =  1 ) 
 
					 
					 
					 
					      feedrate  =  homing_feedrate [ Z_AXIS ] / homing_bump_divisor [ Z_AXIS ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    { 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        feedrate  =  homing_feedrate [ Z_AXIS ] / homing_bump_divisor [ Z_AXIS ] ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    }  
 
					 
					 
					 
					    }  
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    else 
 
					 
					 
					 
					    else  { 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    { 
 
					 
					 
					 
					      feedrate  =  homing_feedrate [ Z_AXIS ] / 10 ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        feedrate  =  homing_feedrate [ Z_AXIS ] / 10 ; 
 
					 
					 
					 
					      SERIAL_ECHOLN ( " Warning: The Homing Bump Feedrate Divisor cannot be less then 1 " ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHOLN ( " Warning: The Homing Bump Feedrate Divisor cannot be less then 1 " ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    zPosition  - =  home_retract_mm ( Z_AXIS )  *  2 ; 
 
					 
					 
					 
					    zPosition  - =  home_retract_mm ( Z_AXIS )  *  2 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    plan_buffer_line ( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  zPosition ,  current_position [ E_AXIS ] ,  feedrate / 60 ,  active_extruder ) ; 
 
					 
					 
					 
					    plan_buffer_line ( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  zPosition ,  current_position [ E_AXIS ] ,  feedrate / 60 ,  active_extruder ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    st_synchronize ( ) ; 
 
					 
					 
					 
					    st_synchronize ( ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1195,7 +1138,7 @@ static void run_z_probe() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    current_position [ Z_AXIS ]  =  st_get_position_mm ( Z_AXIS ) ; 
 
					 
					 
					 
					    current_position [ Z_AXIS ]  =  st_get_position_mm ( Z_AXIS ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    // make sure the planner knows where we are as it may be a bit different than we last said to move to
 
 
					 
					 
					 
					    // make sure the planner knows where we are as it may be a bit different than we last said to move to
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					    sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    
 
					 
					 
					 
					    
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # endif 
 
					 
					 
					 
					  # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					} 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -1233,10 +1176,6 @@ static void do_blocking_move_to(float x, float y, float z) {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    feedrate  =  oldFeedRate ; 
 
					 
					 
					 
					    feedrate  =  oldFeedRate ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  void  do_blocking_move_relative ( float  offset_x ,  float  offset_y ,  float  offset_z )  { 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    do_blocking_move_to ( current_position [ X_AXIS ]  +  offset_x ,  current_position [ Y_AXIS ]  +  offset_y ,  current_position [ Z_AXIS ]  +  offset_z ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					static  void  setup_for_endstop_move ( )  { 
 
					 
					 
					 
					static  void  setup_for_endstop_move ( )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    saved_feedrate  =  feedrate ; 
 
					 
					 
					 
					    saved_feedrate  =  feedrate ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    saved_feedmultiply  =  feedmultiply ; 
 
					 
					 
					 
					    saved_feedmultiply  =  feedmultiply ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -1489,7 +1428,7 @@ static void homeaxis(int axis) {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# endif 
 
					 
					 
					 
					# endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    current_position [ axis ]  =  0 ; 
 
					 
					 
					 
					    current_position [ axis ]  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					    sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# ifndef Z_PROBE_SLED 
 
					 
					 
					 
					# ifndef Z_PROBE_SLED 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1515,7 +1454,7 @@ static void homeaxis(int axis) {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    st_synchronize ( ) ; 
 
					 
					 
					 
					    st_synchronize ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    current_position [ axis ]  =  0 ; 
 
					 
					 
					 
					    current_position [ axis ]  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					    sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    destination [ axis ]  =  - home_retract_mm ( axis )  *  axis_home_dir ; 
 
					 
					 
					 
					    destination [ axis ]  =  - home_retract_mm ( axis )  *  axis_home_dir ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    plan_buffer_line ( destination [ X_AXIS ] ,  destination [ Y_AXIS ] ,  destination [ Z_AXIS ] ,  destination [ E_AXIS ] ,  feedrate / 60 ,  active_extruder ) ; 
 
					 
					 
					 
					    plan_buffer_line ( destination [ X_AXIS ] ,  destination [ Y_AXIS ] ,  destination [ Z_AXIS ] ,  destination [ E_AXIS ] ,  feedrate / 60 ,  active_extruder ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    st_synchronize ( ) ; 
 
					 
					 
					 
					    st_synchronize ( ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1538,7 +1477,7 @@ static void homeaxis(int axis) {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( axis = = Z_AXIS ) 
 
					 
					 
					 
					      if  ( axis = = Z_AXIS ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      { 
 
					 
					 
					 
					      { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        feedrate  =  homing_feedrate [ axis ] ; 
 
					 
					 
					 
					        feedrate  =  homing_feedrate [ axis ] ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					        sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        if  ( axis_home_dir  >  0 ) 
 
					 
					 
					 
					        if  ( axis_home_dir  >  0 ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        { 
 
					 
					 
					 
					        { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          destination [ axis ]  =  ( - 1 )  *  fabs ( z_endstop_adj ) ; 
 
					 
					 
					 
					          destination [ axis ]  =  ( - 1 )  *  fabs ( z_endstop_adj ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1558,7 +1497,7 @@ static void homeaxis(int axis) {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# ifdef DELTA 
 
					 
					 
					 
					# ifdef DELTA 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    // retrace by the amount specified in endstop_adj
 
 
					 
					 
					 
					    // retrace by the amount specified in endstop_adj
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( endstop_adj [ axis ]  *  axis_home_dir  <  0 )  { 
 
					 
					 
					 
					    if  ( endstop_adj [ axis ]  *  axis_home_dir  <  0 )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					      sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      destination [ axis ]  =  endstop_adj [ axis ] ; 
 
					 
					 
					 
					      destination [ axis ]  =  endstop_adj [ axis ] ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      plan_buffer_line ( destination [ X_AXIS ] ,  destination [ Y_AXIS ] ,  destination [ Z_AXIS ] ,  destination [ E_AXIS ] ,  feedrate / 60 ,  active_extruder ) ; 
 
					 
					 
					 
					      plan_buffer_line ( destination [ X_AXIS ] ,  destination [ Y_AXIS ] ,  destination [ Z_AXIS ] ,  destination [ E_AXIS ] ,  feedrate / 60 ,  active_extruder ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      st_synchronize ( ) ; 
 
					 
					 
					 
					      st_synchronize ( ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -1614,7 +1553,7 @@ void refresh_cmd_timeout(void)
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					         calculate_delta ( current_position ) ;  // change cartesian kinematic to  delta kinematic;
 
 
					 
					 
					 
					         calculate_delta ( current_position ) ;  // change cartesian kinematic to  delta kinematic;
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					         plan_set_position ( delta [ X_AXIS ] ,  delta [ Y_AXIS ] ,  delta [ Z_AXIS ] ,  current_position [ E_AXIS ] ) ; 
 
					 
					 
					 
					         plan_set_position ( delta [ X_AXIS ] ,  delta [ Y_AXIS ] ,  delta [ Z_AXIS ] ,  current_position [ E_AXIS ] ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# else 
 
					 
					 
					 
					# else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					         plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					         sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					# endif 
 
					 
					 
					 
					# endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					         prepare_move ( ) ; 
 
					 
					 
					 
					         prepare_move ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					      } 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1630,7 +1569,7 @@ void refresh_cmd_timeout(void)
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					         calculate_delta ( current_position ) ;  // change cartesian kinematic  to  delta kinematic;
 
 
					 
					 
					 
					         calculate_delta ( current_position ) ;  // change cartesian kinematic  to  delta kinematic;
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					         plan_set_position ( delta [ X_AXIS ] ,  delta [ Y_AXIS ] ,  delta [ Z_AXIS ] ,  current_position [ E_AXIS ] ) ; 
 
					 
					 
					 
					         plan_set_position ( delta [ X_AXIS ] ,  delta [ Y_AXIS ] ,  delta [ Z_AXIS ] ,  current_position [ E_AXIS ] ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# else 
 
					 
					 
					 
					# else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					         plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					         sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					# endif 
 
					 
					 
					 
					# endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					         //prepare_move();
 
 
					 
					 
					 
					         //prepare_move();
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					      } 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -1774,7 +1713,25 @@ inline void gcode_G4() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# endif  //FWRETRACT
 
 
					 
					 
					 
					# endif  //FWRETRACT
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					/**
 
 
					 
					 
					 
					/**
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 *  G28 :  Home  all  axes ,  one  at  a  time 
 
					 
					 
					 
					 *  G28 :  Home  all  axes  according  to  settings 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *  Parameters 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *   None   Home  to  all  axes  with  no  parameters . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *         With  QUICK_HOME  enabled  XY  will  home  together ,  then  Z . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *  Cartesian  parameters 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *   X    Home  to  the  X  endstop 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *   Y    Home  to  the  Y  endstop 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *   Z    Home  to  the  Z  endstop 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *  If  numbers  are  included  with  XYZ  set  the  position  as  with  G92 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *  Currently  adds  the  home_offset ,  which  may  be  wrong  and  removed  soon . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *   Xn   Home  X ,  setting  X  to  n  +  home_offset [ X_AXIS ] 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *   Yn   Home  Y ,  setting  Y  to  n  +  home_offset [ Y_AXIS ] 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *   Zn   Home  Z ,  setting  Z  to  n  +  home_offset [ Z_AXIS ] 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 */ 
 
					 
					 
					 
					 */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					inline  void  gcode_G28 ( )  { 
 
					 
					 
					 
					inline  void  gcode_G28 ( )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # ifdef ENABLE_AUTO_BED_LEVELING 
 
					 
					 
					 
					  # ifdef ENABLE_AUTO_BED_LEVELING 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1797,7 +1754,7 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  enable_endstops ( true ) ; 
 
					 
					 
					 
					  enable_endstops ( true ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  for  ( int  i  =  X_AXIS ;  i  <  NUM_AXIS ;  i + + )  destination [ i ]  =  current_position [ i ] ; 
 
					 
					 
					 
					  for  ( int  i  =  0 ;  i  <  NUM_AXIS ;  i + + )  destination [ i ]  =  current_position [ i ] ;  // includes E_AXIS
  
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  feedrate  =  0.0 ; 
 
					 
					 
					 
					  feedrate  =  0.0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1807,7 +1764,7 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    // Move all carriages up together until the first endstop is hit.
 
 
					 
					 
					 
					    // Move all carriages up together until the first endstop is hit.
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    for  ( int  i  =  X_AXIS ;  i  < =  Z_AXIS ;  i + + )  current_position [ i ]  =  0 ; 
 
					 
					 
					 
					    for  ( int  i  =  X_AXIS ;  i  < =  Z_AXIS ;  i + + )  current_position [ i ]  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					    sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    for  ( int  i  =  X_AXIS ;  i  < =  Z_AXIS ;  i + + )  destination [ i ]  =  3  *  Z_MAX_LENGTH ; 
 
					 
					 
					 
					    for  ( int  i  =  X_AXIS ;  i  < =  Z_AXIS ;  i + + )  destination [ i ]  =  3  *  Z_MAX_LENGTH ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    feedrate  =  1.732  *  homing_feedrate [ X_AXIS ] ; 
 
					 
					 
					 
					    feedrate  =  1.732  *  homing_feedrate [ X_AXIS ] ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1828,26 +1785,28 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # else  // NOT DELTA
 
 
					 
					 
					 
					  # else  // NOT DELTA
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    home_all_axis  =  ! ( code_seen ( axis_codes [ X_AXIS ] )  | |  code_seen ( axis_codes [ Y_AXIS ] )  | |  code_seen ( axis_codes [ Z_AXIS ] ) ) ; 
 
					 
					 
					 
					    bool   homeX  =  code_seen ( axis_codes [ X_AXIS ] ) , 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					          homeY  =  code_seen ( axis_codes [ Y_AXIS ] ) , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					          homeZ  =  code_seen ( axis_codes [ Z_AXIS ] ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    home_all_axis  =  ! homeX  & &  ! homeY  & &  ! homeZ ;  // No parameters means home all axes
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # if Z_HOME_DIR > 0                       // If homing away from BED do Z first
 
 
					 
					 
					 
					    # if Z_HOME_DIR > 0                       // If homing away from BED do Z first
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( home_all_axis  | |  code_seen ( axis_codes [ Z_AXIS ] ) )  { 
 
					 
					 
					 
					      if  ( home_all_axis  | |  homeZ )  HOMEAXIS ( Z ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        HOMEAXIS ( Z ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    # endif 
 
					 
					 
					 
					    # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # ifdef QUICK_HOME 
 
					 
					 
					 
					    # ifdef QUICK_HOME 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( home_all_axis  | |  code_seen ( axis_codes [ X_AXIS ]  & &  code_seen ( axis_codes [ Y_AXIS ] ) ) )  {   //first diagonal move
 
 
					 
					 
					 
					      if  ( home_all_axis  | |  ( homeX  & &  homeY ) )  {   //first diagonal move
 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        current_position [ X_AXIS ]  =  current_position [ Y_AXIS ]  =  0 ; 
 
					 
					 
					 
					        current_position [ X_AXIS ]  =  current_position [ Y_AXIS ]  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # ifndef DUAL_X_CARRIAGE 
 
					 
					 
					 
					        # ifdef DUAL_X_CARRIAGE 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					          int  x_axis_home_dir  =  home_dir ( X_AXIS ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # else 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					          int  x_axis_home_dir  =  x_home_dir ( active_extruder ) ; 
 
					 
					 
					 
					          int  x_axis_home_dir  =  x_home_dir ( active_extruder ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          extruder_duplication_enabled  =  false ; 
 
					 
					 
					 
					          extruder_duplication_enabled  =  false ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        # else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					          int  x_axis_home_dir  =  home_dir ( X_AXIS ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # endif 
 
					 
					 
					 
					        # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					        sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        destination [ X_AXIS ]  =  1.5  *  max_length ( X_AXIS )  *  x_axis_home_dir ; 
 
					 
					 
					 
					        destination [ X_AXIS ]  =  1.5  *  max_length ( X_AXIS )  *  x_axis_home_dir ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        destination [ Y_AXIS ]  =  1.5  *  max_length ( Y_AXIS )  *  home_dir ( Y_AXIS ) ; 
 
					 
					 
					 
					        destination [ Y_AXIS ]  =  1.5  *  max_length ( Y_AXIS )  *  home_dir ( Y_AXIS ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        feedrate  =  homing_feedrate [ X_AXIS ] ; 
 
					 
					 
					 
					        feedrate  =  homing_feedrate [ X_AXIS ] ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1862,7 +1821,7 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        axis_is_at_home ( X_AXIS ) ; 
 
					 
					 
					 
					        axis_is_at_home ( X_AXIS ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        axis_is_at_home ( Y_AXIS ) ; 
 
					 
					 
					 
					        axis_is_at_home ( Y_AXIS ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					        sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        destination [ X_AXIS ]  =  current_position [ X_AXIS ] ; 
 
					 
					 
					 
					        destination [ X_AXIS ]  =  current_position [ X_AXIS ] ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        destination [ Y_AXIS ]  =  current_position [ Y_AXIS ] ; 
 
					 
					 
					 
					        destination [ Y_AXIS ]  =  current_position [ Y_AXIS ] ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        plan_buffer_line ( destination [ X_AXIS ] ,  destination [ Y_AXIS ] ,  destination [ Z_AXIS ] ,  destination [ E_AXIS ] ,  feedrate / 60 ,  active_extruder ) ; 
 
					 
					 
					 
					        plan_buffer_line ( destination [ X_AXIS ] ,  destination [ Y_AXIS ] ,  destination [ Z_AXIS ] ,  destination [ E_AXIS ] ,  feedrate / 60 ,  active_extruder ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1878,7 +1837,8 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					      } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # endif  //QUICK_HOME
 
 
					 
					 
					 
					    # endif  //QUICK_HOME
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( ( home_all_axis )  | |  ( code_seen ( axis_codes [ X_AXIS ] ) ) )  { 
 
					 
					 
					 
					    // Home X
 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    if  ( home_all_axis  | |  homeX )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # ifdef DUAL_X_CARRIAGE 
 
					 
					 
					 
					      # ifdef DUAL_X_CARRIAGE 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        int  tmp_extruder  =  active_extruder ; 
 
					 
					 
					 
					        int  tmp_extruder  =  active_extruder ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        extruder_duplication_enabled  =  false ; 
 
					 
					 
					 
					        extruder_duplication_enabled  =  false ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1896,31 +1856,38 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # endif 
 
					 
					 
					 
					      # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( home_all_axis  | |  code_seen ( axis_codes [ Y_AXIS ] ) )  HOMEAXIS ( Y ) ; 
 
					 
					 
					 
					    // Home Y
 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    if  ( home_all_axis  | |  homeY )  HOMEAXIS ( Y ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    // Set the X position, if included
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    // Adds the home_offset as well, which may be wrong
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( axis_codes [ X_AXIS ] ) )  { 
 
					 
					 
					 
					    if  ( code_seen ( axis_codes [ X_AXIS ] ) )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( code_value_long ( )  ! =  0 )  { 
 
					 
					 
					 
					      float  v  =  code_value ( ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					          current_position [ X_AXIS ]  =  code_value ( ) 
 
					 
					 
					 
					      if  ( v )  current_position [ X_AXIS ]  =  v 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					            # ifndef SCARA 
 
					 
					 
					 
					        # ifndef SCARA 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					              +  home_offset [ X_AXIS ] 
 
					 
					 
					 
					          +  home_offset [ X_AXIS ] 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					            # endif 
 
					 
					 
					 
					        # endif 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					          ; 
 
					 
					 
					 
					      ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( axis_codes [ Y_AXIS ] )  & &  code_value_long ( )  ! =  0 )  { 
 
					 
					 
					 
					    // Set the Y position, if included
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      current_position [ Y_AXIS ]  =  code_value ( ) 
 
					 
					 
					 
					    // Adds the home_offset as well, which may be wrong
 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    if  ( code_seen ( axis_codes [ Y_AXIS ] ) )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      float  v  =  code_value ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      if  ( v )  current_position [ Y_AXIS ]  =  v 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # ifndef SCARA 
 
					 
					 
					 
					        # ifndef SCARA 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          +  home_offset [ Y_AXIS ] 
 
					 
					 
					 
					          +  home_offset [ Y_AXIS ] 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # endif 
 
					 
					 
					 
					        # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      ; 
 
					 
					 
					 
					      ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # if Z_HOME_DIR < 0                       // If homing towards BED do Z last
 
 
					 
					 
					 
					    // Home Z last if homing towards the bed
 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    # if Z_HOME_DIR < 0 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # ifndef Z_SAFE_HOMING 
 
					 
					 
					 
					      # ifndef Z_SAFE_HOMING 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        if  ( home_all_axis  | |  code_seen ( axis_codes [ Z_AXIS ] ) )  { 
 
					 
					 
					 
					        if  ( home_all_axis  | |  homeZ )  { 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					          // Raise Z before homing Z? Shouldn't this happen before homing X or Y?
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          # if defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0 
 
					 
					 
					 
					          # if defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            # ifndef Z_PROBE_AND_ENDSTOP 
 
					 
					 
					 
					            # ifndef Z_PROBE_AND_ENDSTOP 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            destination [ Z_AXIS ]  =  - Z_RAISE_BEFORE_HOMING  *  home_dir ( Z_AXIS ) ;     // Set destination away from bed
 
 
					 
					 
					 
					            destination [ Z_AXIS ]  =  - Z_RAISE_BEFORE_HOMING  *  home_dir ( Z_AXIS ) ;     // Set destination away from bed
 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1941,7 +1908,7 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          feedrate  =  XY_TRAVEL_SPEED  /  60 ; 
 
					 
					 
					 
					          feedrate  =  XY_TRAVEL_SPEED  /  60 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          current_position [ Z_AXIS ]  =  0 ; 
 
					 
					 
					 
					          current_position [ Z_AXIS ]  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					          sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					          plan_buffer_line ( destination [ X_AXIS ] ,  destination [ Y_AXIS ] ,  destination [ Z_AXIS ] ,  destination [ E_AXIS ] ,  feedrate ,  active_extruder ) ; 
 
					 
					 
					 
					          plan_buffer_line ( destination [ X_AXIS ] ,  destination [ Y_AXIS ] ,  destination [ Z_AXIS ] ,  destination [ E_AXIS ] ,  feedrate ,  active_extruder ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          st_synchronize ( ) ; 
 
					 
					 
					 
					          st_synchronize ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          current_position [ X_AXIS ]  =  destination [ X_AXIS ] ; 
 
					 
					 
					 
					          current_position [ X_AXIS ]  =  destination [ X_AXIS ] ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -1951,7 +1918,7 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        } 
 
					 
					 
					 
					        } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        // Let's see if X and Y are homed and probe is inside bed area.
 
 
					 
					 
					 
					        // Let's see if X and Y are homed and probe is inside bed area.
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        if  ( code_seen( axis_codes [ Z_AXIS ] )  )  { 
 
					 
					 
					 
					        if  ( homeZ )  { 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          if  ( axis_known_position [ X_AXIS ]  & &  axis_known_position [ Y_AXIS ] )  { 
 
					 
					 
					 
					          if  ( axis_known_position [ X_AXIS ]  & &  axis_known_position [ Y_AXIS ] )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -1985,15 +1952,17 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # endif  // Z_HOME_DIR < 0
 
 
					 
					 
					 
					    # endif  // Z_HOME_DIR < 0
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					    // Set the Z position, if included
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( axis_codes [ Z_AXIS ] )  & &  code_value_long ( )  ! =  0 ) 
 
					 
					 
					 
					    // Adds the home_offset as well, which may be wrong
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      current_position [ Z_AXIS ]  =  code_value ( )  +  home_offset [ Z_AXIS ] ; 
 
					 
					 
					 
					    if  ( code_seen ( axis_codes [ Z_AXIS ] ) )  { 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      float  v  =  code_value ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      if  ( v )  current_position [ Z_AXIS ]  =  v  +  home_offset [ Z_AXIS ] ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # if defined(ENABLE_AUTO_BED_LEVELING) && (Z_HOME_DIR < 0) 
 
					 
					 
					 
					    # if defined(ENABLE_AUTO_BED_LEVELING) && (Z_HOME_DIR < 0) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( home_all_axis  | |  code_seen ( axis_codes [ Z_AXIS ] ) ) 
 
					 
					 
					 
					      if  ( home_all_axis  | |  homeZ )  current_position [ Z_AXIS ]  + =  zprobe_zoffset ;   // Add Z_Probe offset (the distance is negative)
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        current_position [ Z_AXIS ]  + =  zprobe_zoffset ;   //Add Z_Probe offset (the distance is negative)
 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    # endif 
 
					 
					 
					 
					    # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					    sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # endif  // else DELTA
 
 
					 
					 
					 
					  # endif  // else DELTA
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -2018,7 +1987,7 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      plan_buffer_line ( destination [ X_AXIS ] ,  destination [ Y_AXIS ] ,  destination [ Z_AXIS ] ,  destination [ E_AXIS ] ,  feedrate ,  active_extruder ) ; 
 
					 
					 
					 
					      plan_buffer_line ( destination [ X_AXIS ] ,  destination [ Y_AXIS ] ,  destination [ Z_AXIS ] ,  destination [ E_AXIS ] ,  feedrate ,  active_extruder ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      st_synchronize ( ) ; 
 
					 
					 
					 
					      st_synchronize ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      current_position [ Z_AXIS ]  =  MESH_HOME_SEARCH_Z ; 
 
					 
					 
					 
					      current_position [ Z_AXIS ]  =  MESH_HOME_SEARCH_Z ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					      sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      mbl . active  =  1 ; 
 
					 
					 
					 
					      mbl . active  =  1 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # endif 
 
					 
					 
					 
					  # endif 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -2089,7 +2058,7 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      int  ix ,  iy ; 
 
					 
					 
					 
					      int  ix ,  iy ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( probe_point  = =  0 )  { 
 
					 
					 
					 
					      if  ( probe_point  = =  0 )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        current_position [ Z_AXIS ]  =  MESH_HOME_SEARCH_Z ; 
 
					 
					 
					 
					        current_position [ Z_AXIS ]  =  MESH_HOME_SEARCH_Z ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					        sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      }  else  { 
 
					 
					 
					 
					      }  else  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        ix  =  ( probe_point - 1 )  %  MESH_NUM_X_POINTS ; 
 
					 
					 
					 
					        ix  =  ( probe_point - 1 )  %  MESH_NUM_X_POINTS ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        iy  =  ( probe_point - 1 )  /  MESH_NUM_X_POINTS ; 
 
					 
					 
					 
					        iy  =  ( probe_point - 1 )  /  MESH_NUM_X_POINTS ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -2151,8 +2120,8 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   * 
 
					 
					 
					 
					   * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *  Global  Parameters : 
 
					 
					 
					 
					   *  Global  Parameters : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   * 
 
					 
					 
					 
					   * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *  E / e  By  default  G29  engages /  disengages  the  probe  for  each  point  . 
 
					 
					 
					 
					   *  E / e  By  default  G29  will engages  the  probe ,  test  the  bed ,  then  disengage  . 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					   *      Include  " E "  to  engage  and  disengage  the  probe  just  onc  e. 
 
					 
					 
					 
					   *      Include  " E "  to  engage / disengage  the  probe  for  each  sampl  e. 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					   *      There ' s  no  extra  effect  if  you  have  a  fixed  probe . 
 
					 
					 
					 
					   *      There ' s  no  extra  effect  if  you  have  a  fixed  probe . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *      Usage :  " G29 E "  or  " G29 e " 
 
					 
					 
					 
					   *      Usage :  " G29 E "  or  " G29 e " 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   * 
 
					 
					 
					 
					   * 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -2168,7 +2137,6 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    int  verbose_level  =  1 ; 
 
					 
					 
					 
					    int  verbose_level  =  1 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    float  x_tmp ,  y_tmp ,  z_tmp ,  real_z ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( ' V ' )  | |  code_seen ( ' v ' ) )  { 
 
					 
					 
					 
					    if  ( code_seen ( ' V ' )  | |  code_seen ( ' v ' ) )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      verbose_level  =  code_value_long ( ) ; 
 
					 
					 
					 
					      verbose_level  =  code_value_long ( ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -2179,7 +2147,7 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    bool  dryrun  =  code_seen ( ' D ' )  | |  code_seen ( ' d ' ) ; 
 
					 
					 
					 
					    bool  dryrun  =  code_seen ( ' D ' )  | |  code_seen ( ' d ' ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    bool  en hanced_g29  =  code_seen ( ' E ' )  | |  code_seen ( ' e ' ) ; 
 
					 
					 
					 
					    bool  en gage_probe_for_each_reading  =  code_seen ( ' E ' )  | |  code_seen ( ' e ' ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # ifdef AUTO_BED_LEVELING_GRID 
 
					 
					 
					 
					    # ifdef AUTO_BED_LEVELING_GRID 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -2263,7 +2231,7 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        current_position [ X_AXIS ]  =  uncorrected_position . x ; 
 
					 
					 
					 
					        current_position [ X_AXIS ]  =  uncorrected_position . x ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        current_position [ Y_AXIS ]  =  uncorrected_position . y ; 
 
					 
					 
					 
					        current_position [ Y_AXIS ]  =  uncorrected_position . y ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        current_position [ Z_AXIS ]  =  uncorrected_position . z ; 
 
					 
					 
					 
					        current_position [ Z_AXIS ]  =  uncorrected_position . z ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					        sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # endif 
 
					 
					 
					 
					      # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -2337,16 +2305,14 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          // Enhanced G29 - Do not retract servo between probes
 
 
					 
					 
					 
					          // Enhanced G29 - Do not retract servo between probes
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          ProbeAction  act ; 
 
					 
					 
					 
					          ProbeAction  act ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          if  ( enhanced_g29 )  { 
 
					 
					 
					 
					          if  ( engage_probe_for_each_reading ) 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					            if  ( yProbe  = =  front_probe_bed_position  & &  xCount  = =  0 ) 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					              act  =  ProbeEngage ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            else  if  ( yProbe  = =  front_probe_bed_position  +  ( yGridSpacing  *  ( auto_bed_leveling_grid_points  -  1 ) )  & &  xCount  = =  auto_bed_leveling_grid_points  -  1 ) 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					              act  =  ProbeRetract ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            else 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					              act  =  ProbeStay ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          } 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          else 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					            act  =  ProbeEngageAndRetract ; 
 
					 
					 
					 
					            act  =  ProbeEngageAndRetract ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					          else  if  ( yProbe  = =  front_probe_bed_position  & &  xCount  = =  0 ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            act  =  ProbeEngage ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					          else  if  ( yProbe  = =  front_probe_bed_position  +  ( yGridSpacing  *  ( auto_bed_leveling_grid_points  -  1 ) )  & &  xCount  = =  auto_bed_leveling_grid_points  -  1 ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            act  =  ProbeRetract ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					          else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            act  =  ProbeStay ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          measured_z  =  probe_pt ( xProbe ,  yProbe ,  z_before ,  act ,  verbose_level ) ; 
 
					 
					 
					 
					          measured_z  =  probe_pt ( xProbe ,  yProbe ,  z_before ,  act ,  verbose_level ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -2428,20 +2394,17 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # else  // !AUTO_BED_LEVELING_GRID
 
 
					 
					 
					 
					    # else  // !AUTO_BED_LEVELING_GRID
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      // Probe at 3 arbitrary points
 
 
					 
					 
					 
					      // Actions for each probe
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      float  z_at_pt_1 ,  z_at_pt_2 ,  z_at_pt_3 ; 
 
					 
					 
					 
					      ProbeAction  p1 ,  p2 ,  p3 ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      if  ( engage_probe_for_each_reading ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        p1  =  p2  =  p3  =  ProbeEngageAndRetract ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					      else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        p1  =  ProbeEngage ,  p2  =  ProbeStay ,  p3  =  ProbeRetract ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( enhanced_g29 )  { 
 
					 
					 
					 
					      // Probe at 3 arbitrary points
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        // Basic Enhanced G29
 
 
					 
					 
					 
					      float  z_at_pt_1  =  probe_pt ( ABL_PROBE_PT_1_X ,  ABL_PROBE_PT_1_Y ,  Z_RAISE_BEFORE_PROBING ,  p1 ,  verbose_level ) , 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        z_at_pt_1  =  probe_pt ( ABL_PROBE_PT_1_X ,  ABL_PROBE_PT_1_Y ,  Z_RAISE_BEFORE_PROBING ,  ProbeEngage ,  verbose_level ) ; 
 
					 
					 
					 
					            z_at_pt_2  =  probe_pt ( ABL_PROBE_PT_2_X ,  ABL_PROBE_PT_2_Y ,  current_position [ Z_AXIS ]  +  Z_RAISE_BETWEEN_PROBINGS ,  p2 ,  verbose_level ) , 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        z_at_pt_2  =  probe_pt ( ABL_PROBE_PT_2_X ,  ABL_PROBE_PT_2_Y ,  current_position [ Z_AXIS ]  +  Z_RAISE_BETWEEN_PROBINGS ,  ProbeStay ,  verbose_level ) ; 
 
					 
					 
					 
					            z_at_pt_3  =  probe_pt ( ABL_PROBE_PT_3_X ,  ABL_PROBE_PT_3_Y ,  current_position [ Z_AXIS ]  +  Z_RAISE_BETWEEN_PROBINGS ,  p3 ,  verbose_level ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        z_at_pt_3  =  probe_pt ( ABL_PROBE_PT_3_X ,  ABL_PROBE_PT_3_Y ,  current_position [ Z_AXIS ]  +  Z_RAISE_BETWEEN_PROBINGS ,  ProbeRetract ,  verbose_level ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      else  { 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        z_at_pt_1  =  probe_pt ( ABL_PROBE_PT_1_X ,  ABL_PROBE_PT_1_Y ,  Z_RAISE_BEFORE_PROBING ,  ProbeEngageAndRetract ,  verbose_level ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        z_at_pt_2  =  probe_pt ( ABL_PROBE_PT_2_X ,  ABL_PROBE_PT_2_Y ,  current_position [ Z_AXIS ]  +  Z_RAISE_BETWEEN_PROBINGS ,  ProbeEngageAndRetract ,  verbose_level ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        z_at_pt_3  =  probe_pt ( ABL_PROBE_PT_3_X ,  ABL_PROBE_PT_3_Y ,  current_position [ Z_AXIS ]  +  Z_RAISE_BETWEEN_PROBINGS ,  ProbeEngageAndRetract ,  verbose_level ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      clean_up_after_endstop_move ( ) ; 
 
					 
					 
					 
					      clean_up_after_endstop_move ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( ! dryrun )  set_bed_level_equation_3pts ( z_at_pt_1 ,  z_at_pt_2 ,  z_at_pt_3 ) ; 
 
					 
					 
					 
					      if  ( ! dryrun )  set_bed_level_equation_3pts ( z_at_pt_1 ,  z_at_pt_2 ,  z_at_pt_3 ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -2456,6 +2419,7 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      // When the bed is uneven, this height must be corrected.
 
 
					 
					 
					 
					      // When the bed is uneven, this height must be corrected.
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( ! dryrun ) 
 
					 
					 
					 
					      if  ( ! dryrun ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      { 
 
					 
					 
					 
					      { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        float  x_tmp ,  y_tmp ,  z_tmp ,  real_z ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        real_z  =  float ( st_get_position ( Z_AXIS ) )  /  axis_steps_per_unit [ Z_AXIS ] ;   //get the real Z (since the auto bed leveling is already correcting the plane)
 
 
					 
					 
					 
					        real_z  =  float ( st_get_position ( Z_AXIS ) )  /  axis_steps_per_unit [ Z_AXIS ] ;   //get the real Z (since the auto bed leveling is already correcting the plane)
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        x_tmp  =  current_position [ X_AXIS ]  +  X_PROBE_OFFSET_FROM_EXTRUDER ; 
 
					 
					 
					 
					        x_tmp  =  current_position [ X_AXIS ]  +  X_PROBE_OFFSET_FROM_EXTRUDER ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        y_tmp  =  current_position [ Y_AXIS ]  +  Y_PROBE_OFFSET_FROM_EXTRUDER ; 
 
					 
					 
					 
					        y_tmp  =  current_position [ Y_AXIS ]  +  Y_PROBE_OFFSET_FROM_EXTRUDER ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -2463,7 +2427,7 @@ inline void gcode_G28() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        apply_rotation_xyz ( plan_bed_level_matrix ,  x_tmp ,  y_tmp ,  z_tmp ) ;          //Apply the correction sending the probe offset
 
 
					 
					 
					 
					        apply_rotation_xyz ( plan_bed_level_matrix ,  x_tmp ,  y_tmp ,  z_tmp ) ;          //Apply the correction sending the probe offset
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        current_position [ Z_AXIS ]  =  z_tmp  -  real_z  +  current_position [ Z_AXIS ] ;    //The difference is added to current position and sent to planner.
 
 
					 
					 
					 
					        current_position [ Z_AXIS ]  =  z_tmp  -  real_z  +  current_position [ Z_AXIS ] ;    //The difference is added to current position and sent to planner.
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					        sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					      } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # endif  // !DELTA
 
 
					 
					 
					 
					    # endif  // !DELTA
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -2514,15 +2478,17 @@ inline void gcode_G92() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  if  ( ! code_seen ( axis_codes [ E_AXIS ] ) ) 
 
					 
					 
					 
					  if  ( ! code_seen ( axis_codes [ E_AXIS ] ) ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    st_synchronize ( ) ; 
 
					 
					 
					 
					    st_synchronize ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  bool  didXYZ  =  false ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  for  ( int  i  =  0 ;  i  <  NUM_AXIS ;  i + + )  { 
 
					 
					 
					 
					  for  ( int  i  =  0 ;  i  <  NUM_AXIS ;  i + + )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( axis_codes [ i ] ) )  { 
 
					 
					 
					 
					    if  ( code_seen ( axis_codes [ i ] ) )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      current_position [ i ]  =  code_value ( ) ; 
 
					 
					 
					 
					      float  v  =  current_position [ i ]  =  code_value ( ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( i  = =  E_AXIS ) 
 
					 
					 
					 
					      if  ( i  = =  E_AXIS ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        plan_set_e_position ( current_position[ E_AXIS ]  ) ; 
 
					 
					 
					 
					        plan_set_e_position ( v ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      else 
 
					 
					 
					 
					      else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ] )  ; 
 
					 
					 
					 
					        didXYZ =  true  ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  } 
 
					 
					 
					 
					  } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  if  ( didXYZ )  sync_plan_position ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} 
 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					# ifdef ULTIPANEL 
 
					 
					 
					 
					# ifdef ULTIPANEL 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -2805,14 +2771,14 @@ inline void gcode_M42() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   * 
 
					 
					 
					 
					   * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *  Usage : 
 
					 
					 
					 
					   *  Usage : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *    M48  < n # >  < X # >  < Y # >  < V # >  < E >  < L # > 
 
					 
					 
					 
					   *    M48  < n # >  < X # >  < Y # >  < V # >  < E >  < L # > 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *      n  =  Number  of  sample s ( 4 - 50 ,  default  10 ) 
 
					 
					 
					 
					   *      P  =  Number  of  sample d point  s ( 4 - 50 ,  default  10 ) 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					   *      X  =  Sample  X  position 
 
					 
					 
					 
					   *      X  =  Sample  X  position 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *      Y  =  Sample  Y  position 
 
					 
					 
					 
					   *      Y  =  Sample  Y  position 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *      V  =  Verbose  level  ( 0 - 4 ,  default = 1 ) 
 
					 
					 
					 
					   *      V  =  Verbose  level  ( 0 - 4 ,  default = 1 ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *      E  =  Engage  probe  for  each  reading 
 
					 
					 
					 
					   *      E  =  Engage  probe  for  each  reading 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *      L  =  Number  of  legs  of  movement  before  probe 
 
					 
					 
					 
					   *      L  =  Number  of  legs  of  movement  before  probe 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *   
 
					 
					 
					 
					   *   
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *  This  function  assumes  the  bed  has  been  homed .   Specifical y,  that  a  G28  command 
 
					 
					 
					 
					   *  This  function  assumes  the  bed  has  been  homed .   Specifical l y,  that  a  G28  command 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					   *  as  been  issued  prior  to  invoking  the  M48  Z - Probe  repeatability  measurement  function . 
 
					 
					 
					 
					   *  as  been  issued  prior  to  invoking  the  M48  Z - Probe  repeatability  measurement  function . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *  Any  information  generated  by  a  prior  G29  Bed  leveling  command  will  be  lost  and  need  to  be 
 
					 
					 
					 
					   *  Any  information  generated  by  a  prior  G29  Bed  leveling  command  will  be  lost  and  need  to  be 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					   *  regenerated . 
 
					 
					 
					 
					   *  regenerated . 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -2839,10 +2805,10 @@ inline void gcode_M42() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( verbose_level  >  0 ) 
 
					 
					 
					 
					    if  ( verbose_level  >  0 ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      SERIAL_PROTOCOLPGM ( " M48 Z-Probe Repeatability test \n " ) ; 
 
					 
					 
					 
					      SERIAL_PROTOCOLPGM ( " M48 Z-Probe Repeatability test \n " ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( '  n' ) )  { 
 
					 
					 
					 
					    if  ( code_seen ( ' P' )  | |  code_seen ( ' p ' )  | |  code_seen ( '  n' ) )  {  // `n` for legacy support only - please use `P`!
  
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      n_samples  =  code_value ( ) ; 
 
					 
					 
					 
					      n_samples  =  code_value ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( n_samples  <  4  | |  n_samples  >  50 )  { 
 
					 
					 
					 
					      if  ( n_samples  <  4  | |  n_samples  >  50 )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_PROTOCOLPGM ( " ?S pecified s ample size not plausible (4-50).\n " ) ; 
 
					 
					 
					 
					        SERIAL_PROTOCOLPGM ( " ?S ample size not plausible (4-50).\n " ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        return ; 
 
					 
					 
					 
					        return ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					      } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -2859,7 +2825,7 @@ inline void gcode_M42() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( ' X ' )  | |  code_seen ( ' x ' ) )  { 
 
					 
					 
					 
					    if  ( code_seen ( ' X ' )  | |  code_seen ( ' x ' ) )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      X_probe_location  =  code_value ( )  -  X_PROBE_OFFSET_FROM_EXTRUDER ; 
 
					 
					 
					 
					      X_probe_location  =  code_value ( )  -  X_PROBE_OFFSET_FROM_EXTRUDER ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( X_probe_location  <  X_MIN_POS  | |  X_probe_location  >  X_MAX_POS )  { 
 
					 
					 
					 
					      if  ( X_probe_location  <  X_MIN_POS  | |  X_probe_location  >  X_MAX_POS )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_PROTOCOLPGM ( " ? Specified  X position out of range.\n " ) ; 
 
					 
					 
					 
					        SERIAL_PROTOCOLPGM ( " ? X position out of range.\n " ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        return ; 
 
					 
					 
					 
					        return ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					      } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -2867,7 +2833,7 @@ inline void gcode_M42() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( ' Y ' )  | |  code_seen ( ' y ' ) )  { 
 
					 
					 
					 
					    if  ( code_seen ( ' Y ' )  | |  code_seen ( ' y ' ) )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      Y_probe_location  =  code_value ( )  -   Y_PROBE_OFFSET_FROM_EXTRUDER ; 
 
					 
					 
					 
					      Y_probe_location  =  code_value ( )  -   Y_PROBE_OFFSET_FROM_EXTRUDER ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( Y_probe_location  <  Y_MIN_POS  | |  Y_probe_location  >  Y_MAX_POS )  { 
 
					 
					 
					 
					      if  ( Y_probe_location  <  Y_MIN_POS  | |  Y_probe_location  >  Y_MAX_POS )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_PROTOCOLPGM ( " ? Specified  Y position out of range.\n " ) ; 
 
					 
					 
					 
					        SERIAL_PROTOCOLPGM ( " ? Y position out of range.\n " ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        return ; 
 
					 
					 
					 
					        return ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					      } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -2876,7 +2842,7 @@ inline void gcode_M42() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      n_legs  =  code_value ( ) ; 
 
					 
					 
					 
					      n_legs  =  code_value ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( n_legs  = =  1 )  n_legs  =  2 ; 
 
					 
					 
					 
					      if  ( n_legs  = =  1 )  n_legs  =  2 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( n_legs  <  0  | |  n_legs  >  15 )  { 
 
					 
					 
					 
					      if  ( n_legs  <  0  | |  n_legs  >  15 )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_PROTOCOLPGM ( " ? Specified n umber of legs in movement not plausible (0-15).\n " ) ; 
 
					 
					 
					 
					        SERIAL_PROTOCOLPGM ( " ? N umber of legs in movement not plausible (0-15).\n " ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        return ; 
 
					 
					 
					 
					        return ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      } 
 
					 
					 
					 
					      } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -2899,7 +2865,7 @@ inline void gcode_M42() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    // use that as a starting point for each probe.
 
 
					 
					 
					 
					    // use that as a starting point for each probe.
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    //
 
 
					 
					 
					 
					    //
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( verbose_level  >  2 ) 
 
					 
					 
					 
					    if  ( verbose_level  >  2 ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      SERIAL_PROTOCOL ( " Positioning  probe for the test .\n " ) ; 
 
					 
					 
					 
					      SERIAL_PROTOCOL ( " Positioning  the probe.. .\n " ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    plan_buffer_line (  X_probe_location ,  Y_probe_location ,  Z_start_location , 
 
					 
					 
					 
					    plan_buffer_line (  X_probe_location ,  Y_probe_location ,  Z_start_location , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        ext_position , 
 
					 
					 
					 
					        ext_position , 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -2948,7 +2914,7 @@ inline void gcode_M42() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        //SERIAL_ECHOPAIR("starting radius: ",radius);
 
 
					 
					 
					 
					        //SERIAL_ECHOPAIR("starting radius: ",radius);
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        //SERIAL_ECHOPAIR("   theta: ",theta);
 
 
					 
					 
					 
					        //SERIAL_ECHOPAIR("   theta: ",theta);
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        //SERIAL_ECHOPAIR("   direction: ",rotational_direction);
 
 
					 
					 
					 
					        //SERIAL_ECHOPAIR("   direction: ",rotational_direction);
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        //SERIAL_ PROTOCOLLNPGM("") ;
 
					 
					 
					 
					        //SERIAL_ EOL ;
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        float  dir  =  rotational_direction  ?  1  :  - 1 ; 
 
					 
					 
					 
					        float  dir  =  rotational_direction  ?  1  :  - 1 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        for  ( l  =  0 ;  l  <  n_legs  -  1 ;  l + + )  { 
 
					 
					 
					 
					        for  ( l  =  0 ;  l  <  n_legs  -  1 ;  l + + )  { 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -2967,7 +2933,7 @@ inline void gcode_M42() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          if  ( verbose_level  >  3 )  { 
 
					 
					 
					 
					          if  ( verbose_level  >  3 )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            SERIAL_ECHOPAIR ( " x:  " ,  X_current ) ; 
 
					 
					 
					 
					            SERIAL_ECHOPAIR ( " x:  " ,  X_current ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            SERIAL_ECHOPAIR ( " y:  " ,  Y_current ) ; 
 
					 
					 
					 
					            SERIAL_ECHOPAIR ( " y:  " ,  Y_current ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            SERIAL_ PROTOCOLLNPGM( " " )  ; 
 
					 
					 
					 
					            SERIAL_ EOL ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					          } 
 
					 
					 
					 
					          } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          do_blocking_move_to (  X_current ,  Y_current ,  Z_current  ) ; 
 
					 
					 
					 
					          do_blocking_move_to (  X_current ,  Y_current ,  Z_current  ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -3783,23 +3749,23 @@ inline void gcode_M206() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  inline  void  gcode_M218 ( )  { 
 
					 
					 
					 
					  inline  void  gcode_M218 ( )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( setTargetedHotend ( 218 ) )  return ; 
 
					 
					 
					 
					    if  ( setTargetedHotend ( 218 ) )  return ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( ' X ' ) )  extruder_offset [ X_AXIS] [  tmp_extruder]  =  code_value ( ) ; 
 
					 
					 
					 
					    if  ( code_seen ( ' X ' ) )  extruder_offset [  tmp_extruder] [ X_AXIS ]  =  code_value ( ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( ' Y ' ) )  extruder_offset [ Y_AXIS] [  tmp_extruder]  =  code_value ( ) ; 
 
					 
					 
					 
					    if  ( code_seen ( ' Y ' ) )  extruder_offset [  tmp_extruder] [ Y_AXIS ]  =  code_value ( ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # ifdef DUAL_X_CARRIAGE 
 
					 
					 
					 
					    # ifdef DUAL_X_CARRIAGE 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( code_seen ( ' Z ' ) )  extruder_offset [ Z_AXIS] [  tmp_extruder]  =  code_value ( ) ; 
 
					 
					 
					 
					      if  ( code_seen ( ' Z ' ) )  extruder_offset [  tmp_extruder] [ Z_AXIS ]  =  code_value ( ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    # endif 
 
					 
					 
					 
					    # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    SERIAL_ECHO_START ; 
 
					 
					 
					 
					    SERIAL_ECHO_START ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    SERIAL_ECHOPGM ( MSG_HOTEND_OFFSET ) ; 
 
					 
					 
					 
					    SERIAL_ECHOPGM ( MSG_HOTEND_OFFSET ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    for  ( tmp_extruder  =  0 ;  tmp_extruder  <  EXTRUDERS ;  tmp_extruder + + )  { 
 
					 
					 
					 
					    for  ( tmp_extruder  =  0 ;  tmp_extruder  <  EXTRUDERS ;  tmp_extruder + + )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      SERIAL_ECHO ( "   " ) ; 
 
					 
					 
					 
					      SERIAL_ECHO ( "   " ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      SERIAL_ECHO ( extruder_offset [ X_AXIS] [  tmp_extruder] ) ; 
 
					 
					 
					 
					      SERIAL_ECHO ( extruder_offset [  tmp_extruder] [ X_AXIS ] ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      SERIAL_ECHO ( " , " ) ; 
 
					 
					 
					 
					      SERIAL_ECHO ( " , " ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      SERIAL_ECHO ( extruder_offset [ Y_AXIS] [  tmp_extruder] ) ; 
 
					 
					 
					 
					      SERIAL_ECHO ( extruder_offset [  tmp_extruder] [ Y_AXIS ] ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      # ifdef DUAL_X_CARRIAGE 
 
					 
					 
					 
					      # ifdef DUAL_X_CARRIAGE 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHO ( " , " ) ; 
 
					 
					 
					 
					        SERIAL_ECHO ( " , " ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHO ( extruder_offset [ Z_AXIS] [  tmp_extruder] ) ; 
 
					 
					 
					 
					        SERIAL_ECHO ( extruder_offset [  tmp_extruder] [ Z_AXIS ] ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      # endif 
 
					 
					 
					 
					      # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    SERIAL_EOL ; 
 
					 
					 
					 
					    SERIAL_EOL ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -4490,13 +4456,13 @@ inline void gcode_M503() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHO_START ; 
 
					 
					 
					 
					        SERIAL_ECHO_START ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHOPGM ( MSG_HOTEND_OFFSET ) ; 
 
					 
					 
					 
					        SERIAL_ECHOPGM ( MSG_HOTEND_OFFSET ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHO ( "   " ) ; 
 
					 
					 
					 
					        SERIAL_ECHO ( "   " ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHO ( extruder_offset [ X_AXIS ] [ 0 ] ) ; 
 
					 
					 
					 
					        SERIAL_ECHO ( extruder_offset [ 0 ] [ X_AXIS ] ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHO ( " , " ) ; 
 
					 
					 
					 
					        SERIAL_ECHO ( " , " ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHO ( extruder_offset [ Y_AXIS ] [ 0 ] ) ; 
 
					 
					 
					 
					        SERIAL_ECHO ( extruder_offset [ 0 ] [ Y_AXIS ] ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHO ( "   " ) ; 
 
					 
					 
					 
					        SERIAL_ECHO ( "   " ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHO ( duplicate_extruder_x_offset ) ; 
 
					 
					 
					 
					        SERIAL_ECHO ( duplicate_extruder_x_offset ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHO ( " , " ) ; 
 
					 
					 
					 
					        SERIAL_ECHO ( " , " ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        SERIAL_ECHOLN ( extruder_offset [ Y_AXIS ] [ 1 ] ) ; 
 
					 
					 
					 
					        SERIAL_ECHOLN ( extruder_offset [ 1 ] [ Y_AXIS ] ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        break ; 
 
					 
					 
					 
					        break ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      case  DXC_FULL_CONTROL_MODE : 
 
					 
					 
					 
					      case  DXC_FULL_CONTROL_MODE : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      case  DXC_AUTO_PARK_MODE : 
 
					 
					 
					 
					      case  DXC_AUTO_PARK_MODE : 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -4605,7 +4571,6 @@ inline void gcode_T() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # if EXTRUDERS > 1 
 
					 
					 
					 
					    # if EXTRUDERS > 1 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      bool  make_move  =  false ; 
 
					 
					 
					 
					      bool  make_move  =  false ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # endif 
 
					 
					 
					 
					    # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( ' F ' ) )  { 
 
					 
					 
					 
					    if  ( code_seen ( ' F ' ) )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # if EXTRUDERS > 1 
 
					 
					 
					 
					      # if EXTRUDERS > 1 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        make_move  =  true ; 
 
					 
					 
					 
					        make_move  =  true ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -4632,11 +4597,11 @@ inline void gcode_T() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          // apply Y & Z extruder offset (x offset is already used in determining home pos)
 
 
					 
					 
					 
					          // apply Y & Z extruder offset (x offset is already used in determining home pos)
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          current_position [ Y_AXIS ]  =  current_position [ Y_AXIS ]  - 
 
					 
					 
					 
					          current_position [ Y_AXIS ]  =  current_position [ Y_AXIS ]  - 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                       extruder_offset [ Y_AXIS] [  active_extruder]  + 
 
					 
					 
					 
					                       extruder_offset [  active_extruder] [ Y_AXIS ]  + 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					                       extruder_offset [ Y_AXIS] [  tmp_extruder] ; 
 
					 
					 
					 
					                       extruder_offset [  tmp_extruder] [ Y_AXIS ] ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					          current_position [ Z_AXIS ]  =  current_position [ Z_AXIS ]  - 
 
					 
					 
					 
					          current_position [ Z_AXIS ]  =  current_position [ Z_AXIS ]  - 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                       extruder_offset [ Z_AXIS] [  active_extruder]  + 
 
					 
					 
					 
					                       extruder_offset [  active_extruder] [ Z_AXIS ]  + 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					                       extruder_offset [ Z_AXIS] [  tmp_extruder] ; 
 
					 
					 
					 
					                       extruder_offset [  tmp_extruder] [ Z_AXIS ] ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          active_extruder  =  tmp_extruder ; 
 
					 
					 
					 
					          active_extruder  =  tmp_extruder ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -4666,7 +4631,7 @@ inline void gcode_T() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # else  // !DUAL_X_CARRIAGE
 
 
					 
					 
					 
					        # else  // !DUAL_X_CARRIAGE
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          // Offset extruder (only by XY)
 
 
					 
					 
					 
					          // Offset extruder (only by XY)
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          for  ( int  i = X_AXIS ;  i < = Y_AXIS ;  i + + ) 
 
					 
					 
					 
					          for  ( int  i = X_AXIS ;  i < = Y_AXIS ;  i + + ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            current_position [ i ]  + =  extruder_offset [ i] [  tmp_extruder]  -  extruder_offset [ i] [  active_extruder] ; 
 
					 
					 
					 
					            current_position [ i ]  + =  extruder_offset [  tmp_extruder] [ i ]  -  extruder_offset [  active_extruder] [ i ] ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					          // Set the new active extruder and position
 
 
					 
					 
					 
					          // Set the new active extruder and position
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          active_extruder  =  tmp_extruder ; 
 
					 
					 
					 
					          active_extruder  =  tmp_extruder ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # endif  // !DUAL_X_CARRIAGE
 
 
					 
					 
					 
					        # endif  // !DUAL_X_CARRIAGE
 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -4675,7 +4640,7 @@ inline void gcode_T() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          //sent position to plan_set_position();
 
 
					 
					 
					 
					          //sent position to plan_set_position();
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          plan_set_position ( delta [ X_AXIS ] ,  delta [ Y_AXIS ] ,  delta [ Z_AXIS ] , current_position [ E_AXIS ] ) ; 
 
					 
					 
					 
					          plan_set_position ( delta [ X_AXIS ] ,  delta [ Y_AXIS ] ,  delta [ Z_AXIS ] , current_position [ E_AXIS ] ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        # else 
 
					 
					 
					 
					        # else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					          sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        # endif 
 
					 
					 
					 
					        # endif 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        // Move to the old position if 'F' was in the parameters
 
 
					 
					 
					 
					        // Move to the old position if 'F' was in the parameters
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        if  ( make_move  & &  ! Stopped )  prepare_move ( ) ; 
 
					 
					 
					 
					        if  ( make_move  & &  ! Stopped )  prepare_move ( ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -4978,14 +4943,13 @@ void process_commands() {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        case  665 :  // M665 set delta configurations L<diagonal_rod> R<delta_radius> S<segments_per_sec>
 
 
					 
					 
					 
					        case  665 :  // M665 set delta configurations L<diagonal_rod> R<delta_radius> S<segments_per_sec>
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          gcode_M665 ( ) ; 
 
					 
					 
					 
					          gcode_M665 ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          break ; 
 
					 
					 
					 
					          break ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        case  666 :  // M666 set delta endstop adjustment
 
 
					 
					 
					 
					      # endif 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					          gcode_M666 ( ) ; 
 
					 
					 
					 
					
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					          break ; 
 
					 
					 
					 
					      # if defined(DELTA) || defined(Z_DUAL_ENDSTOPS) 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      # elif defined(Z_DUAL_ENDSTOPS) 
 
					 
					 
					 
					        case  666 :  // M666 set delta / dual endstop adjustment
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        case  666 :  // M666 set delta endstop adjustment
 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					          gcode_M666 ( ) ; 
 
					 
					 
					 
					          gcode_M666 ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          break ; 
 
					 
					 
					 
					          break ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # endif  // DELTA
  
 
					 
					 
					 
					      # endif 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      # ifdef FWRETRACT 
 
					 
					 
					 
					      # ifdef FWRETRACT 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        case  207 :  //M207 - set retract length S[positive mm] F[feedrate mm/min] Z[additional zlift/hop]
 
 
					 
					 
					 
					        case  207 :  //M207 - set retract length S[positive mm] F[feedrate mm/min] Z[additional zlift/hop]
 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -5208,16 +5172,10 @@ void ClearToSend()
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					void  get_coordinates ( )  { 
 
					 
					 
					 
					void  get_coordinates ( )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  for  ( int  i  =  0 ;  i  <  NUM_AXIS ;  i + + )  { 
 
					 
					 
					 
					  for  ( int  i  =  0 ;  i  <  NUM_AXIS ;  i + + )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    float  dest ; 
 
					 
					 
					 
					    if  ( code_seen ( axis_codes [ i ] ) ) 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( code_seen ( axis_codes [ i ] ) )  { 
 
					 
					 
					 
					      destination [ i ]  =  code_value ( )  +  ( axis_relative_modes [ i ]  | |  relative_mode  ?  current_position [ i ]  :  0 ) ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      dest  =  code_value ( ) ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      if  ( axis_relative_modes [ i ]  | |  relative_mode ) 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        dest  + =  current_position [ i ] ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    else 
 
					 
					 
					 
					    else 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      dest  =  current_position [ i ] ; 
 
					 
					 
					 
					      destination [ i ]  =  current_position [ i ] ; 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    destination [ i ]  =  dest ; 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					  } 
 
					 
					 
					 
					  } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  if  ( code_seen ( ' F ' ) )  { 
 
					 
					 
					 
					  if  ( code_seen ( ' F ' ) )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    next_feedrate  =  code_value ( ) ; 
 
					 
					 
					 
					    next_feedrate  =  code_value ( ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -5522,7 +5480,7 @@ for (int s = 1; s <= steps; s++) {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      plan_set_position ( inactive_extruder_x_pos ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ] ) ; 
 
					 
					 
					 
					      plan_set_position ( inactive_extruder_x_pos ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ] ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      plan_buffer_line ( current_position [ X_AXIS ]  +  duplicate_extruder_x_offset ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] , 
 
					 
					 
					 
					      plan_buffer_line ( current_position [ X_AXIS ]  +  duplicate_extruder_x_offset ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          current_position [ E_AXIS ] ,  max_feedrate [ X_AXIS ] ,  1 ) ; 
 
					 
					 
					 
					          current_position [ E_AXIS ] ,  max_feedrate [ X_AXIS ] ,  1 ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      plan_set_position( current_position [ X_AXIS ] ,  current_position [ Y_AXIS ] ,  current_position [ Z_AXIS ] ,  current_position [ E_AXIS ]  ) ; 
 
					 
					 
					 
					      sync_plan_position(  ) ; 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      st_synchronize ( ) ; 
 
					 
					 
					 
					      st_synchronize ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      extruder_duplication_enabled  =  true ; 
 
					 
					 
					 
					      extruder_duplication_enabled  =  true ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      active_extruder_parked  =  false ; 
 
					 
					 
					 
					      active_extruder_parked  =  false ;