Ver código fonte

Standard function to turn bed leveling on/off

Scott Lahteine 8 anos atrás
pai
commit
510ef5d14a
1 arquivos alterados com 55 adições e 16 exclusões
  1. 55
    16
      Marlin/Marlin_main.cpp

+ 55
- 16
Marlin/Marlin_main.cpp Ver arquivo

@@ -2132,30 +2132,69 @@ static void clean_up_after_endstop_or_probe_move() {
2132 2132
 
2133 2133
 #endif // HAS_BED_PROBE
2134 2134
 
2135
-#if HAS_ABL
2135
+#if PLANNER_LEVELING
2136
+  /**
2137
+   * Turn bed leveling on or off, fixing the current
2138
+   * position as-needed.
2139
+   *
2140
+   * Disable: Current position = physical position
2141
+   *  Enable: Current position = "unleveled" physical position
2142
+   */
2143
+  void set_bed_leveling_enabled(bool enable=true) {
2144
+    #if ENABLED(MESH_BED_LEVELING)
2145
+
2146
+      if (!enable && mbl.active())
2147
+        current_position[Z_AXIS] +=
2148
+          mbl.get_z(RAW_CURRENT_POSITION(X_AXIS), RAW_CURRENT_POSITION(Y_AXIS)) - (MESH_HOME_SEARCH_Z);
2149
+
2150
+      mbl.set_active(enable && mbl.has_mesh()); // was set_has_mesh(). Is this not correct?
2151
+
2152
+    #elif HAS_ABL
2153
+
2154
+      if (enable != planner.abl_enabled) {
2155
+        planner.abl_enabled = !planner.abl_enabled;
2156
+        if (!planner.abl_enabled)
2157
+          set_current_from_steppers_for_axis(
2158
+            #if ABL_PLANAR
2159
+              ALL_AXES
2160
+            #else
2161
+              Z_AXIS
2162
+            #endif
2163
+          );
2164
+        else
2165
+          planner.unapply_leveling(current_position);
2166
+      }
2167
+
2168
+    #endif
2169
+  }
2170
+
2136 2171
 
2137 2172
   /**
2138 2173
    * Reset calibration results to zero.
2139
-   *
2140
-   * TODO: Proper functions to disable / enable
2141
-   *       bed leveling via a flag, correcting the
2142
-   *       current position in each case.
2143 2174
    */
2144 2175
   void reset_bed_level() {
2145
-    planner.abl_enabled = false;
2146
-    #if ENABLED(DEBUG_LEVELING_FEATURE)
2147
-      if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("reset_bed_level");
2148
-    #endif
2149
-    #if ABL_PLANAR
2150
-      planner.bed_level_matrix.set_to_identity();
2151
-    #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
2152
-      for (uint8_t x = 0; x < ABL_GRID_POINTS_X; x++)
2153
-        for (uint8_t y = 0; y < ABL_GRID_POINTS_Y; y++)
2154
-          bed_level_grid[x][y] = 1000.0;
2176
+    #if ENABLED(MESH_BED_LEVELING)
2177
+      if (mbl.has_mesh()) {
2178
+        set_bed_leveling_enabled(false);
2179
+        mbl.reset();
2180
+        mbl.set_has_mesh(false);
2181
+      }
2182
+    #else
2183
+      planner.abl_enabled = false;
2184
+      #if ENABLED(DEBUG_LEVELING_FEATURE)
2185
+        if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("reset_bed_level");
2186
+      #endif
2187
+      #if ABL_PLANAR
2188
+        planner.bed_level_matrix.set_to_identity();
2189
+      #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
2190
+        for (uint8_t x = 0; x < ABL_GRID_POINTS_X; x++)
2191
+          for (uint8_t y = 0; y < ABL_GRID_POINTS_Y; y++)
2192
+            bed_level_grid[x][y] = 1000.0;
2193
+      #endif
2155 2194
     #endif
2156 2195
   }
2157 2196
 
2158
-#endif // HAS_ABL
2197
+#endif // PLANNER_LEVELING
2159 2198
 
2160 2199
 #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
2161 2200
 

Carregando…
Cancelar
Salvar