Browse Source

Add code to handle changes to zprobe_zoffset

Scott Lahteine 8 years ago
parent
commit
60ac41a32c
4 changed files with 47 additions and 34 deletions
  1. 1
    0
      Marlin/Marlin.h
  2. 36
    29
      Marlin/Marlin_main.cpp
  3. 6
    2
      Marlin/configuration_store.cpp
  4. 4
    3
      Marlin/ultralcd.cpp

+ 1
- 0
Marlin/Marlin.h View File

@@ -317,6 +317,7 @@ float code_value_temp_diff();
317 317
 
318 318
 #if HAS_BED_PROBE
319 319
   extern float zprobe_zoffset;
320
+  void refresh_zprobe_zoffset(const bool no_babystep=false);
320 321
   #define DEPLOY_PROBE() set_probe_deployed(true)
321 322
   #define STOW_PROBE() set_probe_deployed(false)
322 323
 #endif

+ 36
- 29
Marlin/Marlin_main.cpp View File

@@ -7968,46 +7968,53 @@ inline void gcode_M503() {
7968 7968
 
7969 7969
 #if HAS_BED_PROBE
7970 7970
 
7971
-  inline void gcode_M851() {
7971
+  void refresh_zprobe_zoffset(const bool no_babystep/*=false*/) {
7972
+    static float last_zoffset = NAN;
7972 7973
 
7973
-    SERIAL_ECHO_START;
7974
-    SERIAL_ECHOPGM(MSG_ZPROBE_ZOFFSET);
7975
-    SERIAL_CHAR(' ');
7974
+    if (!isnan(last_zoffset)) {
7976 7975
 
7977
-    if (code_seen('Z')) {
7978
-      float value = code_value_axis_units(Z_AXIS);
7979
-      if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
7976
+      #if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(BABYSTEPPING)
7977
+        const float diff = zprobe_zoffset - last_zoffset;
7978
+      #endif
7980 7979
 
7981
-        #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
7982
-          // Correct bilinear grid for new probe offset
7983
-          const float diff = value - zprobe_zoffset;
7984
-          if (diff) {
7985
-            for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
7986
-              for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
7987
-                bed_level_grid[x][y] -= diff;
7988
-          }
7989
-          #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7990
-            bed_level_virt_interpolate();
7991
-          #endif
7980
+      #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
7981
+        // Correct bilinear grid for new probe offset
7982
+        if (diff) {
7983
+          for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
7984
+            for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
7985
+              bed_level_grid[x][y] -= diff;
7986
+        }
7987
+        #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7988
+          bed_level_virt_interpolate();
7992 7989
         #endif
7990
+      #endif
7993 7991
 
7994
-        #if ENABLED(BABYSTEPPING)
7995
-          if (planner.abl_enabled)
7996
-            thermalManager.babystep_axis(Z_AXIS, lround(-(value - zprobe_zoffset) * planner.axis_steps_per_mm[Z_AXIS]));
7997
-        #endif
7992
+      #if ENABLED(BABYSTEPPING)
7993
+        if (!no_babystep && planner.abl_enabled)
7994
+          thermalManager.babystep_axis(Z_AXIS, -lround(diff * planner.axis_steps_per_mm[Z_AXIS]));
7995
+      #else
7996
+        UNUSED(no_babystep);
7997
+      #endif
7998
+    }
7999
+
8000
+    last_zoffset = zprobe_zoffset;
8001
+  }
7998 8002
 
8003
+  inline void gcode_M851() {
8004
+    SERIAL_ECHO_START;
8005
+    SERIAL_ECHOPGM(MSG_ZPROBE_ZOFFSET " ");
8006
+    if (code_seen('Z')) {
8007
+      const float value = code_value_axis_units(Z_AXIS);
8008
+      if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
7999 8009
         zprobe_zoffset = value;
8010
+        refresh_zprobe_zoffset();
8000 8011
         SERIAL_ECHO(zprobe_zoffset);
8001 8012
       }
8002
-      else {
8003
-        SERIAL_ECHOPAIR(MSG_Z_MIN, Z_PROBE_OFFSET_RANGE_MIN);
8004
-        SERIAL_CHAR(' ');
8005
-        SERIAL_ECHOPAIR(MSG_Z_MAX, Z_PROBE_OFFSET_RANGE_MAX);
8006
-      }
8013
+      else
8014
+        SERIAL_ECHOPGM(MSG_Z_MIN " " STRINGIFY(Z_PROBE_OFFSET_RANGE_MIN) " " MSG_Z_MAX " " STRINGIFY(Z_PROBE_OFFSET_RANGE_MAX));
8007 8015
     }
8008
-    else {
8016
+    else
8009 8017
       SERIAL_ECHOPAIR(": ", zprobe_zoffset);
8010
-    }
8011 8018
 
8012 8019
     SERIAL_EOL;
8013 8020
   }

+ 6
- 2
Marlin/configuration_store.cpp View File

@@ -216,6 +216,10 @@ void MarlinSettings::postprocess() {
216 216
       //#endif
217 217
     );
218 218
   #endif
219
+
220
+  #if HAS_BED_PROBE
221
+    refresh_zprobe_zoffset();
222
+  #endif
219 223
 }
220 224
 
221 225
 #if ENABLED(EEPROM_SETTINGS)
@@ -344,7 +348,7 @@ void MarlinSettings::postprocess() {
344 348
     #endif // MESH_BED_LEVELING
345 349
 
346 350
     #if !HAS_BED_PROBE
347
-      float zprobe_zoffset = 0;
351
+      const float zprobe_zoffset = 0;
348 352
     #endif
349 353
     EEPROM_WRITE(zprobe_zoffset);
350 354
 
@@ -685,7 +689,7 @@ void MarlinSettings::postprocess() {
685 689
       #endif // MESH_BED_LEVELING
686 690
 
687 691
       #if !HAS_BED_PROBE
688
-        float zprobe_zoffset = 0;
692
+        float zprobe_zoffset;
689 693
       #endif
690 694
       EEPROM_READ(zprobe_zoffset);
691 695
 

+ 4
- 3
Marlin/ultralcd.cpp View File

@@ -863,11 +863,12 @@ void kill_screen(const char* lcd_msg) {
863 863
 
864 864
           const float new_zoffset = zprobe_zoffset + steps_to_mm[Z_AXIS] * babystep_increment;
865 865
           if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
866
-            
866
+
867 867
             if (planner.abl_enabled)
868 868
               thermalManager.babystep_axis(Z_AXIS, babystep_increment);
869
-      
869
+
870 870
             zprobe_zoffset = new_zoffset;
871
+            refresh_zprobe_zoffset(true);
871 872
             lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
872 873
           }
873 874
         }
@@ -2412,7 +2413,7 @@ void kill_screen(const char* lcd_msg) {
2412 2413
       #if ENABLED(BABYSTEPPING)
2413 2414
         MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
2414 2415
       #else
2415
-        MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
2416
+        MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, refresh_zprobe_zoffset);
2416 2417
       #endif
2417 2418
     #endif
2418 2419
     // Manual bed leveling, Bed Z:

Loading…
Cancel
Save