|
@ -3008,7 +3008,7 @@ inline void gcode_G28() { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int8_t ix, iy; |
|
|
int8_t px, py; |
|
|
float z; |
|
|
float z; |
|
|
|
|
|
|
|
|
switch (state) { |
|
|
switch (state) { |
|
@ -3023,10 +3023,10 @@ inline void gcode_G28() { |
|
|
SERIAL_PROTOCOLPGM("\nZ offset: "); |
|
|
SERIAL_PROTOCOLPGM("\nZ offset: "); |
|
|
SERIAL_PROTOCOL_F(mbl.z_offset, 5); |
|
|
SERIAL_PROTOCOL_F(mbl.z_offset, 5); |
|
|
SERIAL_PROTOCOLLNPGM("\nMeasured points:"); |
|
|
SERIAL_PROTOCOLLNPGM("\nMeasured points:"); |
|
|
for (int y = 0; y < MESH_NUM_Y_POINTS; y++) { |
|
|
for (py = 0; py < MESH_NUM_Y_POINTS; py++) { |
|
|
for (int x = 0; x < MESH_NUM_X_POINTS; x++) { |
|
|
for (px = 0; px < MESH_NUM_X_POINTS; px++) { |
|
|
SERIAL_PROTOCOLPGM(" "); |
|
|
SERIAL_PROTOCOLPGM(" "); |
|
|
SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5); |
|
|
SERIAL_PROTOCOL_F(mbl.z_values[py][px], 5); |
|
|
} |
|
|
} |
|
|
SERIAL_EOL; |
|
|
SERIAL_EOL; |
|
|
} |
|
|
} |
|
@ -3058,8 +3058,8 @@ inline void gcode_G28() { |
|
|
} |
|
|
} |
|
|
// If there's another point to sample, move there with optional lift.
|
|
|
// If there's another point to sample, move there with optional lift.
|
|
|
if (probe_point < (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) { |
|
|
if (probe_point < (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) { |
|
|
mbl.zigzag(probe_point, ix, iy); |
|
|
mbl.zigzag(probe_point, px, py); |
|
|
_mbl_goto_xy(mbl.get_x(ix), mbl.get_y(iy)); |
|
|
_mbl_goto_xy(mbl.get_probe_x(px), mbl.get_probe_y(py)); |
|
|
probe_point++; |
|
|
probe_point++; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
@ -3082,8 +3082,8 @@ inline void gcode_G28() { |
|
|
|
|
|
|
|
|
case MeshSet: |
|
|
case MeshSet: |
|
|
if (code_seen('X')) { |
|
|
if (code_seen('X')) { |
|
|
ix = code_value_long() - 1; |
|
|
px = code_value_long() - 1; |
|
|
if (ix < 0 || ix >= MESH_NUM_X_POINTS) { |
|
|
if (px < 0 || px >= MESH_NUM_X_POINTS) { |
|
|
SERIAL_PROTOCOLPGM("X out of range (1-" STRINGIFY(MESH_NUM_X_POINTS) ").\n"); |
|
|
SERIAL_PROTOCOLPGM("X out of range (1-" STRINGIFY(MESH_NUM_X_POINTS) ").\n"); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -3093,8 +3093,8 @@ inline void gcode_G28() { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
if (code_seen('Y')) { |
|
|
if (code_seen('Y')) { |
|
|
iy = code_value_long() - 1; |
|
|
py = code_value_long() - 1; |
|
|
if (iy < 0 || iy >= MESH_NUM_Y_POINTS) { |
|
|
if (py < 0 || py >= MESH_NUM_Y_POINTS) { |
|
|
SERIAL_PROTOCOLPGM("Y out of range (1-" STRINGIFY(MESH_NUM_Y_POINTS) ").\n"); |
|
|
SERIAL_PROTOCOLPGM("Y out of range (1-" STRINGIFY(MESH_NUM_Y_POINTS) ").\n"); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -3110,7 +3110,7 @@ inline void gcode_G28() { |
|
|
SERIAL_PROTOCOLPGM("Z not entered.\n"); |
|
|
SERIAL_PROTOCOLPGM("Z not entered.\n"); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
mbl.z_values[iy][ix] = z; |
|
|
mbl.z_values[py][px] = z; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case MeshSetZOffset: |
|
|
case MeshSetZOffset: |
|
@ -5904,39 +5904,35 @@ inline void gcode_M410() { stepper.quick_stop(); } |
|
|
* Use either 'M421 X<mm> Y<mm> Z<mm>' or 'M421 I<xindex> J<yindex> Z<mm>' |
|
|
* Use either 'M421 X<mm> Y<mm> Z<mm>' or 'M421 I<xindex> J<yindex> Z<mm>' |
|
|
*/ |
|
|
*/ |
|
|
inline void gcode_M421() { |
|
|
inline void gcode_M421() { |
|
|
float x = 0, y = 0, z = 0; |
|
|
int8_t px, py; |
|
|
int8_t i = 0, j = 0; |
|
|
float z = 0; |
|
|
bool err = false, hasX, hasY, hasZ, hasI, hasJ; |
|
|
bool hasX, hasY, hasZ, hasI, hasJ; |
|
|
if ((hasX = code_seen('X'))) x = code_value(); |
|
|
if ((hasX = code_seen('X'))) px = mbl.probe_index_x(code_value()); |
|
|
if ((hasY = code_seen('Y'))) y = code_value(); |
|
|
if ((hasY = code_seen('Y'))) py = mbl.probe_index_y(code_value()); |
|
|
if ((hasI = code_seen('I'))) i = code_value(); |
|
|
if ((hasI = code_seen('I'))) px = code_value(); |
|
|
if ((hasJ = code_seen('J'))) j = code_value(); |
|
|
if ((hasJ = code_seen('J'))) py = code_value(); |
|
|
if ((hasZ = code_seen('Z'))) z = code_value(); |
|
|
if ((hasZ = code_seen('Z'))) z = code_value(); |
|
|
|
|
|
|
|
|
if (hasX && hasY && hasZ) { |
|
|
if (hasX && hasY && hasZ) { |
|
|
|
|
|
|
|
|
int8_t ix = mbl.select_x_index(x), |
|
|
if (px >= 0 && py >= 0) |
|
|
iy = mbl.select_y_index(y); |
|
|
mbl.set_z(px, py, z); |
|
|
|
|
|
|
|
|
if (ix >= 0 && iy >= 0) |
|
|
|
|
|
mbl.set_z(ix, iy, z); |
|
|
|
|
|
else { |
|
|
else { |
|
|
SERIAL_ERROR_START; |
|
|
SERIAL_ERROR_START; |
|
|
SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY); |
|
|
SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if (hasI && hasJ && hasZ) { |
|
|
else if (hasI && hasJ && hasZ) { |
|
|
if (i >= 0 && i < MESH_NUM_X_POINTS && j >= 0 && j < MESH_NUM_Y_POINTS) |
|
|
if (px >= 0 && px < MESH_NUM_X_POINTS && py >= 0 && py < MESH_NUM_Y_POINTS) |
|
|
mbl.set_z(i, j, z); |
|
|
mbl.set_z(px, py, z); |
|
|
else { |
|
|
else { |
|
|
SERIAL_ERROR_START; |
|
|
SERIAL_ERROR_START; |
|
|
SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY); |
|
|
SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
else { |
|
|
{ |
|
|
|
|
|
SERIAL_ERROR_START; |
|
|
SERIAL_ERROR_START; |
|
|
SERIAL_ERRORLNPGM(MSG_ERR_M421_REQUIRES_XYZ); |
|
|
SERIAL_ERRORLNPGM(MSG_ERR_M421_PARAMETERS); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -7303,52 +7299,52 @@ void mesh_buffer_line(float x, float y, float z, const float e, float feed_rate, |
|
|
set_current_to_destination(); |
|
|
set_current_to_destination(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
int pix = mbl.select_x_index(current_position[X_AXIS] - home_offset[X_AXIS]); |
|
|
int pcx = mbl.cel_index_x(current_position[X_AXIS] - home_offset[X_AXIS]); |
|
|
int piy = mbl.select_y_index(current_position[Y_AXIS] - home_offset[Y_AXIS]); |
|
|
int pcy = mbl.cel_index_y(current_position[Y_AXIS] - home_offset[Y_AXIS]); |
|
|
int ix = mbl.select_x_index(x - home_offset[X_AXIS]); |
|
|
int cx = mbl.cel_index_x(x - home_offset[X_AXIS]); |
|
|
int iy = mbl.select_y_index(y - home_offset[Y_AXIS]); |
|
|
int cy = mbl.cel_index_y(y - home_offset[Y_AXIS]); |
|
|
pix = min(pix, MESH_NUM_X_POINTS - 2); |
|
|
NOMORE(pcx, MESH_NUM_X_POINTS - 2); |
|
|
piy = min(piy, MESH_NUM_Y_POINTS - 2); |
|
|
NOMORE(pcy, MESH_NUM_Y_POINTS - 2); |
|
|
ix = min(ix, MESH_NUM_X_POINTS - 2); |
|
|
NOMORE(cx, MESH_NUM_X_POINTS - 2); |
|
|
iy = min(iy, MESH_NUM_Y_POINTS - 2); |
|
|
NOMORE(cy, MESH_NUM_Y_POINTS - 2); |
|
|
if (pix == ix && piy == iy) { |
|
|
if (pcx == cx && pcy == cy) { |
|
|
// Start and end on same mesh square
|
|
|
// Start and end on same mesh square
|
|
|
planner.buffer_line(x, y, z, e, feed_rate, extruder); |
|
|
planner.buffer_line(x, y, z, e, feed_rate, extruder); |
|
|
set_current_to_destination(); |
|
|
set_current_to_destination(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
float nx, ny, nz, ne, normalized_dist; |
|
|
float nx, ny, nz, ne, normalized_dist; |
|
|
if (ix > pix && TEST(x_splits, ix)) { |
|
|
if (cx > pcx && TEST(x_splits, cx)) { |
|
|
nx = mbl.get_x(ix) + home_offset[X_AXIS]; |
|
|
nx = mbl.get_probe_x(cx) + home_offset[X_AXIS]; |
|
|
normalized_dist = (nx - current_position[X_AXIS]) / (x - current_position[X_AXIS]); |
|
|
normalized_dist = (nx - current_position[X_AXIS]) / (x - current_position[X_AXIS]); |
|
|
ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist; |
|
|
ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist; |
|
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist; |
|
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist; |
|
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist; |
|
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist; |
|
|
CBI(x_splits, ix); |
|
|
CBI(x_splits, cx); |
|
|
} |
|
|
} |
|
|
else if (ix < pix && TEST(x_splits, pix)) { |
|
|
else if (cx < pcx && TEST(x_splits, pcx)) { |
|
|
nx = mbl.get_x(pix) + home_offset[X_AXIS]; |
|
|
nx = mbl.get_probe_x(pcx) + home_offset[X_AXIS]; |
|
|
normalized_dist = (nx - current_position[X_AXIS]) / (x - current_position[X_AXIS]); |
|
|
normalized_dist = (nx - current_position[X_AXIS]) / (x - current_position[X_AXIS]); |
|
|
ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist; |
|
|
ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist; |
|
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist; |
|
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist; |
|
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist; |
|
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist; |
|
|
CBI(x_splits, pix); |
|
|
CBI(x_splits, pcx); |
|
|
} |
|
|
} |
|
|
else if (iy > piy && TEST(y_splits, iy)) { |
|
|
else if (cy > pcy && TEST(y_splits, cy)) { |
|
|
ny = mbl.get_y(iy) + home_offset[Y_AXIS]; |
|
|
ny = mbl.get_probe_y(cy) + home_offset[Y_AXIS]; |
|
|
normalized_dist = (ny - current_position[Y_AXIS]) / (y - current_position[Y_AXIS]); |
|
|
normalized_dist = (ny - current_position[Y_AXIS]) / (y - current_position[Y_AXIS]); |
|
|
nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist; |
|
|
nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist; |
|
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist; |
|
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist; |
|
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist; |
|
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist; |
|
|
CBI(y_splits, iy); |
|
|
CBI(y_splits, cy); |
|
|
} |
|
|
} |
|
|
else if (iy < piy && TEST(y_splits, piy)) { |
|
|
else if (cy < pcy && TEST(y_splits, pcy)) { |
|
|
ny = mbl.get_y(piy) + home_offset[Y_AXIS]; |
|
|
ny = mbl.get_probe_y(pcy) + home_offset[Y_AXIS]; |
|
|
normalized_dist = (ny - current_position[Y_AXIS]) / (y - current_position[Y_AXIS]); |
|
|
normalized_dist = (ny - current_position[Y_AXIS]) / (y - current_position[Y_AXIS]); |
|
|
nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist; |
|
|
nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist; |
|
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist; |
|
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist; |
|
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist; |
|
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist; |
|
|
CBI(y_splits, piy); |
|
|
CBI(y_splits, pcy); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
// Already split on a border
|
|
|
// Already split on a border
|
|
|