From e8701195e66f2d27ffe17fb514eae8173795aaf7 Mon Sep 17 00:00:00 2001
From: Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com>
Date: Thu, 4 Mar 2021 22:54:23 +0500
Subject: Initial commit
---
Marlin/src/gcode/feature/mixing/M163-M165.cpp | 101 +++++++++++++++++++++++++
Marlin/src/gcode/feature/mixing/M166.cpp | 103 ++++++++++++++++++++++++++
2 files changed, 204 insertions(+)
create mode 100644 Marlin/src/gcode/feature/mixing/M163-M165.cpp
create mode 100644 Marlin/src/gcode/feature/mixing/M166.cpp
(limited to 'Marlin/src/gcode/feature/mixing')
diff --git a/Marlin/src/gcode/feature/mixing/M163-M165.cpp b/Marlin/src/gcode/feature/mixing/M163-M165.cpp
new file mode 100644
index 0000000..a4cb64e
--- /dev/null
+++ b/Marlin/src/gcode/feature/mixing/M163-M165.cpp
@@ -0,0 +1,101 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(MIXING_EXTRUDER)
+
+#include "../../gcode.h"
+#include "../../../feature/mixing.h"
+
+/**
+ * M163: Set a single mix factor for a mixing extruder
+ * This is called "weight" by some systems.
+ * Must be followed by M164 to normalize and commit them.
+ *
+ * S[index] The channel index to set
+ * P[float] The mix value
+ */
+void GcodeSuite::M163() {
+ const int mix_index = parser.intval('S');
+ if (mix_index < MIXING_STEPPERS)
+ mixer.set_collector(mix_index, parser.floatval('P'));
+}
+
+/**
+ * M164: Normalize and commit the mix.
+ *
+ * S[index] The virtual tool to store
+ * If 'S' is omitted update the active virtual tool.
+ */
+void GcodeSuite::M164() {
+ #if MIXING_VIRTUAL_TOOLS > 1
+ const int tool_index = parser.intval('S', -1);
+ #else
+ constexpr int tool_index = 0;
+ #endif
+ if (tool_index >= 0) {
+ if (tool_index < MIXING_VIRTUAL_TOOLS)
+ mixer.normalize(tool_index);
+ }
+ else
+ mixer.normalize();
+}
+
+#if ENABLED(DIRECT_MIXING_IN_G1)
+
+ /**
+ * M165: Set multiple mix factors for a mixing extruder.
+ * Omitted factors will be set to 0.
+ * The mix is normalized and stored in the current virtual tool.
+ *
+ * A[factor] Mix factor for extruder stepper 1
+ * B[factor] Mix factor for extruder stepper 2
+ * C[factor] Mix factor for extruder stepper 3
+ * D[factor] Mix factor for extruder stepper 4
+ * H[factor] Mix factor for extruder stepper 5
+ * I[factor] Mix factor for extruder stepper 6
+ */
+ void GcodeSuite::M165() {
+ // Get mixing parameters from the GCode
+ // The total "must" be 1.0 (but it will be normalized)
+ // If no mix factors are given, the old mix is preserved
+ const char mixing_codes[] = { LIST_N(MIXING_STEPPERS, 'A', 'B', 'C', 'D', 'H', 'I') };
+ uint8_t mix_bits = 0;
+ MIXER_STEPPER_LOOP(i) {
+ if (parser.seenval(mixing_codes[i])) {
+ SBI(mix_bits, i);
+ mixer.set_collector(i, parser.value_float());
+ }
+ }
+ // If any mixing factors were included, clear the rest
+ // If none were included, preserve the last mix
+ if (mix_bits) {
+ MIXER_STEPPER_LOOP(i)
+ if (!TEST(mix_bits, i)) mixer.set_collector(i, 0.0f);
+ mixer.normalize();
+ }
+ }
+
+#endif // DIRECT_MIXING_IN_G1
+
+#endif // MIXING_EXTRUDER
diff --git a/Marlin/src/gcode/feature/mixing/M166.cpp b/Marlin/src/gcode/feature/mixing/M166.cpp
new file mode 100644
index 0000000..9e071a4
--- /dev/null
+++ b/Marlin/src/gcode/feature/mixing/M166.cpp
@@ -0,0 +1,103 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(GRADIENT_MIX)
+
+#include "../../gcode.h"
+#include "../../../module/motion.h"
+#include "../../../module/planner.h"
+#include "../../../feature/mixing.h"
+
+inline void echo_mix() {
+ SERIAL_ECHOPAIR(" (", int(mixer.mix[0]), "%|", int(mixer.mix[1]), "%)");
+}
+
+inline void echo_zt(const int t, const float &z) {
+ mixer.update_mix_from_vtool(t);
+ SERIAL_ECHOPAIR_P(SP_Z_STR, z, SP_T_STR, t);
+ echo_mix();
+}
+
+/**
+ * M166: Set a simple gradient mix for a two-component mixer
+ * based on the Geeetech A10M implementation by Jone Liu.
+ *
+ * S[bool] - Enable / disable gradients
+ * A[float] - Starting Z for the gradient
+ * Z[float] - Ending Z for the gradient. (Must be greater than the starting Z.)
+ * I[index] - V-Tool to use as the starting mix.
+ * J[index] - V-Tool to use as the ending mix.
+ *
+ * T[index] - A V-Tool index to use as an alias for the Gradient (Requires GRADIENT_VTOOL)
+ * T with no index clears the setting. Note: This can match the I or J value.
+ *
+ * Example: M166 S1 A0 Z20 I0 J1
+ */
+void GcodeSuite::M166() {
+ if (parser.seenval('A')) mixer.gradient.start_z = parser.value_float();
+ if (parser.seenval('Z')) mixer.gradient.end_z = parser.value_float();
+ if (parser.seenval('I')) mixer.gradient.start_vtool = (uint8_t)constrain(parser.value_int(), 0, MIXING_VIRTUAL_TOOLS);
+ if (parser.seenval('J')) mixer.gradient.end_vtool = (uint8_t)constrain(parser.value_int(), 0, MIXING_VIRTUAL_TOOLS);
+
+ #if ENABLED(GRADIENT_VTOOL)
+ if (parser.seen('T')) mixer.gradient.vtool_index = parser.byteval('T', -1);
+ #endif
+
+ if (parser.seen('S')) mixer.gradient.enabled = parser.value_bool();
+
+ mixer.refresh_gradient();
+
+ SERIAL_ECHOPGM("Gradient Mix ");
+ serialprint_onoff(mixer.gradient.enabled);
+ if (mixer.gradient.enabled) {
+
+ #if ENABLED(GRADIENT_VTOOL)
+ if (mixer.gradient.vtool_index >= 0) {
+ SERIAL_ECHOPAIR(" (T", int(mixer.gradient.vtool_index));
+ SERIAL_CHAR(')');
+ }
+ #endif
+
+ SERIAL_ECHOPGM(" ; Start");
+ echo_zt(mixer.gradient.start_vtool, mixer.gradient.start_z);
+
+ SERIAL_ECHOPGM(" ; End");
+ echo_zt(mixer.gradient.end_vtool, mixer.gradient.end_z);
+
+ mixer.update_mix_from_gradient();
+
+ SERIAL_ECHOPGM(" ; Current Z");
+ #if ENABLED(DELTA)
+ get_cartesian_from_steppers();
+ SERIAL_ECHO(cartes.z);
+ #else
+ SERIAL_ECHO(planner.get_axis_position_mm(Z_AXIS));
+ #endif
+ echo_mix();
+ }
+
+ SERIAL_EOL();
+}
+
+#endif // GRADIENT_MIX
--
cgit v1.2.3