Browse Source

Always switch to tool 0 for G28

Scott Lahteine 9 years ago
parent
commit
d2e9a9c188
1 changed files with 52 additions and 30 deletions
  1. 52
    30
      Marlin/Marlin_main.cpp

+ 52
- 30
Marlin/Marlin_main.cpp View File

572
 void serial_echopair_P(const char* s_P, double v)        { serialprintPGM(s_P); SERIAL_ECHO(v); }
572
 void serial_echopair_P(const char* s_P, double v)        { serialprintPGM(s_P); SERIAL_ECHO(v); }
573
 void serial_echopair_P(const char* s_P, unsigned long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
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
 static void report_current_position();
576
 static void report_current_position();
576
 
577
 
577
 #if ENABLED(DEBUG_LEVELING_FEATURE)
578
 #if ENABLED(DEBUG_LEVELING_FEATURE)
2882
     #endif
2883
     #endif
2883
   #endif
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
    * For mesh bed leveling deactivate the mesh calculations, will be turned
2893
    * For mesh bed leveling deactivate the mesh calculations, will be turned
2887
    * on again when homing all axis
2894
    * on again when homing all axis
3185
     if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G28");
3192
     if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G28");
3186
   #endif
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
   report_current_position();
3200
   report_current_position();
3189
 }
3201
 }
3190
 
3202
 
6666
   SERIAL_ECHOLN(MSG_INVALID_EXTRUDER);
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
   #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
6683
   #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
6678
 
6684
 
6687
 
6693
 
6688
   #else //!MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1
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
     #if HOTENDS > 1
6696
     #if HOTENDS > 1
6699
 
6697
 
6700
       if (tmp_extruder >= EXTRUDERS) {
6698
       if (tmp_extruder >= EXTRUDERS) {
6704
 
6702
 
6705
       float old_feedrate_mm_m = feedrate_mm_m;
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
       if (tmp_extruder != active_extruder) {
6707
       if (tmp_extruder != active_extruder) {
6715
-        bool no_move = code_seen('S') && code_value_bool();
6716
-
6717
         if (!no_move && axis_unhomed_error(true, true, true)) {
6708
         if (!no_move && axis_unhomed_error(true, true, true)) {
6718
           SERIAL_ECHOLNPGM("No move on toolchange");
6709
           SERIAL_ECHOLNPGM("No move on toolchange");
6719
           no_move = true;
6710
           no_move = true;
6970
 
6961
 
6971
     #endif // HOTENDS <= 1
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
     SERIAL_ECHO_START;
6964
     SERIAL_ECHO_START;
6981
     SERIAL_ECHOPGM(MSG_ACTIVE_EXTRUDER);
6965
     SERIAL_ECHOPGM(MSG_ACTIVE_EXTRUDER);
6982
     SERIAL_PROTOCOLLN((int)active_extruder);
6966
     SERIAL_PROTOCOLLN((int)active_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
  * Process a single command and dispatch it to its handler
7010
  * Process a single command and dispatch it to its handler
6989
  * This is called from the main loop()
7011
  * This is called from the main loop()
6990
  */
7012
  */

Loading…
Cancel
Save