Kaynağa Gözat

Pre-apply cosmetic changes to mixing

Scott Lahteine 6 yıl önce
ebeveyn
işleme
a5e3384691

+ 1
- 1
Marlin/src/feature/fwretract.cpp Dosyayı Görüntüle

142
   set_destination_from_current();
142
   set_destination_from_current();
143
 
143
 
144
   #if ENABLED(RETRACT_SYNC_MIXING)
144
   #if ENABLED(RETRACT_SYNC_MIXING)
145
-    uint8_t old_mixing_tool = mixer.get_current_v_tool();
145
+    uint8_t old_mixing_tool = mixer.get_current_vtool();
146
     mixer.T(MIXER_AUTORETRACT_TOOL);
146
     mixer.T(MIXER_AUTORETRACT_TOOL);
147
   #endif
147
   #endif
148
 
148
 

+ 27
- 20
Marlin/src/feature/mixing.cpp Dosyayı Görüntüle

25
 #if ENABLED(MIXING_EXTRUDER)
25
 #if ENABLED(MIXING_EXTRUDER)
26
 
26
 
27
 //#define MIXER_NORMALIZER_DEBUG
27
 //#define MIXER_NORMALIZER_DEBUG
28
-#ifdef MIXER_NORMALIZER_DEBUG
29
-  #include "../core/serial.h"
30
-#endif
31
 
28
 
32
 #include "mixing.h"
29
 #include "mixing.h"
33
 
30
 
34
 Mixer mixer;
31
 Mixer mixer;
35
 
32
 
33
+#ifdef MIXER_NORMALIZER_DEBUG
34
+  #include "../core/serial.h"
35
+#endif
36
+
36
 // Used up to Planner level
37
 // Used up to Planner level
37
-uint_fast8_t  Mixer::selected_v_tool = 0;
38
-float         Mixer::M163_collector[MIXING_STEPPERS]; // mix proportion. 0.0 = off, otherwise <= COLOR_A_MASK.
39
-mixer_color_t Mixer::color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
38
+uint_fast8_t Mixer::selected_vtool = 0;
39
+float        Mixer::collector[MIXING_STEPPERS]; // mix proportion. 0.0 = off, otherwise <= COLOR_A_MASK.
40
+mixer_comp_t Mixer::color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
40
 
41
 
41
 // Used in Stepper
42
 // Used in Stepper
42
-int_fast8_t   Mixer::runner = 0;
43
-mixer_color_t Mixer::s_color[MIXING_STEPPERS];
44
-mixer_accu_t  Mixer::accu[MIXING_STEPPERS] = { 0 };
43
+int_fast8_t  Mixer::runner = 0;
44
+mixer_comp_t Mixer::s_color[MIXING_STEPPERS];
45
+mixer_accu_t Mixer::accu[MIXING_STEPPERS] = { 0 };
45
 
46
 
46
 void Mixer::normalize(const uint8_t tool_index) {
47
 void Mixer::normalize(const uint8_t tool_index) {
47
   float cmax = 0;
48
   float cmax = 0;
49
     float csum = 0;
50
     float csum = 0;
50
   #endif
51
   #endif
51
   MIXER_STEPPER_LOOP(i) {
52
   MIXER_STEPPER_LOOP(i) {
52
-    cmax = max(cmax, M163_collector[i]);
53
+    const float v = collector[i];
54
+    NOLESS(cmax, v);
53
     #ifdef MIXER_NORMALIZER_DEBUG
55
     #ifdef MIXER_NORMALIZER_DEBUG
54
-      csum += M163_collector[i];
56
+      csum += v;
55
     #endif
57
     #endif
56
   }
58
   }
57
   #ifdef MIXER_NORMALIZER_DEBUG
59
   #ifdef MIXER_NORMALIZER_DEBUG
58
-    SERIAL_ECHOPGM("Mixer: Relation before normalizing: [ ");
60
+    SERIAL_ECHOPGM("Mixer: Old relation : [ ");
59
     MIXER_STEPPER_LOOP(i) {
61
     MIXER_STEPPER_LOOP(i) {
60
-      SERIAL_ECHO_F(M163_collector[i] / csum, 3);
62
+      SERIAL_ECHO_F(collector[i] / csum, 3);
61
       SERIAL_CHAR(' ');
63
       SERIAL_CHAR(' ');
62
     }
64
     }
63
     SERIAL_ECHOPGM("]\n");
65
     SERIAL_ECHOPGM("]\n");
66
   // Scale all values so their maximum is COLOR_A_MASK
68
   // Scale all values so their maximum is COLOR_A_MASK
67
   const float inverse_max = RECIPROCAL(cmax);
69
   const float inverse_max = RECIPROCAL(cmax);
68
   MIXER_STEPPER_LOOP(i)
70
   MIXER_STEPPER_LOOP(i)
69
-    color[tool_index][i] = M163_collector[i] * COLOR_A_MASK * inverse_max;
71
+    color[tool_index][i] = collector[i] * COLOR_A_MASK * inverse_max;
70
 
72
 
71
   #ifdef MIXER_NORMALIZER_DEBUG
73
   #ifdef MIXER_NORMALIZER_DEBUG
72
     csum = 0;
74
     csum = 0;
73
-    SERIAL_ECHOPGM("Mixer: Normalizing to             : [ ");
75
+    SERIAL_ECHOPGM("Mixer: Normalize to : [ ");
74
     MIXER_STEPPER_LOOP(i) {
76
     MIXER_STEPPER_LOOP(i) {
75
       SERIAL_ECHO(uint16_t(color[tool_index][i]));
77
       SERIAL_ECHO(uint16_t(color[tool_index][i]));
76
       SERIAL_CHAR(' ');
78
       SERIAL_CHAR(' ');
77
       csum += color[tool_index][i];
79
       csum += color[tool_index][i];
78
     }
80
     }
79
     SERIAL_ECHOLNPGM("]");
81
     SERIAL_ECHOLNPGM("]");
80
-    SERIAL_ECHOPGM("Mixer: Relation after normalizing:  [ ");
82
+    SERIAL_ECHOPGM("Mixer: New relation : [ ");
81
     MIXER_STEPPER_LOOP(i) {
83
     MIXER_STEPPER_LOOP(i) {
82
       SERIAL_ECHO_F(uint16_t(color[tool_index][i]) / csum, 3);
84
       SERIAL_ECHO_F(uint16_t(color[tool_index][i]) / csum, 3);
83
       SERIAL_CHAR(' ');
85
       SERIAL_CHAR(' ');
86
   #endif
88
   #endif
87
 }
89
 }
88
 
90
 
89
-// called at boot
90
-void Mixer::init( void ) {
91
+void Mixer::reset_vtools() {
91
   // Virtual Tools 0, 1, 2, 3 = Filament 1, 2, 3, 4, etc.
92
   // Virtual Tools 0, 1, 2, 3 = Filament 1, 2, 3, 4, etc.
92
   // Every virtual tool gets a pure filament
93
   // Every virtual tool gets a pure filament
93
   for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS && t < MIXING_STEPPERS; t++)
94
   for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS && t < MIXING_STEPPERS; t++)
95
       color[t][i] = (t == i) ? COLOR_A_MASK : 0;
96
       color[t][i] = (t == i) ? COLOR_A_MASK : 0;
96
 
97
 
97
   // Remaining virtual tools are 100% filament 1
98
   // Remaining virtual tools are 100% filament 1
98
-  #if MIXING_STEPPERS < MIXING_VIRTUAL_TOOLS
99
+  #if MIXING_VIRTUAL_TOOLS > MIXING_STEPPERS
99
     for (uint8_t t = MIXING_STEPPERS; t < MIXING_VIRTUAL_TOOLS; t++)
100
     for (uint8_t t = MIXING_STEPPERS; t < MIXING_VIRTUAL_TOOLS; t++)
100
       MIXER_STEPPER_LOOP(i)
101
       MIXER_STEPPER_LOOP(i)
101
         color[t][i] = (i == 0) ? COLOR_A_MASK : 0;
102
         color[t][i] = (i == 0) ? COLOR_A_MASK : 0;
102
   #endif
103
   #endif
104
+}
105
+
106
+// called at boot
107
+void Mixer::init() {
108
+
109
+  reset_vtools();
103
 
110
 
104
   #if ENABLED(RETRACT_SYNC_MIXING)
111
   #if ENABLED(RETRACT_SYNC_MIXING)
105
     // AUTORETRACT_TOOL gets the same amount of all filaments
112
     // AUTORETRACT_TOOL gets the same amount of all filaments
107
       color[MIXER_AUTORETRACT_TOOL][i] = COLOR_A_MASK;
114
       color[MIXER_AUTORETRACT_TOOL][i] = COLOR_A_MASK;
108
   #endif
115
   #endif
109
 
116
 
110
-  ZERO(M163_collector);
117
+  ZERO(collector);
111
 }
118
 }
112
 
119
 
113
 #endif // MIXING_EXTRUDER
120
 #endif // MIXING_EXTRUDER

+ 25
- 19
Marlin/src/feature/mixing.h Dosyayı Görüntüle

25
 
25
 
26
 #ifdef __AVR__
26
 #ifdef __AVR__
27
   #define MIXER_ACCU_SIGNED
27
   #define MIXER_ACCU_SIGNED
28
-  typedef uint8_t mixer_color_t;
28
+  typedef uint8_t mixer_comp_t;
29
   typedef int8_t mixer_accu_t;
29
   typedef int8_t mixer_accu_t;
30
   #define COLOR_A_MASK 0x80
30
   #define COLOR_A_MASK 0x80
31
   #define COLOR_MASK 0x7F
31
   #define COLOR_MASK 0x7F
32
 #else
32
 #else
33
-  typedef uint_fast16_t mixer_color_t;
33
+  typedef uint_fast16_t mixer_comp_t;
34
   typedef uint_fast16_t mixer_accu_t;
34
   typedef uint_fast16_t mixer_accu_t;
35
   #define COLOR_A_MASK 0x8000
35
   #define COLOR_A_MASK 0x8000
36
   #define COLOR_MASK 0x7FFF
36
   #define COLOR_MASK 0x7FFF
56
 #define MIXER_STEPPER_LOOP(VAR) \
56
 #define MIXER_STEPPER_LOOP(VAR) \
57
   for (uint_fast8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++)
57
   for (uint_fast8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++)
58
 
58
 
59
-#define MIXER_BLOCK_DEFINITION mixer_color_t b_color[MIXING_STEPPERS]
59
+#define MIXER_BLOCK_FIELD      mixer_comp_t b_color[MIXING_STEPPERS]
60
 #define MIXER_POPULATE_BLOCK() mixer.populate_block(block->b_color)
60
 #define MIXER_POPULATE_BLOCK() mixer.populate_block(block->b_color)
61
-#define MIXER_STEPPER_SETUP() mixer.stepper_setup(current_block->b_color)
61
+#define MIXER_STEPPER_SETUP()  mixer.stepper_setup(current_block->b_color)
62
 
62
 
63
+/**
64
+ * @brief Mixer class
65
+ * @details Contains data and behaviors for a Mixing Extruder
66
+ */
63
 class Mixer {
67
 class Mixer {
64
   public:
68
   public:
65
 
69
 
66
-  static void init(void); // Populate colors at boot time
70
+  static void init();
71
+
72
+  static void reset_vtools();
67
 
73
 
68
   // Used up to Planner level
74
   // Used up to Planner level
69
   static void normalize(const uint8_t tool_index);
75
   static void normalize(const uint8_t tool_index);
70
-  FORCE_INLINE static uint8_t get_current_v_tool(void) { return selected_v_tool; }
71
-  FORCE_INLINE static void T(const uint_fast8_t c) { selected_v_tool = c; }
72
-  FORCE_INLINE static void set_M163_collector(const uint8_t c, const float f) { M163_collector[c] = f; }
76
+  FORCE_INLINE static uint8_t get_current_vtool() { return selected_vtool; }
77
+  FORCE_INLINE static void T(const uint_fast8_t c) { selected_vtool = c; }
78
+  FORCE_INLINE static void set_collector(const uint8_t c, const float f) { collector[c] = f; }
73
 
79
 
74
   // Used when dealing with blocks
80
   // Used when dealing with blocks
75
-  FORCE_INLINE static void populate_block(mixer_color_t b_color[]) {
76
-    uint_fast8_t j = get_current_v_tool();
81
+  FORCE_INLINE static void populate_block(mixer_comp_t b_color[]) {
82
+    uint_fast8_t j = get_current_vtool();
77
     MIXER_STEPPER_LOOP(i) b_color[i] = color[j][i];
83
     MIXER_STEPPER_LOOP(i) b_color[i] = color[j][i];
78
   }
84
   }
79
-  FORCE_INLINE static void stepper_setup(mixer_color_t b_color[]) { MIXER_STEPPER_LOOP(i) s_color[i] = b_color[i]; }
85
+  FORCE_INLINE static void stepper_setup(mixer_comp_t b_color[]) { MIXER_STEPPER_LOOP(i) s_color[i] = b_color[i]; }
80
 
86
 
81
   // Used in Stepper
87
   // Used in Stepper
82
-  FORCE_INLINE static uint8_t get_stepper(void) { return runner; }
83
-  FORCE_INLINE static uint8_t get_next_stepper(void) {
88
+  FORCE_INLINE static uint8_t get_stepper() { return runner; }
89
+  FORCE_INLINE static uint8_t get_next_stepper() {
84
     do {
90
     do {
85
       if (--runner < 0) runner = MIXING_STEPPERS - 1;
91
       if (--runner < 0) runner = MIXING_STEPPERS - 1;
86
       accu[runner] += s_color[runner];
92
       accu[runner] += s_color[runner];
100
   private:
106
   private:
101
 
107
 
102
   // Used up to Planner level
108
   // Used up to Planner level
103
-  static uint_fast8_t  selected_v_tool;
104
-  static float         M163_collector[MIXING_STEPPERS];
105
-  static mixer_color_t color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
109
+  static uint_fast8_t selected_vtool;
110
+  static float        collector[MIXING_STEPPERS];
111
+  static mixer_comp_t color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
106
 
112
 
107
   // Used in Stepper
113
   // Used in Stepper
108
-  static int_fast8_t   runner;
109
-  static mixer_color_t s_color[MIXING_STEPPERS];
110
-  static mixer_accu_t  accu[MIXING_STEPPERS];
114
+  static int_fast8_t  runner;
115
+  static mixer_comp_t s_color[MIXING_STEPPERS];
116
+  static mixer_accu_t accu[MIXING_STEPPERS];
111
 };
117
 };
112
 
118
 
113
 extern Mixer mixer;
119
 extern Mixer mixer;

+ 5
- 5
Marlin/src/gcode/feature/mixing/M163-M165.cpp Dosyayı Görüntüle

38
 void GcodeSuite::M163() {
38
 void GcodeSuite::M163() {
39
   const int mix_index = parser.intval('S');
39
   const int mix_index = parser.intval('S');
40
   if (mix_index < MIXING_STEPPERS)
40
   if (mix_index < MIXING_STEPPERS)
41
-    mixer.set_M163_collector(mix_index, MAX(parser.floatval('P'), 0.0));
41
+    mixer.set_collector(mix_index, MAX(parser.floatval('P'), 0.0));
42
 }
42
 }
43
 
43
 
44
 /**
44
 /**
56
   if (WITHIN(tool_index, 0, MIXING_VIRTUAL_TOOLS - 1))
56
   if (WITHIN(tool_index, 0, MIXING_VIRTUAL_TOOLS - 1))
57
     mixer.normalize(tool_index);
57
     mixer.normalize(tool_index);
58
   else
58
   else
59
-    mixer.normalize(mixer.get_current_v_tool());
59
+    mixer.normalize(mixer.get_current_vtool());
60
 }
60
 }
61
 
61
 
62
 #if ENABLED(DIRECT_MIXING_IN_G1)
62
 #if ENABLED(DIRECT_MIXING_IN_G1)
95
     MIXER_STEPPER_LOOP(i) {
95
     MIXER_STEPPER_LOOP(i) {
96
       if (parser.seenval(mixing_codes[i])) {
96
       if (parser.seenval(mixing_codes[i])) {
97
         SBI(mix_bits, i);
97
         SBI(mix_bits, i);
98
-        mixer.set_M163_collector(i, MAX(parser.value_float(), 0.0f));
98
+        mixer.set_collector(i, MAX(parser.value_float(), 0.0f));
99
       }
99
       }
100
     }
100
     }
101
     // If any mixing factors were included, clear the rest
101
     // If any mixing factors were included, clear the rest
102
     // If none were included, preserve the last mix
102
     // If none were included, preserve the last mix
103
     if (mix_bits) {
103
     if (mix_bits) {
104
       MIXER_STEPPER_LOOP(i)
104
       MIXER_STEPPER_LOOP(i)
105
-        if (!TEST(mix_bits, i)) mixer.set_M163_collector(i, 0.0f);
106
-      mixer.normalize(mixer.get_current_v_tool());
105
+        if (!TEST(mix_bits, i)) mixer.set_collector(i, 0.0f);
106
+      mixer.normalize(mixer.get_current_vtool());
107
     }
107
     }
108
   }
108
   }
109
 
109
 

+ 1
- 1
Marlin/src/module/planner.cpp Dosyayı Görüntüle

2161
       // In worst case, only one extruder running, no change is needed.
2161
       // In worst case, only one extruder running, no change is needed.
2162
       // In best case, all extruders run the same amount, we can divide by MIXING_STEPPERS
2162
       // In best case, all extruders run the same amount, we can divide by MIXING_STEPPERS
2163
       float delta_mm_i = 0;
2163
       float delta_mm_i = 0;
2164
-      if (i == E_AXIS && mixer.get_current_v_tool() == MIXER_AUTORETRACT_TOOL)
2164
+      if (i == E_AXIS && mixer.get_current_vtool() == MIXER_AUTORETRACT_TOOL)
2165
         delta_mm_i = delta_mm[i] / MIXING_STEPPERS;
2165
         delta_mm_i = delta_mm[i] / MIXING_STEPPERS;
2166
       else
2166
       else
2167
         delta_mm_i = delta_mm[i];
2167
         delta_mm_i = delta_mm[i];

+ 1
- 1
Marlin/src/module/planner.h Dosyayı Görüntüle

114
   #endif
114
   #endif
115
 
115
 
116
   #if ENABLED(MIXING_EXTRUDER)
116
   #if ENABLED(MIXING_EXTRUDER)
117
-    MIXER_BLOCK_DEFINITION;                 // Normalized color for the mixing steppers
117
+    MIXER_BLOCK_FIELD;                      // Normalized color for the mixing steppers
118
   #endif
118
   #endif
119
 
119
 
120
   // Settings for the trapezoid generator
120
   // Settings for the trapezoid generator

+ 2
- 3
Marlin/src/module/tool_change.cpp Dosyayı Görüntüle

507
     if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
507
     if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
508
       return invalid_extruder_error(tmp_extruder);
508
       return invalid_extruder_error(tmp_extruder);
509
 
509
 
510
-    #if MIXING_VIRTUAL_TOOLS >  1
510
+    #if MIXING_VIRTUAL_TOOLS > 1
511
       // T0-Tnnn: Switch virtual tool by changing the index to the mix
511
       // T0-Tnnn: Switch virtual tool by changing the index to the mix
512
-      mixer.T(uint_fast8_t(tmp_extruder));
512
+      mixer.T(tmp_extruder);
513
     #endif
513
     #endif
514
 
514
 
515
   #elif ENABLED(PRUSA_MMU2)
515
   #elif ENABLED(PRUSA_MMU2)
518
 
518
 
519
     mmu2.toolChange(tmp_extruder);
519
     mmu2.toolChange(tmp_extruder);
520
 
520
 
521
-
522
   #elif EXTRUDERS < 2
521
   #elif EXTRUDERS < 2
523
 
522
 
524
     UNUSED(fr_mm_s); UNUSED(no_move);
523
     UNUSED(fr_mm_s); UNUSED(no_move);

Loading…
İptal
Kaydet