Browse Source

Fix mixing for up to 6 steppers (#15374)

Christian 5 years ago
parent
commit
ddded80ff3
1 changed files with 22 additions and 8 deletions
  1. 22
    8
      Marlin/src/feature/mixing.h

+ 22
- 8
Marlin/src/feature/mixing.h View File

142
     static inline void copy_mix_to_color(mixer_comp_t (&tcolor)[MIXING_STEPPERS]) {
142
     static inline void copy_mix_to_color(mixer_comp_t (&tcolor)[MIXING_STEPPERS]) {
143
       // Scale each component to the largest one in terms of COLOR_A_MASK
143
       // Scale each component to the largest one in terms of COLOR_A_MASK
144
       // So the largest component will be COLOR_A_MASK and the other will be in proportion to it
144
       // So the largest component will be COLOR_A_MASK and the other will be in proportion to it
145
-      const float scale = (COLOR_A_MASK) * RECIPROCAL(float(_MAX(mix[0], mix[1])));
145
+      const float scale = (COLOR_A_MASK) * RECIPROCAL(_MAX(
146
+        LIST_N(MIXING_STEPPERS, mix[0], mix[1], mix[2], mix[3], mix[4], mix[5])
147
+      ));
146
 
148
 
147
       // Scale all values so their maximum is COLOR_A_MASK
149
       // Scale all values so their maximum is COLOR_A_MASK
148
       MIXER_STEPPER_LOOP(i) tcolor[i] = mix[i] * scale;
150
       MIXER_STEPPER_LOOP(i) tcolor[i] = mix[i] * scale;
149
 
151
 
150
       #ifdef MIXER_NORMALIZER_DEBUG
152
       #ifdef MIXER_NORMALIZER_DEBUG
151
-        SERIAL_ECHOLNPAIR("Mix [", int(mix[0]), ", ", int(mix[1]), "] to Color [", int(tcolor[0]), ", ", int(tcolor[1]), "]");
153
+        SERIAL_ECHOPGM("Mix [ ");
154
+        SERIAL_ECHOLIST_N(MIXING_STEPPERS, int(mix[0]), int(mix[1]), int(mix[2]), int(mix[3]), int(mix[4]), int(mix[5]));
155
+        SERIAL_ECHOPGM(" ] to Color [ ");
156
+        SERIAL_ECHOLIST_N(MIXING_STEPPERS, int(tcolor[0]), int(tcolor[1]), int(tcolor[2]), int(tcolor[3]), int(tcolor[4]), int(tcolor[5]));
157
+        SERIAL_ECHOLNPGM(" ]");
152
       #endif
158
       #endif
153
     }
159
     }
154
 
160
 
156
       float ctot = 0;
162
       float ctot = 0;
157
       MIXER_STEPPER_LOOP(i) ctot += color[j][i];
163
       MIXER_STEPPER_LOOP(i) ctot += color[j][i];
158
       //MIXER_STEPPER_LOOP(i) mix[i] = 100.0f * color[j][i] / ctot;
164
       //MIXER_STEPPER_LOOP(i) mix[i] = 100.0f * color[j][i] / ctot;
159
-      mix[0] = mixer_perc_t(100.0f * color[j][0] / ctot);
160
-      mix[1] = 100 - mix[0];
165
+      MIXER_STEPPER_LOOP(i) mix[i] = mixer_perc_t(100.0f * color[j][i] / ctot);
166
+
161
       #ifdef MIXER_NORMALIZER_DEBUG
167
       #ifdef MIXER_NORMALIZER_DEBUG
162
-        SERIAL_ECHOLNPAIR("V-tool ", int(j), " [", int(color[j][0]), ", ", int(color[j][1]), "] to Mix [", int(mix[0]), ", ", int(mix[1]), "]");
168
+        SERIAL_ECHOPAIR("V-tool ", int(j), " [ ");
169
+        SERIAL_ECHOLIST_N(MIXING_STEPPERS, int(color[j][0]), int(color[j][1]), int(color[j][2]), int(color[j][3]), int(color[j][4]), int(color[j][5]));
170
+        SERIAL_ECHOPGM(" ] to Mix [ ");
171
+        SERIAL_ECHOLIST_N(MIXING_STEPPERS, int(mix[0]), int(mix[1]), int(mix[2]), int(mix[3]), int(mix[4]), int(mix[5]));
172
+        SERIAL_ECHOLNPGM(" ]");
163
       #endif
173
       #endif
164
     }
174
     }
165
 
175
 
199
     static inline void update_mix_from_gradient() {
209
     static inline void update_mix_from_gradient() {
200
       float ctot = 0;
210
       float ctot = 0;
201
       MIXER_STEPPER_LOOP(i) ctot += gradient.color[i];
211
       MIXER_STEPPER_LOOP(i) ctot += gradient.color[i];
202
-      mix[0] = (mixer_perc_t)CEIL(100.0f * gradient.color[0] / ctot);
203
-      mix[1] = 100 - mix[0];
212
+      MIXER_STEPPER_LOOP(i) mix[i] = (mixer_perc_t)CEIL(100.0f * gradient.color[i] / ctot);
213
+
204
       #ifdef MIXER_NORMALIZER_DEBUG
214
       #ifdef MIXER_NORMALIZER_DEBUG
205
-        SERIAL_ECHOLNPAIR("Gradient [", int(gradient.color[0]), ", ", int(gradient.color[1]), "] to Mix [", int(mix[0]), ", ", int(mix[1]), "]");
215
+        SERIAL_ECHOPGM("Gradient [ ");
216
+        SERIAL_ECHOLIST_N(MIXING_STEPPERS, int(gradient.color[0]), int(gradient.color[1]), int(gradient.color[2]), int(gradient.color[3]), int(gradient.color[4]), int(gradient.color[5]));
217
+        SERIAL_ECHOPGM(" ] to Mix [ ");
218
+        SERIAL_ECHOLIST_N(MIXING_STEPPERS, int(mix[0]), int(mix[1]), int(mix[2]), int(mix[3]), int(mix[4]), int(mix[5]));
219
+        SERIAL_ECHOLNPGM(" ]");
206
       #endif
220
       #endif
207
     }
221
     }
208
 
222
 

Loading…
Cancel
Save