Przeglądaj źródła

Optimize target_extruder, ignore T with mixing (#12432)

* Optimize target_extruder, ignore T with mixing
* Give G-code Tn parity with tool_change
Scott Lahteine 6 lat temu
rodzic
commit
d2bb53702a
No account linked to committer's email address

+ 8
- 5
Marlin/src/gcode/config/M200-M205.cpp Wyświetl plik

@@ -34,7 +34,8 @@
34 34
    */
35 35
   void GcodeSuite::M200() {
36 36
 
37
-    if (get_target_extruder_from_command()) return;
37
+    const int8_t target_extruder = get_target_extruder_from_command();
38
+    if (target_extruder < 0) return;
38 39
 
39 40
     if (parser.seen('D')) {
40 41
       // setting any extruder filament size disables volumetric on the assumption that
@@ -55,11 +56,12 @@
55 56
  */
56 57
 void GcodeSuite::M201() {
57 58
 
58
-  GET_TARGET_EXTRUDER();
59
+  const int8_t target_extruder = get_target_extruder_from_command();
60
+  if (target_extruder < 0) return;
59 61
 
60 62
   LOOP_XYZE(i) {
61 63
     if (parser.seen(axis_codes[i])) {
62
-      const uint8_t a = i + (i == E_AXIS ? TARGET_EXTRUDER : 0);
64
+      const uint8_t a = (i == E_AXIS ? E_AXIS_N(target_extruder) : i);
63 65
       planner.settings.max_acceleration_mm_per_s2[a] = parser.value_axis_units((AxisEnum)a);
64 66
     }
65 67
   }
@@ -74,11 +76,12 @@ void GcodeSuite::M201() {
74 76
  */
75 77
 void GcodeSuite::M203() {
76 78
 
77
-  GET_TARGET_EXTRUDER();
79
+  const int8_t target_extruder = get_target_extruder_from_command();
80
+  if (target_extruder < 0) return;
78 81
 
79 82
   LOOP_XYZE(i)
80 83
     if (parser.seen(axis_codes[i])) {
81
-      const uint8_t a = i + (i == E_AXIS ? TARGET_EXTRUDER : 0);
84
+      const uint8_t a = (i == E_AXIS ? E_AXIS_N(target_extruder) : i);
82 85
       planner.settings.max_feedrate_mm_s[a] = parser.value_axis_units((AxisEnum)a);
83 86
     }
84 87
 }

+ 3
- 1
Marlin/src/gcode/config/M218.cpp Wyświetl plik

@@ -40,7 +40,9 @@
40 40
  *   Z<zoffset>
41 41
  */
42 42
 void GcodeSuite::M218() {
43
-  if (get_target_extruder_from_command() || target_extruder == 0) return;
43
+
44
+  const int8_t target_extruder = get_target_extruder_from_command();
45
+  if (target_extruder < 0) return;
44 46
 
45 47
   if (parser.seenval('X')) hotend_offset[X_AXIS][target_extruder] = parser.value_linear_units();
46 48
   if (parser.seenval('Y')) hotend_offset[Y_AXIS][target_extruder] = parser.value_linear_units();

+ 4
- 1
Marlin/src/gcode/config/M221.cpp Wyświetl plik

@@ -27,7 +27,10 @@
27 27
  * M221: Set extrusion percentage (M221 T0 S95)
28 28
  */
29 29
 void GcodeSuite::M221() {
30
-  if (get_target_extruder_from_command()) return;
30
+
31
+  const int8_t target_extruder = get_target_extruder_from_command();
32
+  if (target_extruder < 0) return;
33
+
31 34
   if (parser.seenval('S')) {
32 35
     planner.flow_percentage[target_extruder] = parser.value_int();
33 36
     planner.refresh_e_factor(target_extruder);

+ 7
- 6
Marlin/src/gcode/config/M92.cpp Wyświetl plik

@@ -31,21 +31,22 @@
31 31
  */
32 32
 void GcodeSuite::M92() {
33 33
 
34
-  GET_TARGET_EXTRUDER();
34
+  const int8_t target_extruder = get_target_extruder_from_command();
35
+  if (target_extruder < 0) return;
35 36
 
36 37
   LOOP_XYZE(i) {
37 38
     if (parser.seen(axis_codes[i])) {
38 39
       if (i == E_AXIS) {
39
-        const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS + TARGET_EXTRUDER));
40
+        const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS_N(target_extruder)));
40 41
         if (value < 20) {
41
-          float factor = planner.settings.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] / value; // increase e constants if M92 E14 is given for netfab.
42
+          float factor = planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] / value; // increase e constants if M92 E14 is given for netfab.
42 43
           #if HAS_CLASSIC_JERK && (DISABLED(JUNCTION_DEVIATION) || DISABLED(LIN_ADVANCE))
43 44
             planner.max_jerk[E_AXIS] *= factor;
44 45
           #endif
45
-          planner.settings.max_feedrate_mm_s[E_AXIS + TARGET_EXTRUDER] *= factor;
46
-          planner.max_acceleration_steps_per_s2[E_AXIS + TARGET_EXTRUDER] *= factor;
46
+          planner.settings.max_feedrate_mm_s[E_AXIS_N(target_extruder)] *= factor;
47
+          planner.max_acceleration_steps_per_s2[E_AXIS_N(target_extruder)] *= factor;
47 48
         }
48
-        planner.settings.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] = value;
49
+        planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] = value;
49 50
       }
50 51
       else {
51 52
         planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i);

+ 7
- 7
Marlin/src/gcode/control/T.cpp Wyświetl plik

@@ -33,27 +33,27 @@
33 33
  *   F[units/min] Set the movement feedrate
34 34
  *   S1           Don't move the tool in XY after change
35 35
  */
36
-void GcodeSuite::T(const uint8_t tmp_extruder) {
36
+void GcodeSuite::T(const uint8_t tool_index) {
37 37
 
38 38
   #if ENABLED(DEBUG_LEVELING_FEATURE)
39 39
     if (DEBUGGING(LEVELING)) {
40
-      SERIAL_ECHOPAIR(">>> T(", tmp_extruder);
40
+      SERIAL_ECHOPAIR(">>> T(", tool_index);
41 41
       SERIAL_CHAR(')');
42 42
       SERIAL_EOL();
43 43
       DEBUG_POS("BEFORE", current_position);
44 44
     }
45 45
   #endif
46 46
 
47
-  #if HOTENDS == 1 || (ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1)
47
+  #if EXTRUDERS < 2
48 48
 
49
-    tool_change(tmp_extruder);
49
+    tool_change(tool_index);
50 50
 
51
-  #elif HOTENDS > 1
51
+  #else
52 52
 
53 53
     tool_change(
54
-      tmp_extruder,
54
+      tool_index,
55 55
       MMM_TO_MMS(parser.linearval('F')),
56
-      (tmp_extruder == active_extruder) || parser.boolval('S')
56
+      (tool_index == active_extruder) || parser.boolval('S')
57 57
     );
58 58
 
59 59
   #endif

+ 2
- 1
Marlin/src/gcode/feature/pause/M600.cpp Wyświetl plik

@@ -54,7 +54,8 @@
54 54
 void GcodeSuite::M600() {
55 55
   point_t park_point = NOZZLE_PARK_POINT;
56 56
 
57
-  if (get_target_extruder_from_command()) return;
57
+  const int8_t target_extruder = get_target_extruder_from_command();
58
+  if (target_extruder < 0) return;
58 59
 
59 60
   #if ENABLED(DUAL_X_CARRIAGE)
60 61
     int8_t DXC_ext = target_extruder;

+ 2
- 1
Marlin/src/gcode/feature/pause/M603.cpp Wyświetl plik

@@ -43,7 +43,8 @@
43 43
  */
44 44
 void GcodeSuite::M603() {
45 45
 
46
-  if (get_target_extruder_from_command()) return;
46
+  const int8_t target_extruder = get_target_extruder_from_command();
47
+  if (target_extruder < 0) return;
47 48
 
48 49
   // Unload length
49 50
   if (parser.seen('U')) {

+ 7
- 4
Marlin/src/gcode/feature/pause/M701_M702.cpp Wyświetl plik

@@ -55,7 +55,9 @@ void GcodeSuite::M701() {
55 55
     if (axis_unhomed_error()) park_point.z = 0;
56 56
   #endif
57 57
 
58
-  if (get_target_extruder_from_command()) return;
58
+  const int8_t target_extruder = get_target_extruder_from_command();
59
+  if (target_extruder < 0) return;
60
+
59 61
 
60 62
   // Z axis lift
61 63
   if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
@@ -121,7 +123,8 @@ void GcodeSuite::M702() {
121 123
     if (axis_unhomed_error()) park_point.z = 0;
122 124
   #endif
123 125
 
124
-  if (get_target_extruder_from_command()) return;
126
+  const int8_t target_extruder = get_target_extruder_from_command();
127
+  if (target_extruder < 0) return;
125 128
 
126 129
   // Z axis lift
127 130
   if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
@@ -154,8 +157,8 @@ void GcodeSuite::M702() {
154 157
   #endif
155 158
   {
156 159
     // Unload length
157
-    const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) :
158
-                                                        fc_settings[target_extruder].unload_length);
160
+    const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
161
+                                                      : fc_settings[target_extruder].unload_length);
159 162
 
160 163
     unload_filament(unload_length, true, ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT);
161 164
   }

+ 2
- 1
Marlin/src/gcode/feature/trinamic/M906.cpp Wyświetl plik

@@ -73,7 +73,8 @@ void GcodeSuite::M906() {
73 73
         #endif
74 74
         break;
75 75
       case E_AXIS: {
76
-        if (get_target_extruder_from_command()) return;
76
+        const int8_t target_extruder = get_target_extruder_from_command();
77
+        if (target_extruder < 0) return;
77 78
         switch (target_extruder) {
78 79
           #if AXIS_IS_TMC(E0)
79 80
             case 0: TMC_SET_CURRENT(E0); break;

+ 2
- 1
Marlin/src/gcode/feature/trinamic/M911-M915.cpp Wyświetl plik

@@ -232,7 +232,8 @@
232 232
           #endif
233 233
           break;
234 234
         case E_AXIS: {
235
-          if (get_target_extruder_from_command()) return;
235
+          const int8_t target_extruder = get_target_extruder_from_command();
236
+          if (target_extruder < 0) return;
236 237
           switch (target_extruder) {
237 238
             #if AXIS_HAS_STEALTHCHOP(E0)
238 239
               case 0: TMC_SET_PWMTHRS_E(0); break;

+ 9
- 12
Marlin/src/gcode/gcode.cpp Wyświetl plik

@@ -38,7 +38,6 @@ GcodeSuite gcode;
38 38
 
39 39
 #include "../Marlin.h" // for idle() and suspend_auto_report
40 40
 
41
-uint8_t GcodeSuite::target_extruder;
42 41
 millis_t GcodeSuite::previous_move_ms;
43 42
 
44 43
 bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
@@ -58,11 +57,10 @@ bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
58 57
 #endif
59 58
 
60 59
 /**
61
- * Set target_extruder from the T parameter or the active_extruder
62
- *
63
- * Returns TRUE if the target is invalid
60
+ * Get the target extruder from the T parameter or the active_extruder
61
+ * Return -1 if the T parameter is out of range
64 62
  */
65
-bool GcodeSuite::get_target_extruder_from_command() {
63
+int8_t GcodeSuite::get_target_extruder_from_command() {
66 64
   if (parser.seenval('T')) {
67 65
     const int8_t e = parser.value_byte();
68 66
     if (e >= EXTRUDERS) {
@@ -70,14 +68,11 @@ bool GcodeSuite::get_target_extruder_from_command() {
70 68
       SERIAL_CHAR('M');
71 69
       SERIAL_ECHO(parser.codenum);
72 70
       SERIAL_ECHOLNPAIR(" " MSG_INVALID_EXTRUDER " ", e);
73
-      return true;
71
+      return -1;
74 72
     }
75
-    target_extruder = e;
73
+    return e;
76 74
   }
77
-  else
78
-    target_extruder = active_extruder;
79
-
80
-  return false;
75
+  return active_extruder;
81 76
 }
82 77
 
83 78
 /**
@@ -539,7 +534,9 @@ void GcodeSuite::process_parsed_command(
539 534
         case 302: M302(); break;                                  // M302: Allow cold extrudes (set the minimum extrude temperature)
540 535
       #endif
541 536
 
542
-      case 303: M303(); break;                                    // M303: PID autotune
537
+      #if HAS_PID_HEATING
538
+        case 303: M303(); break;                                  // M303: PID autotune
539
+      #endif
543 540
 
544 541
       #if ENABLED(MORGAN_SCARA)
545 542
         case 360: if (M360()) return; break;                      // M360: SCARA Theta pos1

+ 6
- 16
Marlin/src/gcode/gcode.h Wyświetl plik

@@ -267,8 +267,6 @@ public:
267 267
 
268 268
   GcodeSuite() {}
269 269
 
270
-  static uint8_t target_extruder;
271
-
272 270
   static bool axis_relative_modes[];
273 271
 
274 272
   #if ENABLED(CNC_WORKSPACE_PLANES)
@@ -290,8 +288,9 @@ public:
290 288
   static millis_t previous_move_ms;
291 289
   FORCE_INLINE static void reset_stepper_timeout() { previous_move_ms = millis(); }
292 290
 
293
-  static bool get_target_extruder_from_command();
291
+  static int8_t get_target_extruder_from_command();
294 292
   static void get_destination_from_command();
293
+
295 294
   static void process_parsed_command(
296 295
     #if USE_EXECUTE_COMMANDS_IMMEDIATE
297 296
       const bool no_ok = false
@@ -306,17 +305,6 @@ public:
306 305
 
307 306
   FORCE_INLINE static void home_all_axes() { G28(true); }
308 307
 
309
-  /**
310
-   * Multi-stepper support for M92, M201, M203
311
-   */
312
-  #if ENABLED(DISTINCT_E_FACTORS)
313
-    #define GET_TARGET_EXTRUDER() if (gcode.get_target_extruder_from_command()) return
314
-    #define TARGET_EXTRUDER gcode.target_extruder
315
-  #else
316
-    #define GET_TARGET_EXTRUDER() NOOP
317
-    #define TARGET_EXTRUDER 0
318
-  #endif
319
-
320 308
   #if ENABLED(HOST_KEEPALIVE_FEATURE)
321 309
     /**
322 310
      * States for managing Marlin and host communication
@@ -669,7 +657,9 @@ private:
669 657
     static void M302();
670 658
   #endif
671 659
 
672
-  static void M303();
660
+  #if HAS_PID_HEATING
661
+    static void M303();
662
+  #endif
673 663
 
674 664
   #if ENABLED(PIDTEMPBED)
675 665
     static void M304();
@@ -832,7 +822,7 @@ private:
832 822
 
833 823
   static void M999();
834 824
 
835
-  static void T(const uint8_t tmp_extruder);
825
+  static void T(const uint8_t tool_index);
836 826
 
837 827
 };
838 828
 

+ 14
- 3
Marlin/src/gcode/temperature/M104_M109.cpp Wyświetl plik

@@ -39,10 +39,15 @@
39 39
  * M104: Set hot end temperature
40 40
  */
41 41
 void GcodeSuite::M104() {
42
-  if (get_target_extruder_from_command()) return;
42
+
43 43
   if (DEBUGGING(DRYRUN)) return;
44 44
 
45
-  const uint8_t e = target_extruder;
45
+  #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
46
+    constexpr int8_t e = 0;
47
+  #else
48
+    const int8_t e = get_target_extruder_from_command();
49
+    if (e < 0) return;
50
+  #endif
46 51
 
47 52
   if (parser.seenval('S')) {
48 53
     const int16_t temp = parser.value_celsius();
@@ -82,9 +87,15 @@ void GcodeSuite::M104() {
82 87
  */
83 88
 void GcodeSuite::M109() {
84 89
 
85
-  if (get_target_extruder_from_command()) return;
86 90
   if (DEBUGGING(DRYRUN)) return;
87 91
 
92
+  #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
93
+    constexpr int8_t target_extruder = 0;
94
+  #else
95
+    const int8_t target_extruder = get_target_extruder_from_command();
96
+    if (target_extruder < 0) return;
97
+  #endif
98
+
88 99
   const bool no_wait_for_cooling = parser.seenval('S'),
89 100
              set_temp = no_wait_for_cooling || parser.seenval('R');
90 101
   if (set_temp) {

+ 5
- 3
Marlin/src/gcode/temperature/M105.cpp Wyświetl plik

@@ -31,7 +31,9 @@
31 31
  * M105: Read hot end and bed temperature
32 32
  */
33 33
 void GcodeSuite::M105() {
34
-  if (get_target_extruder_from_command()) return;
34
+
35
+  const int8_t target_extruder = get_target_extruder_from_command();
36
+  if (target_extruder < 0) return;
35 37
 
36 38
   #if NUM_SERIAL > 1
37 39
     const int16_t port = command_queue_port[cmd_queue_index_r];
@@ -39,9 +41,9 @@ void GcodeSuite::M105() {
39 41
 
40 42
   #if HAS_TEMP_SENSOR
41 43
     SERIAL_PROTOCOLPGM_P(port, MSG_OK);
42
-    thermalManager.print_heaterstates(
44
+    thermalManager.print_heater_states(target_extruder
43 45
       #if NUM_SERIAL > 1
44
-        port
46
+        , port
45 47
       #endif
46 48
     );
47 49
   #else // !HAS_TEMP_SENSOR

+ 30
- 16
Marlin/src/gcode/temperature/M303.cpp Wyświetl plik

@@ -20,6 +20,10 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "../../inc/MarlinConfig.h"
24
+
25
+#if HAS_PID_HEATING
26
+
23 27
 #include "../gcode.h"
24 28
 #include "../../module/temperature.h"
25 29
 
@@ -32,26 +36,36 @@
32 36
  *       U<bool> with a non-zero value will apply the result to current settings
33 37
  */
34 38
 void GcodeSuite::M303() {
35
-  #if HAS_PID_HEATING
36
-    const int e = parser.intval('E'), c = parser.intval('C', 5);
37
-    const bool u = parser.boolval('U');
38
-
39
-    int16_t temp = parser.celsiusval('S', e < 0 ? 70 : 150);
40 39
 
41
-    if (WITHIN(e, 0, HOTENDS - 1))
42
-      target_extruder = e;
40
+  const int8_t e = parser.byteval('E');
43 41
 
44
-    #if DISABLED(BUSY_WHILE_HEATING)
45
-      KEEPALIVE_STATE(NOT_BUSY);
42
+  if (!WITHIN(e, 0
43
+    #if ENABLED(PIDTEMPBED)
44
+      -1
46 45
     #endif
46
+    ,
47
+    #if ENABLED(PIDTEMP)
48
+      HOTENDS
49
+    #endif
50
+    -1
51
+  )) {
52
+    SERIAL_ECHOLNPGM(MSG_PID_BAD_EXTRUDER_NUM);
53
+    return;
54
+  }
47 55
 
48
-    thermalManager.PID_autotune(temp, e, c, u);
56
+  const int c = parser.intval('C', 5);
57
+  const bool u = parser.boolval('U');
58
+  const int16_t temp = parser.celsiusval('S', e < 0 ? 70 : 150);
49 59
 
50
-    #if DISABLED(BUSY_WHILE_HEATING)
51
-      KEEPALIVE_STATE(IN_HANDLER);
52
-    #endif
53
-  #else
54
-    SERIAL_ERROR_START();
55
-    SERIAL_ERRORLNPGM(MSG_ERR_M303_DISABLED);
60
+  #if DISABLED(BUSY_WHILE_HEATING)
61
+    KEEPALIVE_STATE(NOT_BUSY);
62
+  #endif
63
+
64
+  thermalManager.PID_autotune(temp, e, c, u);
65
+
66
+  #if DISABLED(BUSY_WHILE_HEATING)
67
+    KEEPALIVE_STATE(IN_HANDLER);
56 68
   #endif
57 69
 }
70
+
71
+#endif // HAS_PID_HEATING

+ 33
- 51
Marlin/src/module/temperature.cpp Wyświetl plik

@@ -236,7 +236,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
236 236
    * Alternately heat and cool the nozzle, observing its behavior to
237 237
    * determine the best PID values to achieve a stable temperature.
238 238
    */
239
-  void Temperature::PID_autotune(const float &target, const int8_t hotend, const int8_t ncycles, const bool set_result/*=false*/) {
239
+  void Temperature::PID_autotune(const float &target, const int8_t heater, const int8_t ncycles, const bool set_result/*=false*/) {
240 240
     float current = 0.0;
241 241
     int cycles = 0;
242 242
     bool heating = true;
@@ -249,10 +249,10 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
249 249
     float max = 0, min = 10000;
250 250
 
251 251
     #if HAS_PID_FOR_BOTH
252
-      #define GHV(B,H) (hotend < 0 ? (B) : (H))
253
-      #define SHV(S,B,H) do{ if (hotend < 0) S##_bed = B; else S [hotend] = H; }while(0)
254
-      #define ONHEATINGSTART() (hotend < 0 ? printerEventLEDs.onBedHeatingStart() : printerEventLEDs.onHotendHeatingStart())
255
-      #define ONHEATING(S,C,T) do{ if (hotend < 0) printerEventLEDs.onBedHeating(S,C,T); else printerEventLEDs.onHotendHeating(S,C,T); }while(0)
252
+      #define GHV(B,H) (heater < 0 ? (B) : (H))
253
+      #define SHV(S,B,H) do{ if (heater < 0) S##_bed = B; else S [heater] = H; }while(0)
254
+      #define ONHEATINGSTART() (heater < 0 ? printerEventLEDs.onBedHeatingStart() : printerEventLEDs.onHotendHeatingStart())
255
+      #define ONHEATING(S,C,T) do{ if (heater < 0) printerEventLEDs.onBedHeating(S,C,T); else printerEventLEDs.onHotendHeating(S,C,T); }while(0)
256 256
     #elif ENABLED(PIDTEMPBED)
257 257
       #define GHV(B,H) B
258 258
       #define SHV(S,B,H) (S##_bed = B)
@@ -260,7 +260,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
260 260
       #define ONHEATING(S,C,T) printerEventLEDs.onBedHeating(S,C,T)
261 261
     #else
262 262
       #define GHV(B,H) H
263
-      #define SHV(S,B,H) (S [hotend] = H)
263
+      #define SHV(S,B,H) (S [heater] = H)
264 264
       #define ONHEATINGSTART() printerEventLEDs.onHotendHeatingStart()
265 265
       #define ONHEATING(S,C,T) printerEventLEDs.onHotendHeating(S,C,T)
266 266
     #endif
@@ -268,7 +268,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
268 268
     #if WATCH_THE_BED || WATCH_HOTENDS
269 269
       #define HAS_TP_BED (ENABLED(THERMAL_PROTECTION_BED) && ENABLED(PIDTEMPBED))
270 270
       #if HAS_TP_BED && ENABLED(THERMAL_PROTECTION_HOTENDS) && ENABLED(PIDTEMP)
271
-        #define GTV(B,H) (hotend < 0 ? (B) : (H))
271
+        #define GTV(B,H) (heater < 0 ? (B) : (H))
272 272
       #elif HAS_TP_BED
273 273
         #define GTV(B,H) (B)
274 274
       #else
@@ -286,22 +286,6 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
286 286
       next_auto_fan_check_ms = next_temp_ms + 2500UL;
287 287
     #endif
288 288
 
289
-    #if ENABLED(PIDTEMP)
290
-      #define _TOP_HOTEND HOTENDS - 1
291
-    #else
292
-      #define _TOP_HOTEND -1
293
-    #endif
294
-    #if ENABLED(PIDTEMPBED)
295
-      #define _BOT_HOTEND -1
296
-    #else
297
-      #define _BOT_HOTEND 0
298
-    #endif
299
-
300
-    if (!WITHIN(hotend, _BOT_HOTEND, _TOP_HOTEND)) {
301
-      SERIAL_ECHOLNPGM(MSG_PID_BAD_EXTRUDER_NUM);
302
-      return;
303
-    }
304
-
305 289
     SERIAL_ECHOLNPGM(MSG_PID_AUTOTUNE_START);
306 290
 
307 291
     disable_all_heaters();
@@ -310,7 +294,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
310 294
 
311 295
     wait_for_heatup = true; // Can be interrupted with M108
312 296
     #if ENABLED(PRINTER_EVENT_LEDS)
313
-      const float start_temp = GHV(current_temperature_bed, current_temperature[hotend]);
297
+      const float start_temp = GHV(current_temperature_bed, current_temperature[heater]);
314 298
       LEDColor color = ONHEATINGSTART();
315 299
     #endif
316 300
 
@@ -323,7 +307,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
323 307
         updateTemperaturesFromRawValues();
324 308
 
325 309
         // Get the current temperature and constrain it
326
-        current = GHV(current_temperature_bed, current_temperature[hotend]);
310
+        current = GHV(current_temperature_bed, current_temperature[heater]);
327 311
         NOLESS(max, current);
328 312
         NOMORE(min, current);
329 313
 
@@ -412,7 +396,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
412 396
       // Report heater states every 2 seconds
413 397
       if (ELAPSED(ms, next_temp_ms)) {
414 398
         #if HAS_TEMP_SENSOR
415
-          print_heaterstates();
399
+          print_heater_states(heater >= 0 ? heater : active_extruder);
416 400
           SERIAL_EOL();
417 401
         #endif
418 402
         next_temp_ms = ms + 2000UL;
@@ -423,9 +407,9 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
423 407
             #if WATCH_THE_BED && WATCH_HOTENDS
424 408
               true
425 409
             #elif WATCH_HOTENDS
426
-              hotend >= 0
410
+              heater >= 0
427 411
             #else
428
-              hotend < 0
412
+              heater < 0
429 413
             #endif
430 414
           ) {
431 415
             if (!heated) {                                          // If not yet reached target...
@@ -435,10 +419,10 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
435 419
                 if (current > watch_temp_target) heated = true;     // - Flag if target temperature reached
436 420
               }
437 421
               else if (ELAPSED(ms, temp_change_ms))                 // Watch timer expired
438
-                _temp_error(hotend, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, hotend));
422
+                _temp_error(heater, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, heater));
439 423
             }
440 424
             else if (current < target - (MAX_OVERSHOOT_PID_AUTOTUNE)) // Heated, then temperature fell too far?
441
-              _temp_error(hotend, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, hotend));
425
+              _temp_error(heater, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, heater));
442 426
           }
443 427
         #endif
444 428
       } // every 2 seconds
@@ -477,15 +461,15 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
477 461
         }while(0)
478 462
 
479 463
         #define _SET_EXTRUDER_PID() do { \
480
-          PID_PARAM(Kp, hotend) = tune_pid.Kp; \
481
-          PID_PARAM(Ki, hotend) = scalePID_i(tune_pid.Ki); \
482
-          PID_PARAM(Kd, hotend) = scalePID_d(tune_pid.Kd); \
464
+          PID_PARAM(Kp, heater) = tune_pid.Kp; \
465
+          PID_PARAM(Ki, heater) = scalePID_i(tune_pid.Ki); \
466
+          PID_PARAM(Kd, heater) = scalePID_d(tune_pid.Kd); \
483 467
           updatePID(); }while(0)
484 468
 
485 469
         // Use the result? (As with "M303 U1")
486 470
         if (set_result) {
487 471
           #if HAS_PID_FOR_BOTH
488
-            if (hotend < 0) _SET_BED_PID(); else _SET_EXTRUDER_PID();
472
+            if (heater < 0) _SET_BED_PID(); else _SET_EXTRUDER_PID();
489 473
           #elif ENABLED(PIDTEMP)
490 474
             _SET_EXTRUDER_PID();
491 475
           #else
@@ -575,13 +559,13 @@ int Temperature::getHeaterPower(const int heater) {
575 559
 //
576 560
 // Temperature Error Handlers
577 561
 //
578
-void Temperature::_temp_error(const int8_t e, PGM_P const serial_msg, PGM_P const lcd_msg) {
562
+void Temperature::_temp_error(const int8_t heater, PGM_P const serial_msg, PGM_P const lcd_msg) {
579 563
   static bool killed = false;
580 564
   if (IsRunning()) {
581 565
     SERIAL_ERROR_START();
582 566
     serialprintPGM(serial_msg);
583 567
     SERIAL_ERRORPGM(MSG_STOPPED_HEATER);
584
-    if (e >= 0) SERIAL_ERRORLN((int)e); else SERIAL_ERRORLNPGM(MSG_HEATER_BED);
568
+    if (heater >= 0) SERIAL_ERRORLN((int)heater); else SERIAL_ERRORLNPGM(MSG_HEATER_BED);
585 569
   }
586 570
   #if DISABLED(BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE)
587 571
     if (!killed) {
@@ -594,12 +578,12 @@ void Temperature::_temp_error(const int8_t e, PGM_P const serial_msg, PGM_P cons
594 578
   #endif
595 579
 }
596 580
 
597
-void Temperature::max_temp_error(const int8_t e) {
598
-  _temp_error(e, PSTR(MSG_T_MAXTEMP), TEMP_ERR_PSTR(MSG_ERR_MAXTEMP, e));
581
+void Temperature::max_temp_error(const int8_t heater) {
582
+  _temp_error(heater, PSTR(MSG_T_MAXTEMP), TEMP_ERR_PSTR(MSG_ERR_MAXTEMP, heater));
599 583
 }
600 584
 
601
-void Temperature::min_temp_error(const int8_t e) {
602
-  _temp_error(e, PSTR(MSG_T_MINTEMP), TEMP_ERR_PSTR(MSG_ERR_MINTEMP, e));
585
+void Temperature::min_temp_error(const int8_t heater) {
586
+  _temp_error(heater, PSTR(MSG_T_MINTEMP), TEMP_ERR_PSTR(MSG_ERR_MINTEMP, heater));
603 587
 }
604 588
 
605 589
 float Temperature::get_pid_output(const int8_t e) {
@@ -2346,15 +2330,15 @@ void Temperature::isr() {
2346 2330
     delay(2);
2347 2331
   }
2348 2332
 
2349
-  void Temperature::print_heaterstates(
2333
+  void Temperature::print_heater_states(const uint8_t target_extruder
2350 2334
     #if NUM_SERIAL > 1
2351
-      const int8_t port
2335
+      , const int8_t port
2352 2336
     #endif
2353 2337
   ) {
2354 2338
     #if HAS_TEMP_HOTEND
2355
-      print_heater_state(degHotend(gcode.target_extruder), degTargetHotend(gcode.target_extruder)
2339
+      print_heater_state(degHotend(target_extruder), degTargetHotend(target_extruder)
2356 2340
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
2357
-          , rawHotendTemp(gcode.target_extruder)
2341
+          , rawHotendTemp(target_extruder)
2358 2342
         #endif
2359 2343
         #if NUM_SERIAL > 1
2360 2344
           , port
@@ -2392,7 +2376,7 @@ void Temperature::isr() {
2392 2376
       );
2393 2377
     #endif
2394 2378
     SERIAL_PROTOCOLPGM_P(port, " @:");
2395
-    SERIAL_PROTOCOL_P(port, getHeaterPower(gcode.target_extruder));
2379
+    SERIAL_PROTOCOL_P(port, getHeaterPower(target_extruder));
2396 2380
     #if HAS_HEATED_BED
2397 2381
       SERIAL_PROTOCOLPGM_P(port, " B@:");
2398 2382
       SERIAL_PROTOCOL_P(port, getHeaterPower(-1));
@@ -2414,7 +2398,7 @@ void Temperature::isr() {
2414 2398
     void Temperature::auto_report_temperatures() {
2415 2399
       if (auto_report_temp_interval && ELAPSED(millis(), next_temp_report_ms)) {
2416 2400
         next_temp_report_ms = millis() + 1000UL * auto_report_temp_interval;
2417
-        print_heaterstates();
2401
+        print_heater_states(active_extruder);
2418 2402
         SERIAL_EOL();
2419 2403
       }
2420 2404
     }
@@ -2480,9 +2464,9 @@ void Temperature::isr() {
2480 2464
         }
2481 2465
 
2482 2466
         now = millis();
2483
-        if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting
2467
+        if (ELAPSED(now, next_temp_ms)) { // Print temp & remaining time every 1s while waiting
2484 2468
           next_temp_ms = now + 1000UL;
2485
-          print_heaterstates();
2469
+          print_heater_states(target_extruder);
2486 2470
           #if TEMP_RESIDENCY_TIME > 0
2487 2471
             SERIAL_PROTOCOLPGM(" W:");
2488 2472
             if (residency_start_ms)
@@ -2587,8 +2571,6 @@ void Temperature::isr() {
2587 2571
         KEEPALIVE_STATE(NOT_BUSY);
2588 2572
       #endif
2589 2573
 
2590
-      gcode.target_extruder = active_extruder; // for print_heaterstates
2591
-
2592 2574
       #if ENABLED(PRINTER_EVENT_LEDS)
2593 2575
         const float start_temp = degBed();
2594 2576
         printerEventLEDs.onBedHeatingStart();
@@ -2607,7 +2589,7 @@ void Temperature::isr() {
2607 2589
         now = millis();
2608 2590
         if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up.
2609 2591
           next_temp_ms = now + 1000UL;
2610
-          print_heaterstates();
2592
+          print_heater_states(active_extruder);
2611 2593
           #if TEMP_BED_RESIDENCY_TIME > 0
2612 2594
             SERIAL_PROTOCOLPGM(" W:");
2613 2595
             if (residency_start_ms)

+ 2
- 2
Marlin/src/module/temperature.h Wyświetl plik

@@ -601,9 +601,9 @@ class Temperature {
601 601
     #endif // HEATER_IDLE_HANDLER
602 602
 
603 603
     #if HAS_TEMP_SENSOR
604
-      static void print_heaterstates(
604
+      static void print_heater_states(const uint8_t target_extruder
605 605
         #if NUM_SERIAL > 1
606
-          const int8_t port = -1
606
+          , const int8_t port = -1
607 607
         #endif
608 608
       );
609 609
       #if ENABLED(AUTO_REPORT_TEMPERATURES)

+ 6
- 6
Marlin/src/module/tool_change.cpp Wyświetl plik

@@ -500,8 +500,8 @@ inline void invalid_extruder_error(const uint8_t e) {
500 500
 void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) {
501 501
   #if ENABLED(MIXING_EXTRUDER)
502 502
 
503
-    UNUSED(fr_mm_s);
504
-    UNUSED(no_move);
503
+    UNUSED(fr_mm_s); UNUSED(no_move);
504
+
505 505
     if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
506 506
       return invalid_extruder_error(tmp_extruder);
507 507
 
@@ -512,12 +512,12 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
512 512
 
513 513
   #elif EXTRUDERS < 2
514 514
 
515
-    UNUSED(fr_mm_s);
516
-    UNUSED(no_move);
515
+    UNUSED(fr_mm_s); UNUSED(no_move);
516
+
517 517
     if (tmp_extruder) invalid_extruder_error(tmp_extruder);
518 518
     return;
519 519
 
520
-  #else
520
+  #else // EXTRUDERS > 1
521 521
 
522 522
     planner.synchronize();
523 523
 
@@ -751,5 +751,5 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
751 751
     SERIAL_ECHO_START();
752 752
     SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(active_extruder));
753 753
 
754
-  #endif // EXTRUDERS <= 1 && (!MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1)
754
+  #endif // EXTRUDERS > 1
755 755
 }

Ładowanie…
Anuluj
Zapisz