|
|
@ -25,23 +25,24 @@
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
|
|
|
|
|
|
|
|
//#define MIXER_NORMALIZER_DEBUG
|
|
|
|
//#define MIXER_NORMALIZER_DEBUG
|
|
|
|
#ifdef MIXER_NORMALIZER_DEBUG
|
|
|
|
|
|
|
|
#include "../core/serial.h"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "mixing.h"
|
|
|
|
#include "mixing.h"
|
|
|
|
|
|
|
|
|
|
|
|
Mixer mixer;
|
|
|
|
Mixer mixer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MIXER_NORMALIZER_DEBUG
|
|
|
|
|
|
|
|
#include "../core/serial.h"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Used up to Planner level
|
|
|
|
// Used up to Planner level
|
|
|
|
uint_fast8_t Mixer::selected_v_tool = 0;
|
|
|
|
uint_fast8_t Mixer::selected_vtool = 0;
|
|
|
|
float Mixer::M163_collector[MIXING_STEPPERS]; // mix proportion. 0.0 = off, otherwise <= COLOR_A_MASK.
|
|
|
|
float Mixer::collector[MIXING_STEPPERS]; // mix proportion. 0.0 = off, otherwise <= COLOR_A_MASK.
|
|
|
|
mixer_color_t Mixer::color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
|
|
|
|
mixer_comp_t Mixer::color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
|
|
|
|
|
|
|
|
|
|
|
|
// Used in Stepper
|
|
|
|
// Used in Stepper
|
|
|
|
int_fast8_t Mixer::runner = 0;
|
|
|
|
int_fast8_t Mixer::runner = 0;
|
|
|
|
mixer_color_t Mixer::s_color[MIXING_STEPPERS];
|
|
|
|
mixer_comp_t Mixer::s_color[MIXING_STEPPERS];
|
|
|
|
mixer_accu_t Mixer::accu[MIXING_STEPPERS] = { 0 };
|
|
|
|
mixer_accu_t Mixer::accu[MIXING_STEPPERS] = { 0 };
|
|
|
|
|
|
|
|
|
|
|
|
void Mixer::normalize(const uint8_t tool_index) {
|
|
|
|
void Mixer::normalize(const uint8_t tool_index) {
|
|
|
|
float cmax = 0;
|
|
|
|
float cmax = 0;
|
|
|
@ -49,15 +50,16 @@ void Mixer::normalize(const uint8_t tool_index) {
|
|
|
|
float csum = 0;
|
|
|
|
float csum = 0;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
MIXER_STEPPER_LOOP(i) {
|
|
|
|
MIXER_STEPPER_LOOP(i) {
|
|
|
|
cmax = max(cmax, M163_collector[i]);
|
|
|
|
const float v = collector[i];
|
|
|
|
|
|
|
|
NOLESS(cmax, v);
|
|
|
|
#ifdef MIXER_NORMALIZER_DEBUG
|
|
|
|
#ifdef MIXER_NORMALIZER_DEBUG
|
|
|
|
csum += M163_collector[i];
|
|
|
|
csum += v;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef MIXER_NORMALIZER_DEBUG
|
|
|
|
#ifdef MIXER_NORMALIZER_DEBUG
|
|
|
|
SERIAL_ECHOPGM("Mixer: Relation before normalizing: [ ");
|
|
|
|
SERIAL_ECHOPGM("Mixer: Old relation : [ ");
|
|
|
|
MIXER_STEPPER_LOOP(i) {
|
|
|
|
MIXER_STEPPER_LOOP(i) {
|
|
|
|
SERIAL_ECHO_F(M163_collector[i] / csum, 3);
|
|
|
|
SERIAL_ECHO_F(collector[i] / csum, 3);
|
|
|
|
SERIAL_CHAR(' ');
|
|
|
|
SERIAL_CHAR(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERIAL_ECHOPGM("]\n");
|
|
|
|
SERIAL_ECHOPGM("]\n");
|
|
|
@ -66,18 +68,18 @@ void Mixer::normalize(const uint8_t tool_index) {
|
|
|
|
// Scale all values so their maximum is COLOR_A_MASK
|
|
|
|
// Scale all values so their maximum is COLOR_A_MASK
|
|
|
|
const float inverse_max = RECIPROCAL(cmax);
|
|
|
|
const float inverse_max = RECIPROCAL(cmax);
|
|
|
|
MIXER_STEPPER_LOOP(i)
|
|
|
|
MIXER_STEPPER_LOOP(i)
|
|
|
|
color[tool_index][i] = M163_collector[i] * COLOR_A_MASK * inverse_max;
|
|
|
|
color[tool_index][i] = collector[i] * COLOR_A_MASK * inverse_max;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MIXER_NORMALIZER_DEBUG
|
|
|
|
#ifdef MIXER_NORMALIZER_DEBUG
|
|
|
|
csum = 0;
|
|
|
|
csum = 0;
|
|
|
|
SERIAL_ECHOPGM("Mixer: Normalizing to : [ ");
|
|
|
|
SERIAL_ECHOPGM("Mixer: Normalize to : [ ");
|
|
|
|
MIXER_STEPPER_LOOP(i) {
|
|
|
|
MIXER_STEPPER_LOOP(i) {
|
|
|
|
SERIAL_ECHO(uint16_t(color[tool_index][i]));
|
|
|
|
SERIAL_ECHO(uint16_t(color[tool_index][i]));
|
|
|
|
SERIAL_CHAR(' ');
|
|
|
|
SERIAL_CHAR(' ');
|
|
|
|
csum += color[tool_index][i];
|
|
|
|
csum += color[tool_index][i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERIAL_ECHOLNPGM("]");
|
|
|
|
SERIAL_ECHOLNPGM("]");
|
|
|
|
SERIAL_ECHOPGM("Mixer: Relation after normalizing: [ ");
|
|
|
|
SERIAL_ECHOPGM("Mixer: New relation : [ ");
|
|
|
|
MIXER_STEPPER_LOOP(i) {
|
|
|
|
MIXER_STEPPER_LOOP(i) {
|
|
|
|
SERIAL_ECHO_F(uint16_t(color[tool_index][i]) / csum, 3);
|
|
|
|
SERIAL_ECHO_F(uint16_t(color[tool_index][i]) / csum, 3);
|
|
|
|
SERIAL_CHAR(' ');
|
|
|
|
SERIAL_CHAR(' ');
|
|
|
@ -86,8 +88,7 @@ void Mixer::normalize(const uint8_t tool_index) {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// called at boot
|
|
|
|
void Mixer::reset_vtools() {
|
|
|
|
void Mixer::init( void ) {
|
|
|
|
|
|
|
|
// Virtual Tools 0, 1, 2, 3 = Filament 1, 2, 3, 4, etc.
|
|
|
|
// Virtual Tools 0, 1, 2, 3 = Filament 1, 2, 3, 4, etc.
|
|
|
|
// Every virtual tool gets a pure filament
|
|
|
|
// Every virtual tool gets a pure filament
|
|
|
|
for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS && t < MIXING_STEPPERS; t++)
|
|
|
|
for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS && t < MIXING_STEPPERS; t++)
|
|
|
@ -95,11 +96,17 @@ void Mixer::init( void ) {
|
|
|
|
color[t][i] = (t == i) ? COLOR_A_MASK : 0;
|
|
|
|
color[t][i] = (t == i) ? COLOR_A_MASK : 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Remaining virtual tools are 100% filament 1
|
|
|
|
// Remaining virtual tools are 100% filament 1
|
|
|
|
#if MIXING_STEPPERS < MIXING_VIRTUAL_TOOLS
|
|
|
|
#if MIXING_VIRTUAL_TOOLS > MIXING_STEPPERS
|
|
|
|
for (uint8_t t = MIXING_STEPPERS; t < MIXING_VIRTUAL_TOOLS; t++)
|
|
|
|
for (uint8_t t = MIXING_STEPPERS; t < MIXING_VIRTUAL_TOOLS; t++)
|
|
|
|
MIXER_STEPPER_LOOP(i)
|
|
|
|
MIXER_STEPPER_LOOP(i)
|
|
|
|
color[t][i] = (i == 0) ? COLOR_A_MASK : 0;
|
|
|
|
color[t][i] = (i == 0) ? COLOR_A_MASK : 0;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// called at boot
|
|
|
|
|
|
|
|
void Mixer::init() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reset_vtools();
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(RETRACT_SYNC_MIXING)
|
|
|
|
#if ENABLED(RETRACT_SYNC_MIXING)
|
|
|
|
// AUTORETRACT_TOOL gets the same amount of all filaments
|
|
|
|
// AUTORETRACT_TOOL gets the same amount of all filaments
|
|
|
@ -107,7 +114,7 @@ void Mixer::init( void ) {
|
|
|
|
color[MIXER_AUTORETRACT_TOOL][i] = COLOR_A_MASK;
|
|
|
|
color[MIXER_AUTORETRACT_TOOL][i] = COLOR_A_MASK;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
ZERO(M163_collector);
|
|
|
|
ZERO(collector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // MIXING_EXTRUDER
|
|
|
|
#endif // MIXING_EXTRUDER
|
|
|
|