Browse Source

Move M163-M165 MIXING_EXTRUDER to cpp

Scott Lahteine 6 years ago
parent
commit
1a37ebc76d

+ 5
- 62
Marlin/src/Marlin.cpp View File

@@ -62,6 +62,10 @@
62 62
   #include "feature/digipot/digipot.h"
63 63
 #endif
64 64
 
65
+#if ENABLED(MIXING_EXTRUDER)
66
+  #include "feature/mixing.h"
67
+#endif
68
+
65 69
 #if ENABLED(BEZIER_CURVE_SUPPORT)
66 70
   #include "module/planner_bezier.h"
67 71
 #endif
@@ -186,13 +190,6 @@ millis_t max_inactive_time = 0,
186 190
   AdvancedPauseMenuResponse advanced_pause_menu_response;
187 191
 #endif
188 192
 
189
-#if ENABLED(MIXING_EXTRUDER)
190
-  float mixing_factor[MIXING_STEPPERS]; // Reciprocal of mix proportion. 0.0 = off, otherwise >= 1.0.
191
-  #if MIXING_VIRTUAL_TOOLS > 1
192
-    float mixing_virtual_tool_mix[MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
193
-  #endif
194
-#endif
195
-
196 193
 #ifdef CHDK
197 194
   millis_t chdkHigh = 0;
198 195
   bool chdkActive = false;
@@ -302,45 +299,6 @@ void suicide() {
302 299
 
303 300
 #endif
304 301
 
305
-#if ENABLED(MIXING_EXTRUDER)
306
-
307
-  void normalize_mix() {
308
-    float mix_total = 0.0;
309
-    for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mix_total += RECIPROCAL(mixing_factor[i]);
310
-    // Scale all values if they don't add up to ~1.0
311
-    if (!NEAR(mix_total, 1.0)) {
312
-      SERIAL_PROTOCOLLNPGM("Warning: Mix factors must add up to 1.0. Scaling.");
313
-      for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mixing_factor[i] *= mix_total;
314
-    }
315
-  }
316
-
317
-  #if ENABLED(DIRECT_MIXING_IN_G1)
318
-    // Get mixing parameters from the GCode
319
-    // The total "must" be 1.0 (but it will be normalized)
320
-    // If no mix factors are given, the old mix is preserved
321
-    void gcode_get_mix() {
322
-      const char* mixing_codes = "ABCDHI";
323
-      byte mix_bits = 0;
324
-      for (uint8_t i = 0; i < MIXING_STEPPERS; i++) {
325
-        if (parser.seenval(mixing_codes[i])) {
326
-          SBI(mix_bits, i);
327
-          float v = parser.value_float();
328
-          NOLESS(v, 0.0);
329
-          mixing_factor[i] = RECIPROCAL(v);
330
-        }
331
-      }
332
-      // If any mixing factors were included, clear the rest
333
-      // If none were included, preserve the last mix
334
-      if (mix_bits) {
335
-        for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
336
-          if (!TEST(mix_bits, i)) mixing_factor[i] = 0.0;
337
-        normalize_mix();
338
-      }
339
-    }
340
-  #endif
341
-
342
-#endif
343
-
344 302
 /**************************************************
345 303
  ***************** GCode Handlers *****************
346 304
  **************************************************/
@@ -362,16 +320,6 @@ void quickstop_stepper() {
362 320
   SYNC_PLAN_POSITION_KINEMATIC();
363 321
 }
364 322
 
365
-#if ENABLED(MIXING_EXTRUDER)
366
-  #include "gcode/feature/mixing/M163.h"
367
-  #if MIXING_VIRTUAL_TOOLS > 1
368
-    #include "gcode/feature/mixing/M164.h"
369
-  #endif
370
-  #if ENABLED(DIRECT_MIXING_IN_G1)
371
-    #include "gcode/feature/mixing/M165.h"
372
-  #endif
373
-#endif
374
-
375 323
 #include "gcode/control/M999.h"
376 324
 
377 325
 #include "gcode/control/T.h"
@@ -957,12 +905,7 @@ void setup() {
957 905
   #endif
958 906
 
959 907
   #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
960
-    // Initialize mixing to 100% color 1
961
-    for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
962
-      mixing_factor[i] = (i == 0) ? 1.0 : 0.0;
963
-    for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS; t++)
964
-      for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
965
-        mixing_virtual_tool_mix[t][i] = mixing_factor[i];
908
+    mixing_tools_init();
966 909
   #endif
967 910
 
968 911
   #if ENABLED(BLTOUCH)

+ 0
- 7
Marlin/src/Marlin.h View File

@@ -223,13 +223,6 @@ extern millis_t max_inactive_time, stepper_inactive_time;
223 223
   extern int lpq_len;
224 224
 #endif
225 225
 
226
-#if ENABLED(MIXING_EXTRUDER)
227
-  extern float mixing_factor[MIXING_STEPPERS];
228
-  #if MIXING_VIRTUAL_TOOLS > 1
229
-    extern float mixing_virtual_tool_mix[MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
230
-  #endif
231
-#endif
232
-
233 226
 void calculate_volumetric_multipliers();
234 227
 
235 228
 bool pin_is_protected(const int8_t pin);

+ 79
- 0
Marlin/src/feature/mixing.cpp View File

@@ -0,0 +1,79 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(MIXING_EXTRUDER)
26
+
27
+float mixing_factor[MIXING_STEPPERS]; // Reciprocal of mix proportion. 0.0 = off, otherwise >= 1.0.
28
+
29
+#if MIXING_VIRTUAL_TOOLS > 1
30
+
31
+  float mixing_virtual_tool_mix[MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
32
+
33
+  void mixing_tools_init() {
34
+    // Initialize mixing to 100% color 1
35
+    for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
36
+      mixing_factor[i] = (i == 0) ? 1.0 : 0.0;
37
+    for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS; t++)
38
+      for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
39
+        mixing_virtual_tool_mix[t][i] = mixing_factor[i];
40
+  }
41
+
42
+#endif // MIXING_VIRTUAL_TOOLS > 1
43
+
44
+void normalize_mix() {
45
+  float mix_total = 0.0;
46
+  for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mix_total += RECIPROCAL(mixing_factor[i]);
47
+  // Scale all values if they don't add up to ~1.0
48
+  if (!NEAR(mix_total, 1.0)) {
49
+    SERIAL_PROTOCOLLNPGM("Warning: Mix factors must add up to 1.0. Scaling.");
50
+    for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mixing_factor[i] *= mix_total;
51
+  }
52
+}
53
+
54
+#if ENABLED(DIRECT_MIXING_IN_G1)
55
+  // Get mixing parameters from the GCode
56
+  // The total "must" be 1.0 (but it will be normalized)
57
+  // If no mix factors are given, the old mix is preserved
58
+  void gcode_get_mix() {
59
+    const char mixing_codes[] = { 'A', 'B', 'C', 'D', 'H', 'I' };
60
+    byte mix_bits = 0;
61
+    for (uint8_t i = 0; i < MIXING_STEPPERS; i++) {
62
+      if (parser.seenval(mixing_codes[i])) {
63
+        SBI(mix_bits, i);
64
+        float v = parser.value_float();
65
+        NOLESS(v, 0.0);
66
+        mixing_factor[i] = RECIPROCAL(v);
67
+      }
68
+    }
69
+    // If any mixing factors were included, clear the rest
70
+    // If none were included, preserve the last mix
71
+    if (mix_bits) {
72
+      for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
73
+        if (!TEST(mix_bits, i)) mixing_factor[i] = 0.0;
74
+      normalize_mix();
75
+    }
76
+  }
77
+#endif
78
+
79
+#endif // MIXING_EXTRUDER

+ 41
- 0
Marlin/src/feature/mixing.h View File

@@ -0,0 +1,41 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifndef __MIXING_H__
24
+#define __MIXING_H__
25
+
26
+#include "../inc/MarlinConfig.h"
27
+
28
+extern float mixing_factor[MIXING_STEPPERS]; // Reciprocal of mix proportion. 0.0 = off, otherwise >= 1.0.
29
+
30
+#if MIXING_VIRTUAL_TOOLS > 1
31
+  extern float mixing_virtual_tool_mix[MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
32
+  void mixing_tools_init();
33
+#endif
34
+
35
+void normalize_mix();
36
+
37
+#if ENABLED(DIRECT_MIXING_IN_G1)
38
+  void gcode_get_mix();
39
+#endif
40
+
41
+#endif // __MIXING_H__

Marlin/src/gcode/feature/mixing/M163.h → Marlin/src/gcode/feature/mixing/M163.cpp View File

@@ -20,6 +20,13 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(MIXING_EXTRUDER)
26
+
27
+#include "../../gcode.h"
28
+#include "../../../feature/mixing.h"
29
+
23 30
 /**
24 31
  * M163: Set a single mix factor for a mixing extruder
25 32
  *       This is called "weight" by some systems.
@@ -28,7 +35,7 @@
28 35
  *   P[float]   The mix value
29 36
  *
30 37
  */
31
-void gcode_M163() {
38
+void GcodeSuite::M163() {
32 39
   const int mix_index = parser.intval('S');
33 40
   if (mix_index < MIXING_STEPPERS) {
34 41
     float mix_value = parser.floatval('P');
@@ -36,3 +43,5 @@ void gcode_M163() {
36 43
     mixing_factor[mix_index] = RECIPROCAL(mix_value);
37 44
   }
38 45
 }
46
+
47
+#endif // MIXING_EXTRUDER

Marlin/src/gcode/feature/mixing/M164.h → Marlin/src/gcode/feature/mixing/M164.cpp View File

@@ -20,13 +20,20 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
26
+
27
+#include "../../gcode.h"
28
+#include "../../../feature/mixing.h"
29
+
23 30
 /**
24 31
  * M164: Store the current mix factors as a virtual tool.
25 32
  *
26 33
  *   S[index]   The virtual tool to store
27 34
  *
28 35
  */
29
-void gcode_M164() {
36
+void GcodeSuite::M164() {
30 37
   const int tool_index = parser.intval('S');
31 38
   if (tool_index < MIXING_VIRTUAL_TOOLS) {
32 39
     normalize_mix();
@@ -34,3 +41,5 @@ void gcode_M164() {
34 41
       mixing_virtual_tool_mix[tool_index][i] = mixing_factor[i];
35 42
   }
36 43
 }
44
+
45
+#endif // MIXING_EXTRUDER && MIXING_VIRTUAL_TOOLS > 1

Marlin/src/gcode/feature/mixing/M165.h → Marlin/src/gcode/feature/mixing/M165.cpp View File

@@ -20,6 +20,13 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(DIRECT_MIXING_IN_G1)
26
+
27
+#include "../../gcode.h"
28
+#include "../../../feature/mixing.h"
29
+
23 30
 /**
24 31
  * M165: Set multiple mix factors for a mixing extruder.
25 32
  *       Factors that are left out will be set to 0.
@@ -33,4 +40,6 @@
33 40
  *   I[factor] Mix factor for extruder stepper 6
34 41
  *
35 42
  */
36
-void gcode_M165() { gcode_get_mix(); }
43
+void GcodeSuite::M165() { gcode_get_mix(); }
44
+
45
+#endif // DIRECT_MIXING_IN_G1

+ 3
- 12
Marlin/src/gcode/gcode.cpp View File

@@ -116,9 +116,6 @@ void GcodeSuite::dwell(millis_t time) {
116 116
 //
117 117
 // Placeholders for non-migrated codes
118 118
 //
119
-extern void gcode_M163();
120
-extern void gcode_M164();
121
-extern void gcode_M165();
122 119
 extern void gcode_M999();
123 120
 extern void gcode_T(uint8_t tmp_extruder);
124 121
 
@@ -462,18 +459,12 @@ void GcodeSuite::process_next_command() {
462 459
       #endif
463 460
 
464 461
       #if ENABLED(MIXING_EXTRUDER)
465
-        case 163: // M163: Set a component weight for mixing extruder
466
-          gcode_M163();
467
-          break;
462
+        case 163: M163(); break;    // M163: Set a component weight for mixing extruder
468 463
         #if MIXING_VIRTUAL_TOOLS > 1
469
-          case 164: // M164: Save current mix as a virtual extruder
470
-            gcode_M164();
471
-            break;
464
+          case 164: M164(); break;  // M164: Save current mix as a virtual extruder
472 465
         #endif
473 466
         #if ENABLED(DIRECT_MIXING_IN_G1)
474
-          case 165: // M165: Set multiple mix weights
475
-            gcode_M165();
476
-            break;
467
+          case 165: M165(); break;  // M165: Set multiple mix weights
477 468
         #endif
478 469
       #endif
479 470
 

+ 4
- 0
Marlin/src/module/planner.cpp View File

@@ -80,6 +80,10 @@
80 80
   #include "../feature/baricuda.h"
81 81
 #endif
82 82
 
83
+#if ENABLED(MIXING_EXTRUDER)
84
+  #include "../feature/mixing.h"
85
+#endif
86
+
83 87
 Planner planner;
84 88
 
85 89
   // public:

+ 4
- 0
Marlin/src/module/tool_change.cpp View File

@@ -42,6 +42,10 @@
42 42
   #include "../feature/snmm.h"
43 43
 #endif
44 44
 
45
+#if ENABLED(MIXING_EXTRUDER)
46
+  #include "../feature/mixing.h"
47
+#endif
48
+
45 49
 #if ENABLED(SWITCHING_EXTRUDER)
46 50
 
47 51
   #if EXTRUDERS > 3

Loading…
Cancel
Save