|
@@ -3008,7 +3008,7 @@ inline void gcode_G28() {
|
3008
|
3008
|
return;
|
3009
|
3009
|
}
|
3010
|
3010
|
|
3011
|
|
- int8_t ix, iy;
|
|
3011
|
+ int8_t px, py;
|
3012
|
3012
|
float z;
|
3013
|
3013
|
|
3014
|
3014
|
switch (state) {
|
|
@@ -3023,10 +3023,10 @@ inline void gcode_G28() {
|
3023
|
3023
|
SERIAL_PROTOCOLPGM("\nZ offset: ");
|
3024
|
3024
|
SERIAL_PROTOCOL_F(mbl.z_offset, 5);
|
3025
|
3025
|
SERIAL_PROTOCOLLNPGM("\nMeasured points:");
|
3026
|
|
- for (int y = 0; y < MESH_NUM_Y_POINTS; y++) {
|
3027
|
|
- for (int x = 0; x < MESH_NUM_X_POINTS; x++) {
|
|
3026
|
+ for (py = 0; py < MESH_NUM_Y_POINTS; py++) {
|
|
3027
|
+ for (px = 0; px < MESH_NUM_X_POINTS; px++) {
|
3028
|
3028
|
SERIAL_PROTOCOLPGM(" ");
|
3029
|
|
- SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5);
|
|
3029
|
+ SERIAL_PROTOCOL_F(mbl.z_values[py][px], 5);
|
3030
|
3030
|
}
|
3031
|
3031
|
SERIAL_EOL;
|
3032
|
3032
|
}
|
|
@@ -3058,8 +3058,8 @@ inline void gcode_G28() {
|
3058
|
3058
|
}
|
3059
|
3059
|
// If there's another point to sample, move there with optional lift.
|
3060
|
3060
|
if (probe_point < (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
|
3061
|
|
- mbl.zigzag(probe_point, ix, iy);
|
3062
|
|
- _mbl_goto_xy(mbl.get_x(ix), mbl.get_y(iy));
|
|
3061
|
+ mbl.zigzag(probe_point, px, py);
|
|
3062
|
+ _mbl_goto_xy(mbl.get_probe_x(px), mbl.get_probe_y(py));
|
3063
|
3063
|
probe_point++;
|
3064
|
3064
|
}
|
3065
|
3065
|
else {
|
|
@@ -3082,8 +3082,8 @@ inline void gcode_G28() {
|
3082
|
3082
|
|
3083
|
3083
|
case MeshSet:
|
3084
|
3084
|
if (code_seen('X')) {
|
3085
|
|
- ix = code_value_long() - 1;
|
3086
|
|
- if (ix < 0 || ix >= MESH_NUM_X_POINTS) {
|
|
3085
|
+ px = code_value_long() - 1;
|
|
3086
|
+ if (px < 0 || px >= MESH_NUM_X_POINTS) {
|
3087
|
3087
|
SERIAL_PROTOCOLPGM("X out of range (1-" STRINGIFY(MESH_NUM_X_POINTS) ").\n");
|
3088
|
3088
|
return;
|
3089
|
3089
|
}
|
|
@@ -3093,8 +3093,8 @@ inline void gcode_G28() {
|
3093
|
3093
|
return;
|
3094
|
3094
|
}
|
3095
|
3095
|
if (code_seen('Y')) {
|
3096
|
|
- iy = code_value_long() - 1;
|
3097
|
|
- if (iy < 0 || iy >= MESH_NUM_Y_POINTS) {
|
|
3096
|
+ py = code_value_long() - 1;
|
|
3097
|
+ if (py < 0 || py >= MESH_NUM_Y_POINTS) {
|
3098
|
3098
|
SERIAL_PROTOCOLPGM("Y out of range (1-" STRINGIFY(MESH_NUM_Y_POINTS) ").\n");
|
3099
|
3099
|
return;
|
3100
|
3100
|
}
|
|
@@ -3110,7 +3110,7 @@ inline void gcode_G28() {
|
3110
|
3110
|
SERIAL_PROTOCOLPGM("Z not entered.\n");
|
3111
|
3111
|
return;
|
3112
|
3112
|
}
|
3113
|
|
- mbl.z_values[iy][ix] = z;
|
|
3113
|
+ mbl.z_values[py][px] = z;
|
3114
|
3114
|
break;
|
3115
|
3115
|
|
3116
|
3116
|
case MeshSetZOffset:
|
|
@@ -5904,39 +5904,35 @@ inline void gcode_M410() { stepper.quick_stop(); }
|
5904
|
5904
|
* Use either 'M421 X<mm> Y<mm> Z<mm>' or 'M421 I<xindex> J<yindex> Z<mm>'
|
5905
|
5905
|
*/
|
5906
|
5906
|
inline void gcode_M421() {
|
5907
|
|
- float x = 0, y = 0, z = 0;
|
5908
|
|
- int8_t i = 0, j = 0;
|
5909
|
|
- bool err = false, hasX, hasY, hasZ, hasI, hasJ;
|
5910
|
|
- if ((hasX = code_seen('X'))) x = code_value();
|
5911
|
|
- if ((hasY = code_seen('Y'))) y = code_value();
|
5912
|
|
- if ((hasI = code_seen('I'))) i = code_value();
|
5913
|
|
- if ((hasJ = code_seen('J'))) j = code_value();
|
|
5907
|
+ int8_t px, py;
|
|
5908
|
+ float z = 0;
|
|
5909
|
+ bool hasX, hasY, hasZ, hasI, hasJ;
|
|
5910
|
+ if ((hasX = code_seen('X'))) px = mbl.probe_index_x(code_value());
|
|
5911
|
+ if ((hasY = code_seen('Y'))) py = mbl.probe_index_y(code_value());
|
|
5912
|
+ if ((hasI = code_seen('I'))) px = code_value();
|
|
5913
|
+ if ((hasJ = code_seen('J'))) py = code_value();
|
5914
|
5914
|
if ((hasZ = code_seen('Z'))) z = code_value();
|
5915
|
5915
|
|
5916
|
5916
|
if (hasX && hasY && hasZ) {
|
5917
|
5917
|
|
5918
|
|
- int8_t ix = mbl.select_x_index(x),
|
5919
|
|
- iy = mbl.select_y_index(y);
|
5920
|
|
-
|
5921
|
|
- if (ix >= 0 && iy >= 0)
|
5922
|
|
- mbl.set_z(ix, iy, z);
|
|
5918
|
+ if (px >= 0 && py >= 0)
|
|
5919
|
+ mbl.set_z(px, py, z);
|
5923
|
5920
|
else {
|
5924
|
5921
|
SERIAL_ERROR_START;
|
5925
|
5922
|
SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY);
|
5926
|
5923
|
}
|
5927
|
5924
|
}
|
5928
|
5925
|
else if (hasI && hasJ && hasZ) {
|
5929
|
|
- if (i >= 0 && i < MESH_NUM_X_POINTS && j >= 0 && j < MESH_NUM_Y_POINTS)
|
5930
|
|
- mbl.set_z(i, j, z);
|
|
5926
|
+ if (px >= 0 && px < MESH_NUM_X_POINTS && py >= 0 && py < MESH_NUM_Y_POINTS)
|
|
5927
|
+ mbl.set_z(px, py, z);
|
5931
|
5928
|
else {
|
5932
|
5929
|
SERIAL_ERROR_START;
|
5933
|
5930
|
SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY);
|
5934
|
5931
|
}
|
5935
|
5932
|
}
|
5936
|
|
- else
|
5937
|
|
- {
|
|
5933
|
+ else {
|
5938
|
5934
|
SERIAL_ERROR_START;
|
5939
|
|
- SERIAL_ERRORLNPGM(MSG_ERR_M421_REQUIRES_XYZ);
|
|
5935
|
+ SERIAL_ERRORLNPGM(MSG_ERR_M421_PARAMETERS);
|
5940
|
5936
|
}
|
5941
|
5937
|
}
|
5942
|
5938
|
|
|
@@ -7303,52 +7299,52 @@ void mesh_buffer_line(float x, float y, float z, const float e, float feed_rate,
|
7303
|
7299
|
set_current_to_destination();
|
7304
|
7300
|
return;
|
7305
|
7301
|
}
|
7306
|
|
- int pix = mbl.select_x_index(current_position[X_AXIS] - home_offset[X_AXIS]);
|
7307
|
|
- int piy = mbl.select_y_index(current_position[Y_AXIS] - home_offset[Y_AXIS]);
|
7308
|
|
- int ix = mbl.select_x_index(x - home_offset[X_AXIS]);
|
7309
|
|
- int iy = mbl.select_y_index(y - home_offset[Y_AXIS]);
|
7310
|
|
- pix = min(pix, MESH_NUM_X_POINTS - 2);
|
7311
|
|
- piy = min(piy, MESH_NUM_Y_POINTS - 2);
|
7312
|
|
- ix = min(ix, MESH_NUM_X_POINTS - 2);
|
7313
|
|
- iy = min(iy, MESH_NUM_Y_POINTS - 2);
|
7314
|
|
- if (pix == ix && piy == iy) {
|
|
7302
|
+ int pcx = mbl.cel_index_x(current_position[X_AXIS] - home_offset[X_AXIS]);
|
|
7303
|
+ int pcy = mbl.cel_index_y(current_position[Y_AXIS] - home_offset[Y_AXIS]);
|
|
7304
|
+ int cx = mbl.cel_index_x(x - home_offset[X_AXIS]);
|
|
7305
|
+ int cy = mbl.cel_index_y(y - home_offset[Y_AXIS]);
|
|
7306
|
+ NOMORE(pcx, MESH_NUM_X_POINTS - 2);
|
|
7307
|
+ NOMORE(pcy, MESH_NUM_Y_POINTS - 2);
|
|
7308
|
+ NOMORE(cx, MESH_NUM_X_POINTS - 2);
|
|
7309
|
+ NOMORE(cy, MESH_NUM_Y_POINTS - 2);
|
|
7310
|
+ if (pcx == cx && pcy == cy) {
|
7315
|
7311
|
// Start and end on same mesh square
|
7316
|
7312
|
planner.buffer_line(x, y, z, e, feed_rate, extruder);
|
7317
|
7313
|
set_current_to_destination();
|
7318
|
7314
|
return;
|
7319
|
7315
|
}
|
7320
|
7316
|
float nx, ny, nz, ne, normalized_dist;
|
7321
|
|
- if (ix > pix && TEST(x_splits, ix)) {
|
7322
|
|
- nx = mbl.get_x(ix) + home_offset[X_AXIS];
|
|
7317
|
+ if (cx > pcx && TEST(x_splits, cx)) {
|
|
7318
|
+ nx = mbl.get_probe_x(cx) + home_offset[X_AXIS];
|
7323
|
7319
|
normalized_dist = (nx - current_position[X_AXIS]) / (x - current_position[X_AXIS]);
|
7324
|
7320
|
ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist;
|
7325
|
7321
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist;
|
7326
|
7322
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
|
7327
|
|
- CBI(x_splits, ix);
|
|
7323
|
+ CBI(x_splits, cx);
|
7328
|
7324
|
}
|
7329
|
|
- else if (ix < pix && TEST(x_splits, pix)) {
|
7330
|
|
- nx = mbl.get_x(pix) + home_offset[X_AXIS];
|
|
7325
|
+ else if (cx < pcx && TEST(x_splits, pcx)) {
|
|
7326
|
+ nx = mbl.get_probe_x(pcx) + home_offset[X_AXIS];
|
7331
|
7327
|
normalized_dist = (nx - current_position[X_AXIS]) / (x - current_position[X_AXIS]);
|
7332
|
7328
|
ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist;
|
7333
|
7329
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist;
|
7334
|
7330
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
|
7335
|
|
- CBI(x_splits, pix);
|
|
7331
|
+ CBI(x_splits, pcx);
|
7336
|
7332
|
}
|
7337
|
|
- else if (iy > piy && TEST(y_splits, iy)) {
|
7338
|
|
- ny = mbl.get_y(iy) + home_offset[Y_AXIS];
|
|
7333
|
+ else if (cy > pcy && TEST(y_splits, cy)) {
|
|
7334
|
+ ny = mbl.get_probe_y(cy) + home_offset[Y_AXIS];
|
7339
|
7335
|
normalized_dist = (ny - current_position[Y_AXIS]) / (y - current_position[Y_AXIS]);
|
7340
|
7336
|
nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist;
|
7341
|
7337
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist;
|
7342
|
7338
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
|
7343
|
|
- CBI(y_splits, iy);
|
|
7339
|
+ CBI(y_splits, cy);
|
7344
|
7340
|
}
|
7345
|
|
- else if (iy < piy && TEST(y_splits, piy)) {
|
7346
|
|
- ny = mbl.get_y(piy) + home_offset[Y_AXIS];
|
|
7341
|
+ else if (cy < pcy && TEST(y_splits, pcy)) {
|
|
7342
|
+ ny = mbl.get_probe_y(pcy) + home_offset[Y_AXIS];
|
7347
|
7343
|
normalized_dist = (ny - current_position[Y_AXIS]) / (y - current_position[Y_AXIS]);
|
7348
|
7344
|
nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist;
|
7349
|
7345
|
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist;
|
7350
|
7346
|
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
|
7351
|
|
- CBI(y_splits, piy);
|
|
7347
|
+ CBI(y_splits, pcy);
|
7352
|
7348
|
}
|
7353
|
7349
|
else {
|
7354
|
7350
|
// Already split on a border
|