瀏覽代碼

Always switch to tool 0 for G28

Scott Lahteine 9 年之前
父節點
當前提交
d2e9a9c188
共有 1 個檔案被更改,包括 52 行新增30 行删除
  1. 52
    30
      Marlin/Marlin_main.cpp

+ 52
- 30
Marlin/Marlin_main.cpp 查看文件

@@ -572,6 +572,7 @@ void serial_echopair_P(const char* s_P, float v)         { serialprintPGM(s_P);
572 572
 void serial_echopair_P(const char* s_P, double v)        { serialprintPGM(s_P); SERIAL_ECHO(v); }
573 573
 void serial_echopair_P(const char* s_P, unsigned long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
574 574
 
575
+void tool_change(const uint8_t tmp_extruder, const float fr_mm_m=0.0, bool no_move=false);
575 576
 static void report_current_position();
576 577
 
577 578
 #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -2882,6 +2883,12 @@ inline void gcode_G28() {
2882 2883
     #endif
2883 2884
   #endif
2884 2885
 
2886
+  // Always home with tool 0 active
2887
+  #if HOTENDS > 1
2888
+    uint8_t old_tool_index = active_extruder;
2889
+    tool_change(0, 0, true);
2890
+  #endif
2891
+
2885 2892
   /**
2886 2893
    * For mesh bed leveling deactivate the mesh calculations, will be turned
2887 2894
    * on again when homing all axis
@@ -3185,6 +3192,11 @@ inline void gcode_G28() {
3185 3192
     if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G28");
3186 3193
   #endif
3187 3194
 
3195
+  // Restore the active tool after homing
3196
+  #if HOTENDS > 1
3197
+    tool_change(old_tool_index, 0, true);
3198
+  #endif
3199
+
3188 3200
   report_current_position();
3189 3201
 }
3190 3202
 
@@ -6666,13 +6678,7 @@ inline void invalid_extruder_error(const uint8_t &e) {
6666 6678
   SERIAL_ECHOLN(MSG_INVALID_EXTRUDER);
6667 6679
 }
6668 6680
 
6669
-/**
6670
- * T0-T3: Switch tool, usually switching extruders
6671
- *
6672
- *   F[units/min] Set the movement feedrate
6673
- *   S1           Don't move the tool in XY after change
6674
- */
6675
-inline void gcode_T(uint8_t tmp_extruder) {
6681
+void tool_change(const uint8_t tmp_extruder, const float fr_mm_m/*=0.0*/, bool no_move/*=false*/) {
6676 6682
 
6677 6683
   #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
6678 6684
 
@@ -6687,14 +6693,6 @@ inline void gcode_T(uint8_t tmp_extruder) {
6687 6693
 
6688 6694
   #else //!MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1
6689 6695
 
6690
-    #if ENABLED(DEBUG_LEVELING_FEATURE)
6691
-      if (DEBUGGING(LEVELING)) {
6692
-        SERIAL_ECHOPAIR(">>> gcode_T(", tmp_extruder);
6693
-        SERIAL_ECHOLNPGM(")");
6694
-        DEBUG_POS("BEFORE", current_position);
6695
-      }
6696
-    #endif
6697
-
6698 6696
     #if HOTENDS > 1
6699 6697
 
6700 6698
       if (tmp_extruder >= EXTRUDERS) {
@@ -6704,16 +6702,9 @@ inline void gcode_T(uint8_t tmp_extruder) {
6704 6702
 
6705 6703
       float old_feedrate_mm_m = feedrate_mm_m;
6706 6704
 
6707
-      if (code_seen('F')) {
6708
-        float next_feedrate_mm_m = code_value_axis_units(X_AXIS);
6709
-        if (next_feedrate_mm_m > 0.0) old_feedrate_mm_m = feedrate_mm_m = next_feedrate_mm_m;
6710
-      }
6711
-      else
6712
-        feedrate_mm_m = XY_PROBE_FEEDRATE_MM_M;
6705
+      feedrate_mm_m = fr_mm_m > 0.0 ? (old_feedrate_mm_m = fr_mm_m) : XY_PROBE_FEEDRATE_MM_M;
6713 6706
 
6714 6707
       if (tmp_extruder != active_extruder) {
6715
-        bool no_move = code_seen('S') && code_value_bool();
6716
-
6717 6708
         if (!no_move && axis_unhomed_error(true, true, true)) {
6718 6709
           SERIAL_ECHOLNPGM("No move on toolchange");
6719 6710
           no_move = true;
@@ -6970,13 +6961,6 @@ inline void gcode_T(uint8_t tmp_extruder) {
6970 6961
 
6971 6962
     #endif // HOTENDS <= 1
6972 6963
 
6973
-    #if ENABLED(DEBUG_LEVELING_FEATURE)
6974
-      if (DEBUGGING(LEVELING)) {
6975
-        DEBUG_POS("AFTER", current_position);
6976
-        SERIAL_ECHOLNPGM("<<< gcode_T");
6977
-      }
6978
-    #endif
6979
-
6980 6964
     SERIAL_ECHO_START;
6981 6965
     SERIAL_ECHOPGM(MSG_ACTIVE_EXTRUDER);
6982 6966
     SERIAL_PROTOCOLLN((int)active_extruder);
@@ -6985,6 +6969,44 @@ inline void gcode_T(uint8_t tmp_extruder) {
6985 6969
 }
6986 6970
 
6987 6971
 /**
6972
+ * T0-T3: Switch tool, usually switching extruders
6973
+ *
6974
+ *   F[units/min] Set the movement feedrate
6975
+ *   S1           Don't move the tool in XY after change
6976
+ */
6977
+inline void gcode_T(uint8_t tmp_extruder) {
6978
+
6979
+  #if ENABLED(DEBUG_LEVELING_FEATURE)
6980
+    if (DEBUGGING(LEVELING)) {
6981
+      SERIAL_ECHOPAIR(">>> gcode_T(", tmp_extruder);
6982
+      SERIAL_ECHOLNPGM(")");
6983
+      DEBUG_POS("BEFORE", current_position);
6984
+    }
6985
+  #endif
6986
+
6987
+  #if HOTENDS == 1 || (ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1)
6988
+
6989
+    tool_change(tmp_extruder);
6990
+
6991
+  #elif HOTENDS > 1
6992
+
6993
+    tool_change(
6994
+      tmp_extruder,
6995
+      code_seen('F') ? code_value_axis_units(X_AXIS) : 0.0,
6996
+      (tmp_extruder == active_extruder) || (code_seen('S') && code_value_bool())
6997
+    );
6998
+
6999
+  #endif
7000
+
7001
+  #if ENABLED(DEBUG_LEVELING_FEATURE)
7002
+    if (DEBUGGING(LEVELING)) {
7003
+      DEBUG_POS("AFTER", current_position);
7004
+      SERIAL_ECHOLNPGM("<<< gcode_T");
7005
+    }
7006
+  #endif
7007
+}
7008
+
7009
+/**
6988 7010
  * Process a single command and dispatch it to its handler
6989 7011
  * This is called from the main loop()
6990 7012
  */

Loading…
取消
儲存