Apply loop shorthand macros (#17159)
This commit is contained in:
@ -157,7 +157,7 @@ float g26_extrusion_multiplier,
|
||||
g26_layer_height,
|
||||
g26_prime_length;
|
||||
|
||||
xy_pos_t g26_pos; // = { 0, 0 }
|
||||
xy_pos_t g26_xy_pos; // = { 0, 0 }
|
||||
|
||||
int16_t g26_bed_temp,
|
||||
g26_hotend_temp;
|
||||
@ -187,29 +187,27 @@ mesh_index_pair find_closest_circle_to_print(const xy_pos_t &pos) {
|
||||
|
||||
out_point.pos = -1;
|
||||
|
||||
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
||||
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
||||
if (!circle_flags.marked(i, j)) {
|
||||
// We found a circle that needs to be printed
|
||||
const xy_pos_t m = { _GET_MESH_X(i), _GET_MESH_Y(j) };
|
||||
GRID_LOOP(i, j) {
|
||||
if (!circle_flags.marked(i, j)) {
|
||||
// We found a circle that needs to be printed
|
||||
const xy_pos_t m = { _GET_MESH_X(i), _GET_MESH_Y(j) };
|
||||
|
||||
// Get the distance to this intersection
|
||||
float f = (pos - m).magnitude();
|
||||
// Get the distance to this intersection
|
||||
float f = (pos - m).magnitude();
|
||||
|
||||
// It is possible that we are being called with the values
|
||||
// to let us find the closest circle to the start position.
|
||||
// But if this is not the case, add a small weighting to the
|
||||
// distance calculation to help it choose a better place to continue.
|
||||
f += (g26_pos - m).magnitude() / 15.0f;
|
||||
// It is possible that we are being called with the values
|
||||
// to let us find the closest circle to the start position.
|
||||
// But if this is not the case, add a small weighting to the
|
||||
// distance calculation to help it choose a better place to continue.
|
||||
f += (g26_xy_pos - m).magnitude() / 15.0f;
|
||||
|
||||
// Add the specified amount of Random Noise to our search
|
||||
if (random_deviation > 1.0) f += random(0.0, random_deviation);
|
||||
// Add the specified amount of Random Noise to our search
|
||||
if (random_deviation > 1.0) f += random(0.0, random_deviation);
|
||||
|
||||
if (f < closest) {
|
||||
closest = f; // Found a closer un-printed location
|
||||
out_point.pos.set(i, j); // Save its data
|
||||
out_point.distance = closest;
|
||||
}
|
||||
if (f < closest) {
|
||||
closest = f; // Found a closer un-printed location
|
||||
out_point.pos.set(i, j); // Save its data
|
||||
out_point.distance = closest;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -308,51 +306,49 @@ inline bool look_for_lines_to_connect() {
|
||||
xyz_pos_t s, e;
|
||||
s.z = e.z = g26_layer_height;
|
||||
|
||||
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
||||
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
||||
GRID_LOOP(i, j) {
|
||||
|
||||
#if HAS_LCD_MENU
|
||||
if (user_canceled()) return true;
|
||||
#endif
|
||||
#if HAS_LCD_MENU
|
||||
if (user_canceled()) return true;
|
||||
#endif
|
||||
|
||||
if (i < GRID_MAX_POINTS_X) { // Can't connect to anything farther to the right than GRID_MAX_POINTS_X.
|
||||
if (i < (GRID_MAX_POINTS_X)) { // Can't connect to anything farther to the right than GRID_MAX_POINTS_X.
|
||||
// Already a half circle at the edge of the bed.
|
||||
|
||||
if (circle_flags.marked(i, j) && circle_flags.marked(i + 1, j)) { // Test whether a leftward line can be done
|
||||
if (!horizontal_mesh_line_flags.marked(i, j)) {
|
||||
// Two circles need a horizontal line to connect them
|
||||
s.x = _GET_MESH_X( i ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge
|
||||
e.x = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge
|
||||
if (circle_flags.marked(i, j) && circle_flags.marked(i + 1, j)) { // Test whether a leftward line can be done
|
||||
if (!horizontal_mesh_line_flags.marked(i, j)) {
|
||||
// Two circles need a horizontal line to connect them
|
||||
s.x = _GET_MESH_X( i ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge
|
||||
e.x = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge
|
||||
|
||||
LIMIT(s.x, X_MIN_POS + 1, X_MAX_POS - 1);
|
||||
s.y = e.y = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1);
|
||||
LIMIT(e.x, X_MIN_POS + 1, X_MAX_POS - 1);
|
||||
LIMIT(s.x, X_MIN_POS + 1, X_MAX_POS - 1);
|
||||
s.y = e.y = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1);
|
||||
LIMIT(e.x, X_MIN_POS + 1, X_MAX_POS - 1);
|
||||
|
||||
if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
|
||||
print_line_from_here_to_there(s, e);
|
||||
|
||||
horizontal_mesh_line_flags.mark(i, j); // Mark done, even if skipped
|
||||
}
|
||||
}
|
||||
|
||||
if (j < (GRID_MAX_POINTS_Y)) { // Can't connect to anything further back than GRID_MAX_POINTS_Y.
|
||||
// Already a half circle at the edge of the bed.
|
||||
|
||||
if (circle_flags.marked(i, j) && circle_flags.marked(i, j + 1)) { // Test whether a downward line can be done
|
||||
if (!vertical_mesh_line_flags.marked(i, j)) {
|
||||
// Two circles that need a vertical line to connect them
|
||||
s.y = _GET_MESH_Y( j ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // top edge
|
||||
e.y = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge
|
||||
|
||||
s.x = e.x = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1);
|
||||
LIMIT(s.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
|
||||
LIMIT(e.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
|
||||
|
||||
if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
|
||||
print_line_from_here_to_there(s, e);
|
||||
|
||||
horizontal_mesh_line_flags.mark(i, j); // Mark done, even if skipped
|
||||
}
|
||||
}
|
||||
|
||||
if (j < GRID_MAX_POINTS_Y) { // Can't connect to anything further back than GRID_MAX_POINTS_Y.
|
||||
// Already a half circle at the edge of the bed.
|
||||
|
||||
if (circle_flags.marked(i, j) && circle_flags.marked(i, j + 1)) { // Test whether a downward line can be done
|
||||
if (!vertical_mesh_line_flags.marked(i, j)) {
|
||||
// Two circles that need a vertical line to connect them
|
||||
s.y = _GET_MESH_Y( j ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // top edge
|
||||
e.y = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge
|
||||
|
||||
s.x = e.x = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1);
|
||||
LIMIT(s.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
|
||||
LIMIT(e.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
|
||||
|
||||
if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
|
||||
print_line_from_here_to_there(s, e);
|
||||
|
||||
vertical_mesh_line_flags.mark(i, j); // Mark done, even if skipped
|
||||
}
|
||||
vertical_mesh_line_flags.mark(i, j); // Mark done, even if skipped
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -628,9 +624,9 @@ void GcodeSuite::G26() {
|
||||
return;
|
||||
}
|
||||
|
||||
g26_pos.set(parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position.x,
|
||||
parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position.y);
|
||||
if (!position_is_reachable(g26_pos.x, g26_pos.y)) {
|
||||
g26_xy_pos.set(parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position.x,
|
||||
parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position.y);
|
||||
if (!position_is_reachable(g26_xy_pos)) {
|
||||
SERIAL_ECHOLNPGM("?Specified X,Y coordinate out of bounds.");
|
||||
return;
|
||||
}
|
||||
@ -695,7 +691,7 @@ void GcodeSuite::G26() {
|
||||
#error "A_CNT must be a positive value. Please change A_INT."
|
||||
#endif
|
||||
float trig_table[A_CNT];
|
||||
for (uint8_t i = 0; i < A_CNT; i++)
|
||||
LOOP_L_N(i, A_CNT)
|
||||
trig_table[i] = INTERSECTION_CIRCLE_RADIUS * cos(RADIANS(i * A_INT));
|
||||
|
||||
#endif // !ARC_SUPPORT
|
||||
@ -703,7 +699,7 @@ void GcodeSuite::G26() {
|
||||
mesh_index_pair location;
|
||||
do {
|
||||
// Find the nearest confluence
|
||||
location = find_closest_circle_to_print(g26_continue_with_closest ? xy_pos_t(current_position) : g26_pos);
|
||||
location = find_closest_circle_to_print(g26_continue_with_closest ? xy_pos_t(current_position) : g26_xy_pos);
|
||||
|
||||
if (location.valid()) {
|
||||
const xy_pos_t circle = _GET_MESH_POS(location.pos);
|
||||
@ -834,12 +830,9 @@ void GcodeSuite::G26() {
|
||||
|
||||
retract_filament(destination);
|
||||
destination.z = Z_CLEARANCE_BETWEEN_PROBES;
|
||||
move_to(destination, 0); // Raise the nozzle
|
||||
|
||||
move_to(destination, 0); // Raise the nozzle
|
||||
|
||||
destination.set(g26_pos.x, g26_pos.y); // Move back to the starting position
|
||||
//destination.z = Z_CLEARANCE_BETWEEN_PROBES; // Keep the nozzle where it is
|
||||
|
||||
destination = g26_xy_pos; // Move back to the starting XY position
|
||||
move_to(destination, 0); // Move back to the starting position
|
||||
|
||||
#if DISABLED(NO_VOLUMETRICS)
|
||||
|
@ -71,13 +71,12 @@ void GcodeSuite::M420() {
|
||||
bilinear_grid_spacing.set((x_max - x_min) / (GRID_MAX_POINTS_X - 1),
|
||||
(y_max - y_min) / (GRID_MAX_POINTS_Y - 1));
|
||||
#endif
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
|
||||
Z_VALUES(x, y) = 0.001 * random(-200, 200);
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y));
|
||||
#endif
|
||||
}
|
||||
GRID_LOOP(x, y) {
|
||||
Z_VALUES(x, y) = 0.001 * random(-200, 200);
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y));
|
||||
#endif
|
||||
}
|
||||
SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
|
||||
SERIAL_ECHOPAIR(" (", x_min);
|
||||
SERIAL_CHAR(','); SERIAL_ECHO(y_min);
|
||||
|
@ -746,7 +746,7 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
// Probe at 3 arbitrary points
|
||||
|
||||
for (uint8_t i = 0; i < 3; ++i) {
|
||||
LOOP_L_N(i, 3) {
|
||||
if (verbose_level) SERIAL_ECHOLNPAIR("Probing point ", int(i), "/3.");
|
||||
#if HAS_DISPLAY
|
||||
ui.status_printf_P(0, PSTR(S_FMT " %i/3"), GET_TEXT(MSG_PROBING_MESH), int(i));
|
||||
@ -861,7 +861,7 @@ G29_TYPE GcodeSuite::G29() {
|
||||
auto print_topo_map = [&](PGM_P const title, const bool get_min) {
|
||||
serialprintPGM(title);
|
||||
for (int8_t yy = abl_grid_points.y - 1; yy >= 0; yy--) {
|
||||
for (uint8_t xx = 0; xx < abl_grid_points.x; xx++) {
|
||||
LOOP_L_N(xx, abl_grid_points.x) {
|
||||
const int ind = indexIntoAB[xx][yy];
|
||||
xyz_float_t tmp = { eqnAMatrix[ind + 0 * abl_points],
|
||||
eqnAMatrix[ind + 1 * abl_points], 0 };
|
||||
|
Reference in New Issue
Block a user