Unify debugging output with debug_out.h (#13388)

This commit is contained in:
Scott Lahteine
2019-03-14 02:25:42 -05:00
committed by GitHub
parent cc8a871705
commit f5bcc00570
25 changed files with 627 additions and 904 deletions

View File

@ -29,6 +29,9 @@
#include "../../../module/motion.h"
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../../core/debug_out.h"
int bilinear_grid_spacing[2], bilinear_start[2];
float bilinear_grid_factor[2],
z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
@ -37,26 +40,21 @@ float bilinear_grid_factor[2],
* Extrapolate a single point from its neighbors
*/
static void extrapolate_one_point(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPGM("Extrapolate [");
if (x < 10) SERIAL_CHAR(' ');
SERIAL_ECHO((int)x);
SERIAL_CHAR(xdir ? (xdir > 0 ? '+' : '-') : ' ');
SERIAL_CHAR(' ');
if (y < 10) SERIAL_CHAR(' ');
SERIAL_ECHO((int)y);
SERIAL_CHAR(ydir ? (ydir > 0 ? '+' : '-') : ' ');
SERIAL_CHAR(']');
}
#endif
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPGM("Extrapolate [");
if (x < 10) DEBUG_CHAR(' ');
DEBUG_ECHO((int)x);
DEBUG_CHAR(xdir ? (xdir > 0 ? '+' : '-') : ' ');
DEBUG_CHAR(' ');
if (y < 10) DEBUG_CHAR(' ');
DEBUG_ECHO((int)y);
DEBUG_CHAR(ydir ? (ydir > 0 ? '+' : '-') : ' ');
DEBUG_ECHOLNPGM("]");
}
if (!isnan(z_values[x][y])) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM(" (done)");
#endif
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(" (done)");
return; // Don't overwrite good values.
}
SERIAL_EOL();
// Get X neighbors, Y neighbors, and XY neighbors
const uint8_t x1 = x + xdir, y1 = y + ydir, x2 = x1 + xdir, y2 = y1 + ydir;

View File

@ -39,6 +39,9 @@
#include "../../lcd/ultralcd.h"
#endif
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../core/debug_out.h"
#if ENABLED(G26_MESH_VALIDATION)
bool g26_debug_flag; // = false
#endif
@ -122,9 +125,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
* Reset calibration results to zero.
*/
void reset_bed_level() {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("reset_bed_level");
#endif
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("reset_bed_level");
set_bed_leveling_enabled(false);
#if ENABLED(MESH_BED_LEVELING)
mbl.reset();

View File

@ -29,6 +29,9 @@
#include "../../../lcd/ultralcd.h"
#include "../../../Marlin.h"
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../../core/debug_out.h"
#define UBL_VERSION "1.01"
#define UBL_OK false
#define UBL_ERR true
@ -199,12 +202,11 @@ class unified_bed_leveling {
*/
static inline float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) {
if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
serialprintPGM( !WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) ? PSTR("x1_i") : PSTR("yi") );
SERIAL_ECHOLNPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(rx0=", rx0, ",x1_i=", x1_i, ",yi=", yi, ")");
}
#endif
if (DEBUGGING(LEVELING)) {
if (WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1)) DEBUG_ECHOPGM("yi"); else DEBUG_ECHOPGM("x1_i");
DEBUG_ECHOLNPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(rx0=", rx0, ",x1_i=", x1_i, ",yi=", yi, ")");
}
// The requested location is off the mesh. Return UBL_Z_RAISE_WHEN_OFF_MESH or NAN.
return (
@ -229,12 +231,11 @@ class unified_bed_leveling {
//
static inline float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) {
if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 1)) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
serialprintPGM(!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) ? PSTR("xi") : PSTR("y1_i"));
SERIAL_ECHOLNPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ry0=", ry0, ", xi=", xi, ", y1_i=", y1_i, ")");
}
#endif
if (DEBUGGING(LEVELING)) {
if (WITHIN(xi, 0, GRID_MAX_POINTS_X - 1)) DEBUG_ECHOPGM("y1_i"); else DEBUG_ECHOPGM("xi");
DEBUG_ECHOLNPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ry0=", ry0, ", xi=", xi, ", y1_i=", y1_i, ")");
}
// The requested location is off the mesh. Return UBL_Z_RAISE_WHEN_OFF_MESH or NAN.
return (
@ -285,17 +286,12 @@ class unified_bed_leveling {
mesh_index_to_ypos(cy), z1,
mesh_index_to_ypos(cy + 1), z2);
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(MESH_ADJUST)) {
SERIAL_ECHOPAIR(" raw get_z_correction(", rx0);
SERIAL_CHAR(','); SERIAL_ECHO(ry0);
SERIAL_ECHOPAIR_F(") = ", z0, 6);
}
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(MESH_ADJUST)) SERIAL_ECHOLNPAIR_F(" >>>---> ", z0, 6);
#endif
if (DEBUGGING(MESH_ADJUST)) {
DEBUG_ECHOPAIR(" raw get_z_correction(", rx0);
DEBUG_CHAR(','); DEBUG_ECHO(ry0);
DEBUG_ECHOPAIR_F(") = ", z0, 6);
DEBUG_ECHOLNPAIR_F(" >>>---> ", z0, 6);
}
if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN
z0 = 0.0; // in ubl.z_values[][] and propagate through the
@ -303,15 +299,13 @@ class unified_bed_leveling {
// because part of the Mesh is undefined and we don't have the
// information we need to complete the height correction.
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(MESH_ADJUST)) {
SERIAL_ECHOPAIR("??? Yikes! NAN in get_z_correction(", rx0);
SERIAL_CHAR(',');
SERIAL_ECHO(ry0);
SERIAL_CHAR(')');
SERIAL_EOL();
}
#endif
if (DEBUGGING(MESH_ADJUST)) {
DEBUG_ECHOPAIR("??? Yikes! NAN in get_z_correction(", rx0);
DEBUG_CHAR(',');
DEBUG_ECHO(ry0);
DEBUG_CHAR(')');
DEBUG_EOL();
}
}
return z0;
}
@ -342,3 +336,6 @@ class unified_bed_leveling {
extern unified_bed_leveling ubl;
#define Z_VALUES(X,Y) ubl.z_values[X][Y]
// Prevent debugging propagating to other files
#include "../../../core/debug_out.h"

View File

@ -46,6 +46,9 @@
#include "../../../module/tool_change.h"
#endif
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../../core/debug_out.h"
#include <math.h>
#define UBL_G29_P31
@ -442,7 +445,7 @@
SERIAL_ECHOLNPGM("Mesh invalidated. Probing mesh.");
}
if (g29_verbose_level > 1) {
SERIAL_ECHOPAIR("Probing Mesh Points Closest to (", g29_x_pos);
SERIAL_ECHOPAIR("Probing around (", g29_x_pos);
SERIAL_CHAR(',');
SERIAL_ECHO(g29_y_pos);
SERIAL_ECHOLNPGM(").\n");
@ -1463,27 +1466,24 @@
abort_flag = isnan(measured_z);
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_CHAR('(');
SERIAL_ECHO_F(rx, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(ry, 7);
SERIAL_ECHOPGM(") logical: ");
SERIAL_CHAR('(');
SERIAL_ECHO_F(LOGICAL_X_POSITION(rx), 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(LOGICAL_Y_POSITION(ry), 7);
SERIAL_ECHOPAIR_F(") measured: ", measured_z, 7);
SERIAL_ECHOPAIR_F(" correction: ", get_z_correction(rx, ry), 7);
}
#endif
if (DEBUGGING(LEVELING)) {
DEBUG_CHAR('(');
DEBUG_ECHO_F(rx, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(ry, 7);
DEBUG_ECHOPGM(") logical: ");
DEBUG_CHAR('(');
DEBUG_ECHO_F(LOGICAL_X_POSITION(rx), 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(LOGICAL_Y_POSITION(ry), 7);
DEBUG_ECHOPAIR_F(") measured: ", measured_z, 7);
DEBUG_ECHOPAIR_F(" correction: ", get_z_correction(rx, ry), 7);
}
measured_z -= get_z_correction(rx, ry) /* + zprobe_zoffset */ ;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR_F(" final >>>---> ", measured_z, 7);
#endif
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR_F(" final >>>---> ", measured_z, 7);
if (g29_verbose_level > 3) {
serial_spaces(16);
SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z);
@ -1524,31 +1524,27 @@
y_tmp = mesh_index_to_ypos(j),
z_tmp = z_values[i][j];
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR_F("before rotation = [", x_tmp, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(y_tmp, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(z_tmp, 7);
SERIAL_ECHOPGM("] ---> ");
serial_delay(20);
}
#endif
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", x_tmp, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(y_tmp, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(z_tmp, 7);
DEBUG_ECHOPGM("] ---> ");
DEBUG_DELAY(20);
}
apply_rotation_xyz(rotation, x_tmp, y_tmp, z_tmp);
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR_F("after rotation = [", x_tmp, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(y_tmp, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(z_tmp, 7);
SERIAL_ECHOLNPGM("]");
serial_delay(55);
}
#endif
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("after rotation = [", x_tmp, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(y_tmp, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(z_tmp, 7);
DEBUG_ECHOLNPGM("]");
DEBUG_DELAY(55);
}
z_values[i][j] = z_tmp - lsf_results.D;
#if ENABLED(EXTENSIBLE_UI)
@ -1557,62 +1553,59 @@
}
}
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
rotation.debug(PSTR("rotation matrix:\n"));
SERIAL_ECHOPAIR_F("LSF Results A=", lsf_results.A, 7);
SERIAL_ECHOPAIR_F(" B=", lsf_results.B, 7);
SERIAL_ECHOLNPAIR_F(" D=", lsf_results.D, 7);
serial_delay(55);
if (DEBUGGING(LEVELING)) {
rotation.debug(PSTR("rotation matrix:\n"));
DEBUG_ECHOPAIR_F("LSF Results A=", lsf_results.A, 7);
DEBUG_ECHOPAIR_F(" B=", lsf_results.B, 7);
DEBUG_ECHOLNPAIR_F(" D=", lsf_results.D, 7);
DEBUG_DELAY(55);
SERIAL_ECHOPAIR_F("bed plane normal = [", normal.x, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(normal.y, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(normal.z, 7);
SERIAL_ECHOLNPGM("]");
SERIAL_EOL();
DEBUG_ECHOPAIR_F("bed plane normal = [", normal.x, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(normal.y, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(normal.z, 7);
DEBUG_ECHOLNPGM("]");
DEBUG_EOL();
/**
* The following code can be used to check the validity of the mesh tilting algorithm.
* When a 3-Point Mesh Tilt is done, the same algorithm is used as the grid based tilting.
* The only difference is just 3 points are used in the calculations. That fact guarantees
* each probed point should have an exact match when a get_z_correction() for that location
* is calculated. The Z error between the probed point locations and the get_z_correction()
* numbers for those locations should be 0.
*/
#if 0
float t, t1, d;
t = normal.x * (PROBE_PT_1_X) + normal.y * (PROBE_PT_1_Y);
d = t + normal.z * z1;
SERIAL_ECHOPAIR_F("D from 1st point: ", d, 6);
SERIAL_ECHOLNPAIR_F(" Z error: ", normal.z*z1-get_z_correction(PROBE_PT_1_X, PROBE_PT_1_Y), 6);
/**
* The following code can be used to check the validity of the mesh tilting algorithm.
* When a 3-Point Mesh Tilt is done, the same algorithm is used as the grid based tilting.
* The only difference is just 3 points are used in the calculations. That fact guarantees
* each probed point should have an exact match when a get_z_correction() for that location
* is calculated. The Z error between the probed point locations and the get_z_correction()
* numbers for those locations should be 0.
*/
#if 0
float t, t1, d;
t = normal.x * (PROBE_PT_1_X) + normal.y * (PROBE_PT_1_Y);
d = t + normal.z * z1;
DEBUG_ECHOPAIR_F("D from 1st point: ", d, 6);
DEBUG_ECHOLNPAIR_F(" Z error: ", normal.z*z1-get_z_correction(PROBE_PT_1_X, PROBE_PT_1_Y), 6);
t = normal.x * (PROBE_PT_2_X) + normal.y * (PROBE_PT_2_Y);
d = t + normal.z * z2;
SERIAL_EOL();
SERIAL_ECHOPAIR_F("D from 2nd point: ", d, 6);
SERIAL_ECHOLNPAIR_F(" Z error: ", normal.z*z2-get_z_correction(PROBE_PT_2_X, PROBE_PT_2_Y), 6);
t = normal.x * (PROBE_PT_2_X) + normal.y * (PROBE_PT_2_Y);
d = t + normal.z * z2;
DEBUG_EOL();
DEBUG_ECHOPAIR_F("D from 2nd point: ", d, 6);
DEBUG_ECHOLNPAIR_F(" Z error: ", normal.z*z2-get_z_correction(PROBE_PT_2_X, PROBE_PT_2_Y), 6);
t = normal.x * (PROBE_PT_3_X) + normal.y * (PROBE_PT_3_Y);
d = t + normal.z * z3;
SERIAL_ECHOPAIR_F("D from 3rd point: ", d, 6);
SERIAL_ECHOLNPAIR_F(" Z error: ", normal.z*z3-get_z_correction(PROBE_PT_3_X, PROBE_PT_3_Y), 6);
t = normal.x * (PROBE_PT_3_X) + normal.y * (PROBE_PT_3_Y);
d = t + normal.z * z3;
DEBUG_ECHOPAIR_F("D from 3rd point: ", d, 6);
DEBUG_ECHOLNPAIR_F(" Z error: ", normal.z*z3-get_z_correction(PROBE_PT_3_X, PROBE_PT_3_Y), 6);
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
d = t + normal.z * 0;
SERIAL_ECHOLNPAIR_F("D from home location with Z=0 : ", d, 6);
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
d = t + normal.z * 0;
DEBUG_ECHOLNPAIR_F("D from home location with Z=0 : ", d, 6);
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
d = t + get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT); // normal.z * 0;
SERIAL_ECHOPAIR_F("D from home location using mesh value for Z: ", d, 6);
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
d = t + get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT); // normal.z * 0;
DEBUG_ECHOPAIR_F("D from home location using mesh value for Z: ", d, 6);
SERIAL_ECHOPAIR(" Z error: (", Z_SAFE_HOMING_X_POINT);
SERIAL_ECHOPAIR(",", Z_SAFE_HOMING_Y_POINT);
SERIAL_ECHOLNPAIR_F(") = ", get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT), 6);
#endif
} // DEBUGGING(LEVELING)
#endif
DEBUG_ECHOPAIR(" Z error: (", Z_SAFE_HOMING_X_POINT, ",", Z_SAFE_HOMING_Y_POINT);
DEBUG_ECHOLNPAIR_F(") = ", get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT), 6);
#endif
} // DEBUGGING(LEVELING)
}

View File

@ -42,6 +42,9 @@ MMU2 mmu2;
#include "../../feature/host_actions.h"
#endif
#define DEBUG_OUT ENABLED(MMU2_DEBUG)
#include "../../core/debug_out.h"
#define MMU_TODELAY 100
#define MMU_TIMEOUT 10
#define MMU_CMD_TIMEOUT 60000ul //5min timeout for mmu commands (except P0)
@ -128,9 +131,7 @@ void MMU2::init() {
}
void MMU2::reset() {
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("MMU <= reset");
#endif
DEBUG_ECHOLNPGM("MMU <= reset");
#if PIN_EXISTS(MMU2_RST)
WRITE(MMU2_RST_PIN, LOW);
@ -153,10 +154,8 @@ void MMU2::mmuLoop() {
case -1:
if (rx_start()) {
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("MMU => 'start'");
SERIAL_ECHOLNPGM("MMU <= 'S1'");
#endif
DEBUG_ECHOLNPGM("MMU => 'start'");
DEBUG_ECHOLNPGM("MMU <= 'S1'");
// send "read version" request
tx_str_P(PSTR("S1\n"));
@ -173,9 +172,7 @@ void MMU2::mmuLoop() {
if (rx_ok()) {
sscanf(rx_buffer, "%uok\n", &version);
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPAIR("MMU => ", version, "\nMMU <= 'S2'");
#endif
DEBUG_ECHOLNPAIR("MMU => ", version, "\nMMU <= 'S2'");
tx_str_P(PSTR("S2\n")); // read build number
state = -3;
@ -185,24 +182,19 @@ void MMU2::mmuLoop() {
case -3:
if (rx_ok()) {
sscanf(rx_buffer, "%uok\n", &buildnr);
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPAIR("MMU => ", buildnr);
#endif
DEBUG_ECHOLNPAIR("MMU => ", buildnr);
checkVersion();
#if ENABLED(MMU2_MODE_12V)
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("MMU <= 'M1'");
#endif
DEBUG_ECHOLNPGM("MMU <= 'M1'");
tx_str_P(PSTR("M1\n")); // switch to stealth mode
state = -5;
#else
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("MMU <= 'P0'");
#endif
DEBUG_ECHOLNPGM("MMU <= 'P0'");
tx_str_P(PSTR("P0\n")); // read finda
state = -4;
@ -213,15 +205,11 @@ void MMU2::mmuLoop() {
case -5:
// response to M1
if (rx_ok()) {
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("MMU => ok");
#endif
DEBUG_ECHOLNPGM("MMU => ok");
checkVersion();
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("MMU <= 'P0'");
#endif
DEBUG_ECHOLNPGM("MMU <= 'P0'");
tx_str_P(PSTR("P0\n")); // read finda
state = -4;
@ -232,9 +220,7 @@ void MMU2::mmuLoop() {
if (rx_ok()) {
sscanf(rx_buffer, "%hhuok\n", &finda);
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPAIR("MMU => ", finda, "\nMMU - ENABLED");
#endif
DEBUG_ECHOLNPAIR("MMU => ", finda, "\nMMU - ENABLED");
enabled = true;
state = 1;
@ -246,40 +232,26 @@ void MMU2::mmuLoop() {
if (WITHIN(cmd, MMU_CMD_T0, MMU_CMD_T4)) {
// tool change
int filament = cmd - MMU_CMD_T0;
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPAIR("MMU <= T", filament);
#endif
DEBUG_ECHOLNPAIR("MMU <= T", filament);
tx_printf_P(PSTR("T%d\n"), filament);
state = 3; // wait for response
}
else if (WITHIN(cmd, MMU_CMD_L0, MMU_CMD_L4)) {
// load
int filament = cmd - MMU_CMD_L0;
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPAIR("MMU <= L", filament);
#endif
DEBUG_ECHOLNPAIR("MMU <= L", filament);
tx_printf_P(PSTR("L%d\n"), filament);
state = 3; // wait for response
}
else if (cmd == MMU_CMD_C0) {
// continue loading
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("MMU <= 'C0'");
#endif
DEBUG_ECHOLNPGM("MMU <= 'C0'");
tx_str_P(PSTR("C0\n"));
state = 3; // wait for response
}
else if (cmd == MMU_CMD_U0) {
// unload current
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("MMU <= 'U0'");
#endif
DEBUG_ECHOLNPGM("MMU <= 'U0'");
tx_str_P(PSTR("U0\n"));
state = 3; // wait for response
@ -287,31 +259,22 @@ void MMU2::mmuLoop() {
else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E4)) {
// eject filament
int filament = cmd - MMU_CMD_E0;
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPAIR("MMU <= E", filament);
#endif
DEBUG_ECHOLNPAIR("MMU <= E", filament);
tx_printf_P(PSTR("E%d\n"), filament);
state = 3; // wait for response
}
else if (cmd == MMU_CMD_R0) {
// recover after eject
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("MMU <= 'R0'");
#endif
DEBUG_ECHOLNPGM("MMU <= 'R0'");
tx_str_P(PSTR("R0\n"));
state = 3; // wait for response
}
else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F4)) {
// filament type
int filament = cmd - MMU_CMD_F0;
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOPAIR("MMU <= F", filament, " ");
SERIAL_ECHO_F(cmd_arg, DEC);
SERIAL_ECHOPGM("\n");
#endif
DEBUG_ECHOPAIR("MMU <= F", filament, " ");
DEBUG_ECHO_F(cmd_arg, DEC);
DEBUG_EOL();
tx_printf_P(PSTR("F%d %d\n"), filament, cmd_arg);
state = 3; // wait for response
}
@ -330,17 +293,8 @@ void MMU2::mmuLoop() {
if (rx_ok()) {
sscanf(rx_buffer, "%hhuok\n", &finda);
#if ENABLED(MMU2_DEBUG)
// This is super annoying. Only activate if necessary
/*
if (findaRunoutValid) {
SERIAL_ECHOLNPGM("MMU <= 'P0'");
SERIAL_ECHOPGM("MMU => ");
SERIAL_ECHO_F(finda, DEC);
SERIAL_ECHOPGM("\n");
}
*/
#endif
// This is super annoying. Only activate if necessary
// if (findaRunoutValid) DEBUG_ECHOLNPAIR_F("MMU <= 'P0'\nMMU => ", finda, 6);
state = 1;
@ -355,10 +309,7 @@ void MMU2::mmuLoop() {
case 3: // response to mmu commands
if (rx_ok()) {
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("MMU => 'ok'");
#endif
DEBUG_ECHOLNPGM("MMU => 'ok'");
ready = true;
state = 1;
last_cmd = MMU_CMD_NONE;
@ -366,10 +317,7 @@ void MMU2::mmuLoop() {
else if (ELAPSED(millis(), last_request + MMU_CMD_TIMEOUT)) {
// resend request after timeout
if (last_cmd) {
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("MMU retry");
#endif
DEBUG_ECHOLNPGM("MMU retry");
cmd = last_cmd;
last_cmd = MMU_CMD_NONE;
}
@ -404,10 +352,7 @@ bool MMU2::rx_str_P(const char* str) {
rx_buffer[i] = '\0';
if (i == sizeof(rx_buffer) - 1) {
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHOLNPGM("rx buffer overrun");
#endif
DEBUG_ECHOLNPGM("rx buffer overrun");
break;
}
}
@ -876,12 +821,8 @@ void MMU2::filamentRunout() {
const float es = pgm_read_float(&(step->extrude)),
fr = pgm_read_float(&(step->feedRate));
#if ENABLED(MMU2_DEBUG)
SERIAL_ECHO_START();
SERIAL_ECHOPAIR("E step ", es);
SERIAL_CHAR('/');
SERIAL_ECHOLN(fr);
#endif
DEBUG_ECHO_START();
DEBUG_ECHOLNPAIR("E step ", es, "/", fr);
current_position[E_AXIS] += es;
planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS],