|
@@ -36,28 +36,39 @@
|
36
|
36
|
#endif
|
37
|
37
|
|
38
|
38
|
/**
|
39
|
|
- * M421: Set a single Mesh Bed Leveling Z coordinate
|
|
39
|
+ * M421: Set one or more Mesh Bed Leveling Z coordinates
|
40
|
40
|
*
|
41
|
41
|
* Usage:
|
42
|
42
|
* M421 I<xindex> J<yindex> Z<linear>
|
43
|
43
|
* M421 I<xindex> J<yindex> Q<offset>
|
|
44
|
+ *
|
|
45
|
+ * - If I is omitted, set the entire row
|
|
46
|
+ * - If J is omitted, set the entire column
|
|
47
|
+ * - If both I and J are omitted, set all
|
44
|
48
|
*/
|
45
|
49
|
void GcodeSuite::M421() {
|
46
|
50
|
int8_t ix = parser.intval('I', -1), iy = parser.intval('J', -1);
|
47
|
|
- const bool hasI = ix >= 0,
|
48
|
|
- hasJ = iy >= 0,
|
49
|
|
- hasZ = parser.seen('Z'),
|
50
|
|
- hasQ = !hasZ && parser.seen('Q');
|
|
51
|
+ const bool hasZ = parser.seenval('Z'),
|
|
52
|
+ hasQ = !hasZ && parser.seenval('Q');
|
51
|
53
|
|
52
|
|
- if (!hasI || !hasJ || !(hasZ || hasQ))
|
53
|
|
- SERIAL_ERROR_MSG(STR_ERR_M421_PARAMETERS);
|
54
|
|
- else if (!WITHIN(ix, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(iy, 0, GRID_MAX_POINTS_Y - 1))
|
55
|
|
- SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
|
56
|
|
- else {
|
57
|
|
- z_values[ix][iy] = parser.value_linear_units() + (hasQ ? z_values[ix][iy] : 0);
|
58
|
|
- TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
|
59
|
|
- TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, z_values[ix][iy]));
|
|
54
|
+ if (hasZ || hasQ) {
|
|
55
|
+ if (WITHIN(ix, -1, GRID_MAX_POINTS_X - 1) && WITHIN(iy, -1, GRID_MAX_POINTS_Y - 1)) {
|
|
56
|
+ const float zval = parser.value_linear_units();
|
|
57
|
+ uint8_t sx = ix >= 0 ? ix : 0, ex = ix >= 0 ? ix : GRID_MAX_POINTS_X - 1,
|
|
58
|
+ sy = iy >= 0 ? iy : 0, ey = iy >= 0 ? iy : GRID_MAX_POINTS_Y - 1;
|
|
59
|
+ LOOP_S_LE_N(x, sx, ex) {
|
|
60
|
+ LOOP_S_LE_N(y, sy, ey) {
|
|
61
|
+ z_values[x][y] = zval + (hasQ ? z_values[x][y] : 0);
|
|
62
|
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y]));
|
|
63
|
+ }
|
|
64
|
+ }
|
|
65
|
+ TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
|
|
66
|
+ }
|
|
67
|
+ else
|
|
68
|
+ SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
|
60
|
69
|
}
|
|
70
|
+ else
|
|
71
|
+ SERIAL_ERROR_MSG(STR_ERR_M421_PARAMETERS);
|
61
|
72
|
}
|
62
|
73
|
|
63
|
74
|
#endif // AUTO_BED_LEVELING_BILINEAR
|