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