Browse Source

Merge pull request #3760 from thinkyhead/rc_fix_mbl_m503_output

Fix various issues with MBL command M421
Scott Lahteine 8 years ago
parent
commit
86ac48a374

+ 13
- 10
Marlin/Marlin_main.cpp View File

@@ -5851,19 +5851,22 @@ inline void gcode_M410() { stepper.quick_stop(); }
5851 5851
     if ((hasY = code_seen('Y'))) y = code_value();
5852 5852
     if ((hasZ = code_seen('Z'))) z = code_value();
5853 5853
 
5854
-    if (!hasX || !hasY || !hasZ) {
5855
-      SERIAL_ERROR_START;
5856
-      SERIAL_ERRORLNPGM(MSG_ERR_M421_REQUIRES_XYZ);
5857
-      err = true;
5858
-    }
5854
+    if (hasX && hasY && hasZ) {
5859 5855
 
5860
-    if (x >= MESH_NUM_X_POINTS || y >= MESH_NUM_Y_POINTS) {
5856
+      int8_t ix = mbl.select_x_index(x),
5857
+             iy = mbl.select_y_index(y);
5858
+
5859
+      if (ix >= 0 && iy >= 0)
5860
+        mbl.set_z(ix, iy, z);
5861
+      else {
5862
+        SERIAL_ERROR_START;
5863
+        SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY);
5864
+      }
5865
+    }
5866
+    else {
5861 5867
       SERIAL_ERROR_START;
5862
-      SERIAL_ERRORLNPGM(MSG_ERR_MESH_INDEX_OOB);
5863
-      err = true;
5868
+      SERIAL_ERRORLNPGM(MSG_ERR_M421_REQUIRES_XYZ);
5864 5869
     }
5865
-
5866
-    if (!err) mbl.set_z(mbl.select_x_index(x), mbl.select_y_index(y), z);
5867 5870
   }
5868 5871
 
5869 5872
 #endif

+ 2
- 1
Marlin/configuration_store.cpp View File

@@ -738,7 +738,8 @@ void Config_PrintSettings(bool forReplay) {
738 738
         CONFIG_ECHO_START;
739 739
         SERIAL_ECHOPAIR("  M421 X", mbl.get_x(x));
740 740
         SERIAL_ECHOPAIR(" Y", mbl.get_y(y));
741
-        SERIAL_ECHOPAIR(" Z", mbl.z_values[y][x]);
741
+        SERIAL_ECHOPGM(" Z");
742
+        SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5);
742 743
         SERIAL_EOL;
743 744
       }
744 745
     }

+ 1
- 1
Marlin/language.h View File

@@ -148,7 +148,7 @@
148 148
 #define MSG_Z_PROBE                         "z_probe: "
149 149
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
150 150
 #define MSG_ERR_M421_REQUIRES_XYZ           "M421 requires XYZ parameters"
151
-#define MSG_ERR_MESH_INDEX_OOB              "Mesh XY index is out of bounds"
151
+#define MSG_ERR_MESH_XY                     "Mesh XY cannot be resolved"
152 152
 #define MSG_ERR_M428_TOO_FAR                "Too far from reference point"
153 153
 #define MSG_ERR_M303_DISABLED               "PIDTEMP disabled"
154 154
 #define MSG_M119_REPORT                     "Reporting endstop status"

+ 2
- 2
Marlin/mesh_bed_leveling.cpp View File

@@ -31,8 +31,8 @@
31 31
   void mesh_bed_leveling::reset() {
32 32
     active = 0;
33 33
     z_offset = 0;
34
-    for (int y = 0; y < MESH_NUM_Y_POINTS; y++)
35
-      for (int x = 0; x < MESH_NUM_X_POINTS; x++)
34
+    for (int8_t y = MESH_NUM_Y_POINTS; y--;)
35
+      for (int8_t x = MESH_NUM_X_POINTS; x--;)
36 36
         z_values[y][x] = 0;
37 37
   }
38 38
 

+ 18
- 15
Marlin/mesh_bed_leveling.h View File

@@ -37,32 +37,34 @@
37 37
 
38 38
     void reset();
39 39
 
40
-    float get_x(int i) { return MESH_MIN_X + (MESH_X_DIST) * i; }
41
-    float get_y(int i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
42
-    void set_z(int ix, int iy, float z) { z_values[iy][ix] = z; }
40
+    static FORCE_INLINE float get_x(int8_t i) { return MESH_MIN_X + (MESH_X_DIST) * i; }
41
+    static FORCE_INLINE float get_y(int8_t i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
42
+    void set_z(int8_t ix, int8_t iy, float z) { z_values[iy][ix] = z; }
43 43
 
44
-    inline void zigzag(int index, int &ix, int &iy) {
44
+    inline void zigzag(int8_t index, int8_t &ix, int8_t &iy) {
45 45
       ix = index % (MESH_NUM_X_POINTS);
46 46
       iy = index / (MESH_NUM_X_POINTS);
47 47
       if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
48 48
     }
49 49
 
50
-    void set_zigzag_z(int index, float z) {
50
+    void set_zigzag_z(int8_t index, float z) {
51 51
       int ix, iy;
52 52
       zigzag(index, ix, iy);
53 53
       set_z(ix, iy, z);
54 54
     }
55 55
 
56
-    int select_x_index(float x) {
57
-      int i = 1;
58
-      while (x > get_x(i) && i < MESH_NUM_X_POINTS - 1) i++;
59
-      return i - 1;
56
+    int8_t select_x_index(float x) {
57
+      for (uint8_t i = MESH_NUM_X_POINTS; i--;)
58
+        if (fabs(x - get_x(i)) <= (MESH_X_DIST) / 2)
59
+          return i;
60
+      return -1;
60 61
     }
61 62
 
62
-    int select_y_index(float y) {
63
-      int i = 1;
64
-      while (y > get_y(i) && i < MESH_NUM_Y_POINTS - 1) i++;
65
-      return i - 1;
63
+    int8_t select_y_index(float y) {
64
+      for (uint8_t i = MESH_NUM_Y_POINTS; i--;)
65
+        if (fabs(y - get_y(i)) <= (MESH_Y_DIST) / 2)
66
+          return i;
67
+      return -1;
66 68
     }
67 69
 
68 70
     float calc_z0(float a0, float a1, float z1, float a2, float z2) {
@@ -72,8 +74,9 @@
72 74
     }
73 75
 
74 76
     float get_z(float x0, float y0) {
75
-      int x_index = select_x_index(x0);
76
-      int y_index = select_y_index(y0);
77
+      int8_t x_index = select_x_index(x0);
78
+      int8_t y_index = select_y_index(y0);
79
+      if (x_index < 0 || y_index < 0) return z_offset;
77 80
       float z1 = calc_z0(x0,
78 81
                          get_x(x_index), z_values[y_index][x_index],
79 82
                          get_x(x_index + 1), z_values[y_index][x_index + 1]);

Loading…
Cancel
Save