Browse Source

We always use `destination` so modify mesh_buffer_line

Scott Lahteine 9 years ago
parent
commit
07a735ad22
1 changed files with 24 additions and 23 deletions
  1. 24
    23
      Marlin/Marlin_main.cpp

+ 24
- 23
Marlin/Marlin_main.cpp View File

@@ -7841,11 +7841,11 @@ void clamp_to_software_endstops(float target[3]) {
7841 7841
 #if ENABLED(MESH_BED_LEVELING)
7842 7842
 
7843 7843
 // This function is used to split lines on mesh borders so each segment is only part of one mesh area
7844
-void mesh_buffer_line(float x, float y, float z, const float e, float fr_mm_s, const uint8_t& extruder, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
7844
+void mesh_line_to_destination(float fr_mm_m, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
7845 7845
   int cx1 = mbl.cell_index_x(RAW_CURRENT_POSITION(X_AXIS)),
7846 7846
       cy1 = mbl.cell_index_y(RAW_CURRENT_POSITION(Y_AXIS)),
7847
-      cx2 = mbl.cell_index_x(RAW_POSITION(x, X_AXIS)),
7848
-      cy2 = mbl.cell_index_y(RAW_POSITION(y, Y_AXIS));
7847
+      cx2 = mbl.cell_index_x(RAW_POSITION(destination[X_AXIS], X_AXIS)),
7848
+      cy2 = mbl.cell_index_y(RAW_POSITION(destination[Y_AXIS], Y_AXIS));
7849 7849
   NOMORE(cx1, MESH_NUM_X_POINTS - 2);
7850 7850
   NOMORE(cy1, MESH_NUM_Y_POINTS - 2);
7851 7851
   NOMORE(cx2, MESH_NUM_X_POINTS - 2);
@@ -7853,48 +7853,49 @@ void mesh_buffer_line(float x, float y, float z, const float e, float fr_mm_s, c
7853 7853
 
7854 7854
   if (cx1 == cx2 && cy1 == cy2) {
7855 7855
     // Start and end on same mesh square
7856
-    planner.buffer_line(x, y, z, e, fr_mm_s, extruder);
7856
+    line_to_destination(fr_mm_m);
7857 7857
     set_current_to_destination();
7858 7858
     return;
7859 7859
   }
7860 7860
 
7861
-  #define MBL_SEGMENT_END(axis,AXIS) (current_position[AXIS ##_AXIS] + (axis - current_position[AXIS ##_AXIS]) * normalized_dist)
7861
+  #define MBL_SEGMENT_END(A) (current_position[A ##_AXIS] + (destination[A ##_AXIS] - current_position[A ##_AXIS]) * normalized_dist)
7862 7862
 
7863
-  float nx, ny, nz, ne, normalized_dist;
7863
+  float nx, ny, normalized_dist;
7864 7864
   int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
7865 7865
   if (cx2 != cx1 && TEST(x_splits, gcx)) {
7866 7866
     nx = mbl.get_probe_x(gcx) + home_offset[X_AXIS] + position_shift[X_AXIS];
7867
-    normalized_dist = (nx - current_position[X_AXIS]) / (x - current_position[X_AXIS]);
7868
-    ny = MBL_SEGMENT_END(y, Y);
7867
+    normalized_dist = (nx - current_position[X_AXIS]) / (destination[X_AXIS] - current_position[X_AXIS]);
7868
+    ny = MBL_SEGMENT_END(Y);
7869 7869
     CBI(x_splits, gcx);
7870 7870
   }
7871 7871
   else if (cy2 != cy1 && TEST(y_splits, gcy)) {
7872 7872
     ny = mbl.get_probe_y(gcy) + home_offset[Y_AXIS] + position_shift[Y_AXIS];
7873
-    normalized_dist = (ny - current_position[Y_AXIS]) / (y - current_position[Y_AXIS]);
7874
-    nx = MBL_SEGMENT_END(x, X);
7873
+    normalized_dist = (ny - current_position[Y_AXIS]) / (destination[Y_AXIS] - current_position[Y_AXIS]);
7874
+    nx = MBL_SEGMENT_END(X);
7875 7875
     CBI(y_splits, gcy);
7876 7876
   }
7877 7877
   else {
7878 7878
     // Already split on a border
7879
-    planner.buffer_line(x, y, z, e, fr_mm_s, extruder);
7879
+    line_to_destination(fr_mm_m);
7880 7880
     set_current_to_destination();
7881 7881
     return;
7882 7882
   }
7883 7883
 
7884
-  nz = MBL_SEGMENT_END(z, Z);
7885
-  ne = MBL_SEGMENT_END(e, E);
7884
+  // Save given destination for after recursion
7885
+  float end[NUM_AXIS];
7886
+  memcpy(end, destination, sizeof(end));
7886 7887
 
7887
-  // Do the split and look for more borders
7888 7888
   destination[X_AXIS] = nx;
7889 7889
   destination[Y_AXIS] = ny;
7890
-  destination[Z_AXIS] = nz;
7891
-  destination[E_AXIS] = ne;
7892
-  mesh_buffer_line(nx, ny, nz, ne, fr_mm_s, extruder, x_splits, y_splits);
7893
-  destination[X_AXIS] = x;
7894
-  destination[Y_AXIS] = y;
7895
-  destination[Z_AXIS] = z;
7896
-  destination[E_AXIS] = e;
7897
-  mesh_buffer_line(x, y, z, e, fr_mm_s, extruder, x_splits, y_splits);
7890
+  destination[Z_AXIS] = MBL_SEGMENT_END(Z);
7891
+  destination[E_AXIS] = MBL_SEGMENT_END(E);
7892
+
7893
+  // Do the split and look for more borders
7894
+  mesh_line_to_destination(fr_mm_m, x_splits, y_splits);
7895
+
7896
+  // Restore destination from stack
7897
+  memcpy(destination, end, sizeof(end));
7898
+  mesh_line_to_destination(fr_mm_m, x_splits, y_splits);
7898 7899
 }
7899 7900
 #endif  // MESH_BED_LEVELING
7900 7901
 
@@ -7992,7 +7993,7 @@ void mesh_buffer_line(float x, float y, float z, const float e, float fr_mm_s, c
7992 7993
     else {
7993 7994
       #if ENABLED(MESH_BED_LEVELING)
7994 7995
         if (mbl.active()) {
7995
-          mesh_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], MMM_TO_MMS_SCALED(feedrate_mm_m), active_extruder);
7996
+          mesh_line_to_destination(MMM_SCALED(feedrate_mm_m));
7996 7997
           return false;
7997 7998
         }
7998 7999
         else

Loading…
Cancel
Save