Преглед на файлове

Merge pull request #7965 from thinkyhead/bf1_ubl_remove_z_offset

[1.1.x] Unify Z fade factor
Scott Lahteine преди 7 години
родител
ревизия
1c3d06876e

+ 5
- 2
Marlin/Conditionals_post.h Целия файл

@@ -783,9 +783,12 @@
783 783
   #define UBL_DELTA  (ENABLED(AUTO_BED_LEVELING_UBL) && (ENABLED(DELTA) || ENABLED(UBL_GRANULAR_SEGMENTATION_FOR_CARTESIAN)))
784 784
   #define ABL_PLANAR (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT))
785 785
   #define ABL_GRID   (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR))
786
-  #define HAS_ABL    (ABL_PLANAR || ABL_GRID || ENABLED(AUTO_BED_LEVELING_UBL))
786
+  #define OLDSCHOOL_ABL         (ABL_PLANAR || ABL_GRID)
787
+  #define HAS_ABL               (OLDSCHOOL_ABL || ENABLED(AUTO_BED_LEVELING_UBL))
787 788
   #define HAS_LEVELING          (HAS_ABL || ENABLED(MESH_BED_LEVELING))
788
-  #define PLANNER_LEVELING      (ABL_PLANAR || ABL_GRID || ENABLED(MESH_BED_LEVELING) || UBL_DELTA)
789
+  #define HAS_AUTOLEVEL         (HAS_ABL && DISABLED(PROBE_MANUALLY))
790
+  #define HAS_MESH              (ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING))
791
+  #define PLANNER_LEVELING      (OLDSCHOOL_ABL || ENABLED(MESH_BED_LEVELING) || UBL_DELTA)
789 792
   #define HAS_PROBING_PROCEDURE (HAS_ABL || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
790 793
   #if HAS_PROBING_PROCEDURE
791 794
     #define PROBE_BED_WIDTH abs(RIGHT_PROBE_BED_POSITION - (LEFT_PROBE_BED_POSITION))

+ 0
- 1
Marlin/Marlin.h Целия файл

@@ -323,7 +323,6 @@ extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
323 323
 
324 324
 #if HAS_LEVELING
325 325
   bool leveling_is_valid();
326
-  bool leveling_is_active();
327 326
   void set_bed_leveling_enabled(const bool enable=true);
328 327
   void reset_bed_level();
329 328
 #endif

+ 76
- 104
Marlin/Marlin_main.cpp Целия файл

@@ -544,14 +544,14 @@ static uint8_t target_extruder;
544 544
 #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
545 545
   #if ENABLED(DELTA)
546 546
     #define ADJUST_DELTA(V) \
547
-      if (planner.abl_enabled) { \
547
+      if (planner.leveling_active) { \
548 548
         const float zadj = bilinear_z_offset(V); \
549 549
         delta[A_AXIS] += zadj; \
550 550
         delta[B_AXIS] += zadj; \
551 551
         delta[C_AXIS] += zadj; \
552 552
       }
553 553
   #else
554
-    #define ADJUST_DELTA(V) if (planner.abl_enabled) { delta[Z_AXIS] += bilinear_z_offset(V); }
554
+    #define ADJUST_DELTA(V) if (planner.leveling_active) { delta[Z_AXIS] += bilinear_z_offset(V); }
555 555
   #endif
556 556
 #elif IS_KINEMATIC
557 557
   #define ADJUST_DELTA(V) NOOP
@@ -2460,7 +2460,7 @@ static void clean_up_after_endstop_or_probe_move() {
2460 2460
   bool leveling_is_valid() {
2461 2461
     return
2462 2462
       #if ENABLED(MESH_BED_LEVELING)
2463
-        mbl.has_mesh()
2463
+        mbl.has_mesh
2464 2464
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
2465 2465
         !!bilinear_grid_spacing[X_AXIS]
2466 2466
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
@@ -2471,18 +2471,6 @@ static void clean_up_after_endstop_or_probe_move() {
2471 2471
     ;
2472 2472
   }
2473 2473
 
2474
-  bool leveling_is_active() {
2475
-    return
2476
-      #if ENABLED(MESH_BED_LEVELING)
2477
-        mbl.active()
2478
-      #elif ENABLED(AUTO_BED_LEVELING_UBL)
2479
-        ubl.state.active
2480
-      #else
2481
-        planner.abl_enabled
2482
-      #endif
2483
-    ;
2484
-  }
2485
-
2486 2474
   /**
2487 2475
    * Turn bed leveling on or off, fixing the current
2488 2476
    * position as-needed.
@@ -2498,7 +2486,7 @@ static void clean_up_after_endstop_or_probe_move() {
2498 2486
       constexpr bool can_change = true;
2499 2487
     #endif
2500 2488
 
2501
-    if (can_change && enable != leveling_is_active()) {
2489
+    if (can_change && enable != planner.leveling_active) {
2502 2490
 
2503 2491
       #if ENABLED(MESH_BED_LEVELING)
2504 2492
 
@@ -2506,23 +2494,23 @@ static void clean_up_after_endstop_or_probe_move() {
2506 2494
           planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
2507 2495
 
2508 2496
         const bool enabling = enable && leveling_is_valid();
2509
-        mbl.set_active(enabling);
2497
+        planner.leveling_active = enabling;
2510 2498
         if (enabling) planner.unapply_leveling(current_position);
2511 2499
 
2512 2500
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
2513 2501
         #if PLANNER_LEVELING
2514
-          if (ubl.state.active) {                       // leveling from on to off
2502
+          if (planner.leveling_active) {                       // leveling from on to off
2515 2503
             // change unleveled current_position to physical current_position without moving steppers.
2516 2504
             planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
2517
-            ubl.state.active = false;                   // disable only AFTER calling apply_leveling
2505
+            planner.leveling_active = false;                   // disable only AFTER calling apply_leveling
2518 2506
           }
2519 2507
           else {                                        // leveling from off to on
2520
-            ubl.state.active = true;                    // enable BEFORE calling unapply_leveling, otherwise ignored
2508
+            planner.leveling_active = true;                    // enable BEFORE calling unapply_leveling, otherwise ignored
2521 2509
             // change physical current_position to unleveled current_position without moving steppers.
2522 2510
             planner.unapply_leveling(current_position);
2523 2511
           }
2524 2512
         #else
2525
-          ubl.state.active = enable;                    // just flip the bit, current_position will be wrong until next move.
2513
+          planner.leveling_active = enable;                    // just flip the bit, current_position will be wrong until next move.
2526 2514
         #endif
2527 2515
 
2528 2516
       #else // ABL
@@ -2534,7 +2522,7 @@ static void clean_up_after_endstop_or_probe_move() {
2534 2522
         #endif
2535 2523
 
2536 2524
         // Enable or disable leveling compensation in the planner
2537
-        planner.abl_enabled = enable;
2525
+        planner.leveling_active = enable;
2538 2526
 
2539 2527
         if (!enable)
2540 2528
           // When disabling just get the current position from the steppers.
@@ -2559,23 +2547,18 @@ static void clean_up_after_endstop_or_probe_move() {
2559 2547
 
2560 2548
     void set_z_fade_height(const float zfh) {
2561 2549
 
2562
-      const bool level_active = leveling_is_active();
2550
+      const bool level_active = planner.leveling_active;
2563 2551
 
2564 2552
       #if ENABLED(AUTO_BED_LEVELING_UBL)
2553
+        if (level_active) set_bed_leveling_enabled(false);  // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
2554
+      #endif
2565 2555
 
2566
-        if (level_active)
2567
-          set_bed_leveling_enabled(false);  // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
2568
-        planner.z_fade_height = zfh;
2569
-        planner.inverse_z_fade_height = RECIPROCAL(zfh);
2570
-        if (level_active)
2571
-          set_bed_leveling_enabled(true);  // turn back on after changing fade height
2572
-
2573
-      #else
2574
-
2575
-        planner.z_fade_height = zfh;
2576
-        planner.inverse_z_fade_height = RECIPROCAL(zfh);
2556
+      planner.set_z_fade_height(zfh);
2577 2557
 
2578
-        if (level_active) {
2558
+      if (level_active) {
2559
+        #if ENABLED(AUTO_BED_LEVELING_UBL)
2560
+          set_bed_leveling_enabled(true);  // turn back on after changing fade height
2561
+        #else
2579 2562
           set_current_from_steppers_for_axis(
2580 2563
             #if ABL_PLANAR
2581 2564
               ALL_AXES
@@ -2583,8 +2566,8 @@ static void clean_up_after_endstop_or_probe_move() {
2583 2566
               Z_AXIS
2584 2567
             #endif
2585 2568
           );
2586
-        }
2587
-      #endif
2569
+        #endif
2570
+      }
2588 2571
     }
2589 2572
 
2590 2573
   #endif // LEVELING_FADE_HEIGHT
@@ -2597,7 +2580,7 @@ static void clean_up_after_endstop_or_probe_move() {
2597 2580
     #if ENABLED(MESH_BED_LEVELING)
2598 2581
       if (leveling_is_valid()) {
2599 2582
         mbl.reset();
2600
-        mbl.set_has_mesh(false);
2583
+        mbl.has_mesh = false;
2601 2584
       }
2602 2585
     #else
2603 2586
       #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -3771,7 +3754,7 @@ inline void gcode_G4() {
3771 3754
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
3772 3755
         SERIAL_ECHOPGM("UBL");
3773 3756
       #endif
3774
-      if (leveling_is_active()) {
3757
+      if (planner.leveling_active) {
3775 3758
         SERIAL_ECHOLNPGM(" (enabled)");
3776 3759
         #if ABL_PLANAR
3777 3760
           const float diff[XYZ] = {
@@ -3802,7 +3785,7 @@ inline void gcode_G4() {
3802 3785
     #elif ENABLED(MESH_BED_LEVELING)
3803 3786
 
3804 3787
       SERIAL_ECHOPGM("Mesh Bed Leveling");
3805
-      if (leveling_is_active()) {
3788
+      if (planner.leveling_active) {
3806 3789
         float lz = current_position[Z_AXIS];
3807 3790
         planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], lz);
3808 3791
         SERIAL_ECHOLNPGM(" (enabled)");
@@ -3971,7 +3954,7 @@ inline void gcode_G28(const bool always_home_all) {
3971 3954
   // Disable the leveling matrix before homing
3972 3955
   #if HAS_LEVELING
3973 3956
     #if ENABLED(AUTO_BED_LEVELING_UBL)
3974
-      const bool ubl_state_at_entry = leveling_is_active();
3957
+      const bool ubl_state_at_entry = planner.leveling_active;
3975 3958
     #endif
3976 3959
     set_bed_leveling_enabled(false);
3977 3960
   #endif
@@ -4211,7 +4194,7 @@ void home_all_axes() { gcode_G28(true); }
4211 4194
   }
4212 4195
 
4213 4196
   void mesh_probing_done() {
4214
-    mbl.set_has_mesh(true);
4197
+    mbl.has_mesh = true;
4215 4198
     home_all_axes();
4216 4199
     set_bed_leveling_enabled(true);
4217 4200
     #if ENABLED(MESH_G28_REST_ORIGIN)
@@ -4261,7 +4244,7 @@ void home_all_axes() { gcode_G28(true); }
4261 4244
     switch (state) {
4262 4245
       case MeshReport:
4263 4246
         if (leveling_is_valid()) {
4264
-          SERIAL_PROTOCOLLNPAIR("State: ", leveling_is_active() ? MSG_ON : MSG_OFF);
4247
+          SERIAL_PROTOCOLLNPAIR("State: ", planner.leveling_active ? MSG_ON : MSG_OFF);
4265 4248
           mbl_mesh_report();
4266 4249
         }
4267 4250
         else
@@ -4374,7 +4357,7 @@ void home_all_axes() { gcode_G28(true); }
4374 4357
     report_current_position();
4375 4358
   }
4376 4359
 
4377
-#elif HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
4360
+#elif OLDSCHOOL_ABL
4378 4361
 
4379 4362
   #if ABL_GRID
4380 4363
     #if ENABLED(PROBE_Y_FIRST)
@@ -4580,7 +4563,7 @@ void home_all_axes() { gcode_G28(true); }
4580 4563
         abl_probe_index = -1;
4581 4564
       #endif
4582 4565
 
4583
-      abl_should_enable = leveling_is_active();
4566
+      abl_should_enable = planner.leveling_active;
4584 4567
 
4585 4568
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
4586 4569
 
@@ -4720,7 +4703,7 @@ void home_all_axes() { gcode_G28(true); }
4720 4703
       stepper.synchronize();
4721 4704
 
4722 4705
       // Disable auto bed leveling during G29
4723
-      planner.abl_enabled = false;
4706
+      planner.leveling_active = false;
4724 4707
 
4725 4708
       if (!dryrun) {
4726 4709
         // Re-orient the current position without leveling
@@ -4734,7 +4717,7 @@ void home_all_axes() { gcode_G28(true); }
4734 4717
       #if HAS_BED_PROBE
4735 4718
         // Deploy the probe. Probe will raise if needed.
4736 4719
         if (DEPLOY_PROBE()) {
4737
-          planner.abl_enabled = abl_should_enable;
4720
+          planner.leveling_active = abl_should_enable;
4738 4721
           return;
4739 4722
         }
4740 4723
       #endif
@@ -4753,7 +4736,7 @@ void home_all_axes() { gcode_G28(true); }
4753 4736
         ) {
4754 4737
           if (dryrun) {
4755 4738
             // Before reset bed level, re-enable to correct the position
4756
-            planner.abl_enabled = abl_should_enable;
4739
+            planner.leveling_active = abl_should_enable;
4757 4740
           }
4758 4741
           // Reset grid to 0.0 or "not probed". (Also disables ABL)
4759 4742
           reset_bed_level();
@@ -4798,7 +4781,7 @@ void home_all_axes() { gcode_G28(true); }
4798 4781
         #if HAS_SOFTWARE_ENDSTOPS
4799 4782
           soft_endstops_enabled = enable_soft_endstops;
4800 4783
         #endif
4801
-        planner.abl_enabled = abl_should_enable;
4784
+        planner.leveling_active = abl_should_enable;
4802 4785
         g29_in_progress = false;
4803 4786
         #if ENABLED(LCD_BED_LEVELING)
4804 4787
           lcd_wait_for_move = false;
@@ -4999,7 +4982,7 @@ void home_all_axes() { gcode_G28(true); }
4999 4982
             measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
5000 4983
 
5001 4984
             if (isnan(measured_z)) {
5002
-              planner.abl_enabled = abl_should_enable;
4985
+              planner.leveling_active = abl_should_enable;
5003 4986
               break;
5004 4987
             }
5005 4988
 
@@ -5035,7 +5018,7 @@ void home_all_axes() { gcode_G28(true); }
5035 5018
           yProbe = LOGICAL_Y_POSITION(points[i].y);
5036 5019
           measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
5037 5020
           if (isnan(measured_z)) {
5038
-            planner.abl_enabled = abl_should_enable;
5021
+            planner.leveling_active = abl_should_enable;
5039 5022
             break;
5040 5023
           }
5041 5024
           points[i].z = measured_z;
@@ -5058,7 +5041,7 @@ void home_all_axes() { gcode_G28(true); }
5058 5041
 
5059 5042
       // Raise to _Z_CLEARANCE_DEPLOY_PROBE. Stow the probe.
5060 5043
       if (STOW_PROBE()) {
5061
-        planner.abl_enabled = abl_should_enable;
5044
+        planner.leveling_active = abl_should_enable;
5062 5045
         measured_z = NAN;
5063 5046
       }
5064 5047
     }
@@ -5226,9 +5209,9 @@ void home_all_axes() { gcode_G28(true); }
5226 5209
           float converted[XYZ];
5227 5210
           COPY(converted, current_position);
5228 5211
 
5229
-          planner.abl_enabled = true;
5212
+          planner.leveling_active = true;
5230 5213
           planner.unapply_leveling(converted); // use conversion machinery
5231
-          planner.abl_enabled = false;
5214
+          planner.leveling_active = false;
5232 5215
 
5233 5216
           // Use the last measured distance to the bed, if possible
5234 5217
           if ( NEAR(current_position[X_AXIS], xProbe - (X_PROBE_OFFSET_FROM_EXTRUDER))
@@ -5280,7 +5263,7 @@ void home_all_axes() { gcode_G28(true); }
5280 5263
       #endif
5281 5264
 
5282 5265
       // Auto Bed Leveling is complete! Enable if possible.
5283
-      planner.abl_enabled = dryrun ? abl_should_enable : true;
5266
+      planner.leveling_active = dryrun ? abl_should_enable : true;
5284 5267
     } // !isnan(measured_z)
5285 5268
 
5286 5269
     // Restore state after probing
@@ -5294,11 +5277,11 @@ void home_all_axes() { gcode_G28(true); }
5294 5277
 
5295 5278
     KEEPALIVE_STATE(IN_HANDLER);
5296 5279
 
5297
-    if (planner.abl_enabled)
5280
+    if (planner.leveling_active)
5298 5281
       SYNC_PLAN_POSITION_KINEMATIC();
5299 5282
   }
5300 5283
 
5301
-#endif // HAS_ABL && !AUTO_BED_LEVELING_UBL
5284
+#endif // OLDSCHOOL_ABL
5302 5285
 
5303 5286
 #if HAS_BED_PROBE
5304 5287
 
@@ -5886,7 +5869,7 @@ void home_all_axes() { gcode_G28(true); }
5886 5869
 
5887 5870
 #endif // G38_PROBE_TARGET
5888 5871
 
5889
-#if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING)
5872
+#if HAS_MESH
5890 5873
 
5891 5874
   /**
5892 5875
    * G42: Move X & Y axes to mesh coordinates (I & J)
@@ -5938,7 +5921,7 @@ void home_all_axes() { gcode_G28(true); }
5938 5921
     }
5939 5922
   }
5940 5923
 
5941
-#endif // AUTO_BED_LEVELING_UBL
5924
+#endif // HAS_MESH
5942 5925
 
5943 5926
 /**
5944 5927
  * G92: Set current position to given X Y Z E
@@ -7077,7 +7060,7 @@ inline void gcode_M42() {
7077 7060
     // Disable bed level correction in M48 because we want the raw data when we probe
7078 7061
 
7079 7062
     #if HAS_LEVELING
7080
-      const bool was_enabled = leveling_is_active();
7063
+      const bool was_enabled = planner.leveling_active;
7081 7064
       set_bed_leveling_enabled(false);
7082 7065
     #endif
7083 7066
 
@@ -9352,7 +9335,7 @@ void quickstop_stepper() {
9352 9335
       if (parser.seen('L')) {
9353 9336
 
9354 9337
         #if ENABLED(EEPROM_SETTINGS)
9355
-          const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.state.storage_slot;
9338
+          const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.storage_slot;
9356 9339
           const int16_t a = settings.calc_num_meshes();
9357 9340
 
9358 9341
           if (!a) {
@@ -9367,7 +9350,7 @@ void quickstop_stepper() {
9367 9350
           }
9368 9351
 
9369 9352
           settings.load_mesh(storage_slot);
9370
-          ubl.state.storage_slot = storage_slot;
9353
+          ubl.storage_slot = storage_slot;
9371 9354
 
9372 9355
         #else
9373 9356
 
@@ -9381,7 +9364,7 @@ void quickstop_stepper() {
9381 9364
       if (parser.seen('L') || parser.seen('V')) {
9382 9365
         ubl.display_map(0);  // Currently only supports one map type
9383 9366
         SERIAL_ECHOLNPAIR("UBL_MESH_VALID = ", UBL_MESH_VALID);
9384
-        SERIAL_ECHOLNPAIR("ubl.state.storage_slot = ", ubl.state.storage_slot);
9367
+        SERIAL_ECHOLNPAIR("ubl.storage_slot = ", ubl.storage_slot);
9385 9368
       }
9386 9369
 
9387 9370
     #endif // AUTO_BED_LEVELING_UBL
@@ -9413,7 +9396,7 @@ void quickstop_stepper() {
9413 9396
       if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units());
9414 9397
     #endif
9415 9398
 
9416
-    const bool new_status = leveling_is_active();
9399
+    const bool new_status = planner.leveling_active;
9417 9400
 
9418 9401
     if (to_enable && !new_status) {
9419 9402
       SERIAL_ERROR_START();
@@ -9644,7 +9627,7 @@ inline void gcode_M502() {
9644 9627
       #endif
9645 9628
 
9646 9629
       #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
9647
-        if (!no_babystep && leveling_is_active())
9630
+        if (!no_babystep && planner.leveling_active)
9648 9631
           thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS]));
9649 9632
       #else
9650 9633
         UNUSED(no_babystep);
@@ -10521,13 +10504,13 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
10521 10504
                                     + (tmp_extruder == 0 ? -(PARKING_EXTRUDER_GRAB_DISTANCE) : PARKING_EXTRUDER_GRAB_DISTANCE);
10522 10505
               /**
10523 10506
                *  Steps:
10524
-               *    1. raise Z-Axis to have enough clearance
10525
-               *    2. move to park poition of old extruder
10526
-               *    3. disengage magnetc field, wait for delay
10527
-               *    4. move near new extruder
10528
-               *    5. engage magnetic field for new extruder
10529
-               *    6. move to parking incl. offset of new extruder
10530
-               *    7. lower Z-Axis
10507
+               *    1. Raise Z-Axis to give enough clearance
10508
+               *    2. Move to park position of old extruder
10509
+               *    3. Disengage magnetic field, wait for delay
10510
+               *    4. Move near new extruder
10511
+               *    5. Engage magnetic field for new extruder
10512
+               *    6. Move to parking incl. offset of new extruder
10513
+               *    7. Lower Z-Axis
10531 10514
                */
10532 10515
 
10533 10516
               // STEP 1
@@ -10691,7 +10674,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
10691 10674
 
10692 10675
             #if ENABLED(MESH_BED_LEVELING)
10693 10676
 
10694
-              if (leveling_is_active()) {
10677
+              if (planner.leveling_active) {
10695 10678
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
10696 10679
                   if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
10697 10680
                 #endif
@@ -10809,7 +10792,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
10809 10792
  *   F[units/min] Set the movement feedrate
10810 10793
  *   S1           Don't move the tool in XY after change
10811 10794
  */
10812
-inline void gcode_T(uint8_t tmp_extruder) {
10795
+inline void gcode_T(const uint8_t tmp_extruder) {
10813 10796
 
10814 10797
   #if ENABLED(DEBUG_LEVELING_FEATURE)
10815 10798
     if (DEBUGGING(LEVELING)) {
@@ -11006,7 +10989,7 @@ void process_next_command() {
11006 10989
         gcode_G92();
11007 10990
         break;
11008 10991
 
11009
-      #if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING)
10992
+      #if HAS_MESH
11010 10993
         case 42:
11011 10994
           gcode_G42();
11012 10995
           break;
@@ -11491,7 +11474,7 @@ void process_next_command() {
11491 11474
           break;
11492 11475
       #endif
11493 11476
 
11494
-      #if ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_BILINEAR)
11477
+      #if HAS_MESH
11495 11478
         case 421: // M421: Set a Mesh Bed Leveling Z coordinate
11496 11479
           gcode_M421();
11497 11480
           break;
@@ -12389,39 +12372,28 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
12389 12372
    * Prepare a linear move in a Cartesian setup.
12390 12373
    * If Mesh Bed Leveling is enabled, perform a mesh move.
12391 12374
    *
12392
-   * Returns true if the caller didn't update current_position.
12375
+   * Returns true if current_position[] was set to destination[]
12393 12376
    */
12394 12377
   inline bool prepare_move_to_destination_cartesian() {
12395
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
12378
+    if (current_position[X_AXIS] != destination[X_AXIS] || current_position[Y_AXIS] != destination[Y_AXIS]) {
12396 12379
       const float fr_scaled = MMS_SCALED(feedrate_mm_s);
12397
-      if (ubl.state.active) { // direct use of ubl.state.active for speed
12398
-        ubl.line_to_destination_cartesian(fr_scaled, active_extruder);
12399
-        return true;
12400
-      }
12401
-      else
12402
-        line_to_destination(fr_scaled);
12403
-    #else
12404
-      // Do not use feedrate_percentage for E or Z only moves
12405
-      if (current_position[X_AXIS] == destination[X_AXIS] && current_position[Y_AXIS] == destination[Y_AXIS])
12406
-        line_to_destination();
12407
-      else {
12408
-        const float fr_scaled = MMS_SCALED(feedrate_mm_s);
12409
-        #if ENABLED(MESH_BED_LEVELING)
12410
-          if (mbl.active()) { // direct used of mbl.active() for speed
12380
+      #if HAS_MESH
12381
+        if (planner.leveling_active) {
12382
+          #if ENABLED(AUTO_BED_LEVELING_UBL)
12383
+            ubl.line_to_destination_cartesian(fr_scaled, active_extruder);
12384
+          #elif ENABLED(MESH_BED_LEVELING)
12411 12385
             mesh_line_to_destination(fr_scaled);
12412
-            return true;
12413
-          }
12414
-          else
12415
-        #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
12416
-          if (planner.abl_enabled) { // direct use of abl_enabled for speed
12386
+          #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
12417 12387
             bilinear_line_to_destination(fr_scaled);
12418
-            return true;
12419
-          }
12420
-          else
12421
-        #endif
12422
-            line_to_destination(fr_scaled);
12423
-      }
12424
-    #endif
12388
+          #endif
12389
+          return true;
12390
+        }
12391
+      #endif // HAS_MESH
12392
+      line_to_destination(fr_scaled);
12393
+    }
12394
+    else
12395
+      line_to_destination();
12396
+
12425 12397
     return false;
12426 12398
   }
12427 12399
 

+ 1
- 1
Marlin/SanityCheck.h Целия файл

@@ -651,7 +651,7 @@ static_assert(1 >= 0
651 651
   /**
652 652
    * Require some kind of probe for bed leveling and probe testing
653 653
    */
654
-  #if HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
654
+  #if OLDSCHOOL_ABL
655 655
     #error "Auto Bed Leveling requires one of these: PROBE_MANUALLY, FIX_MOUNTED_PROBE, BLTOUCH, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, or a Z Servo."
656 656
   #endif
657 657
 

+ 71
- 61
Marlin/configuration_store.cpp Целия файл

@@ -68,7 +68,7 @@
68 68
  *  219            z_fade_height                    (float)
69 69
  *
70 70
  * MESH_BED_LEVELING:                               43 bytes
71
- *  223  M420 S    from mbl.status                  (bool)
71
+ *  223  M420 S    planner.leveling_active          (bool)
72 72
  *  224            mbl.z_offset                     (float)
73 73
  *  228            GRID_MAX_POINTS_X                (uint8_t)
74 74
  *  229            GRID_MAX_POINTS_Y                (uint8_t)
@@ -88,8 +88,8 @@
88 88
  *  316            z_values[][]                     (float x9, up to float x256) +988
89 89
  *
90 90
  * AUTO_BED_LEVELING_UBL:                           6 bytes
91
- *  324  G29 A     ubl.state.active                 (bool)
92
- *  325  G29 S     ubl.state.storage_slot           (int8_t)
91
+ *  324  G29 A     planner.leveling_active          (bool)
92
+ *  325  G29 S     ubl.storage_slot                 (int8_t)
93 93
  *
94 94
  * DELTA:                                           48 bytes
95 95
  *  348  M666 XYZ  endstop_adj                      (float x3)
@@ -204,6 +204,10 @@ MarlinSettings settings;
204 204
   extern void refresh_bed_level();
205 205
 #endif
206 206
 
207
+#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
208
+  float new_z_fade_height;
209
+#endif
210
+
207 211
 /**
208 212
  * Post-process after Retrieve or Reset
209 213
  */
@@ -233,7 +237,7 @@ void MarlinSettings::postprocess() {
233 237
   #endif
234 238
 
235 239
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
236
-    set_z_fade_height(planner.z_fade_height);
240
+    set_z_fade_height(new_z_fade_height);
237 241
   #endif
238 242
 
239 243
   #if HAS_BED_PROBE
@@ -372,7 +376,7 @@ void MarlinSettings::postprocess() {
372 376
         sizeof(mbl.z_values) == GRID_MAX_POINTS * sizeof(mbl.z_values[0][0]),
373 377
         "MBL Z array is the wrong size."
374 378
       );
375
-      const bool leveling_is_on = TEST(mbl.status, MBL_STATUS_HAS_MESH_BIT);
379
+      const bool leveling_is_on = mbl.has_mesh;
376 380
       const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y;
377 381
       EEPROM_WRITE(leveling_is_on);
378 382
       EEPROM_WRITE(mbl.z_offset);
@@ -435,8 +439,8 @@ void MarlinSettings::postprocess() {
435 439
     #endif // AUTO_BED_LEVELING_BILINEAR
436 440
 
437 441
     #if ENABLED(AUTO_BED_LEVELING_UBL)
438
-      EEPROM_WRITE(ubl.state.active);
439
-      EEPROM_WRITE(ubl.state.storage_slot);
442
+      EEPROM_WRITE(planner.leveling_active);
443
+      EEPROM_WRITE(ubl.storage_slot);
440 444
     #else
441 445
       const bool ubl_active = false;
442 446
       const int8_t storage_slot = -1;
@@ -661,8 +665,8 @@ void MarlinSettings::postprocess() {
661 665
     }
662 666
 
663 667
     #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
664
-      if (ubl.state.storage_slot >= 0)
665
-        store_mesh(ubl.state.storage_slot);
668
+      if (ubl.storage_slot >= 0)
669
+        store_mesh(ubl.storage_slot);
666 670
     #endif
667 671
 
668 672
     return !eeprom_error;
@@ -751,7 +755,7 @@ void MarlinSettings::postprocess() {
751 755
       //
752 756
 
753 757
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
754
-        EEPROM_READ(planner.z_fade_height);
758
+        EEPROM_READ(new_z_fade_height);
755 759
       #else
756 760
         EEPROM_READ(dummy);
757 761
       #endif
@@ -768,7 +772,7 @@ void MarlinSettings::postprocess() {
768 772
       EEPROM_READ(mesh_num_y);
769 773
 
770 774
       #if ENABLED(MESH_BED_LEVELING)
771
-        mbl.status = leveling_is_on ? _BV(MBL_STATUS_HAS_MESH_BIT) : 0;
775
+        mbl.has_mesh = leveling_is_on;
772 776
         mbl.z_offset = dummy;
773 777
         if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
774 778
           // EEPROM data fits the current mesh
@@ -824,8 +828,8 @@ void MarlinSettings::postprocess() {
824 828
         }
825 829
 
826 830
       #if ENABLED(AUTO_BED_LEVELING_UBL)
827
-        EEPROM_READ(ubl.state.active);
828
-        EEPROM_READ(ubl.state.storage_slot);
831
+        EEPROM_READ(planner.leveling_active);
832
+        EEPROM_READ(ubl.storage_slot);
829 833
       #else
830 834
         uint8_t dummyui8;
831 835
         EEPROM_READ(dummyb);
@@ -1042,10 +1046,10 @@ void MarlinSettings::postprocess() {
1042 1046
           ubl.reset();
1043 1047
         }
1044 1048
 
1045
-        if (ubl.state.storage_slot >= 0) {
1046
-          load_mesh(ubl.state.storage_slot);
1049
+        if (ubl.storage_slot >= 0) {
1050
+          load_mesh(ubl.storage_slot);
1047 1051
           #if ENABLED(EEPROM_CHITCHAT)
1048
-            SERIAL_ECHOPAIR("Mesh ", ubl.state.storage_slot);
1052
+            SERIAL_ECHOPAIR("Mesh ", ubl.storage_slot);
1049 1053
             SERIAL_ECHOLNPGM(" loaded from storage.");
1050 1054
           #endif
1051 1055
         }
@@ -1186,7 +1190,7 @@ void MarlinSettings::reset() {
1186 1190
   planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
1187 1191
 
1188 1192
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1189
-    planner.z_fade_height = 0.0;
1193
+    new_z_fade_height = 10.0;
1190 1194
   #endif
1191 1195
 
1192 1196
   #if HAS_HOME_OFFSET
@@ -1563,65 +1567,71 @@ void MarlinSettings::reset() {
1563 1567
       }
1564 1568
     #endif
1565 1569
 
1566
-    #if ENABLED(MESH_BED_LEVELING)
1570
+    /**
1571
+     * Bed Leveling
1572
+     */
1573
+    #if HAS_LEVELING
1567 1574
 
1568
-      if (!forReplay) {
1575
+      #if ENABLED(MESH_BED_LEVELING)
1576
+
1577
+        if (!forReplay) {
1578
+          CONFIG_ECHO_START;
1579
+          SERIAL_ECHOLNPGM("Mesh Bed Leveling:");
1580
+        }
1569 1581
         CONFIG_ECHO_START;
1570
-        SERIAL_ECHOLNPGM("Mesh Bed Leveling:");
1571
-      }
1572
-      CONFIG_ECHO_START;
1573
-      SERIAL_ECHOPAIR("  M420 S", leveling_is_valid() ? 1 : 0);
1574
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1575
-        SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1576
-      #endif
1577
-      SERIAL_EOL();
1578
-      for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
1579
-        for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
1582
+
1583
+      #elif ENABLED(AUTO_BED_LEVELING_UBL)
1584
+
1585
+        if (!forReplay) {
1580 1586
           CONFIG_ECHO_START;
1581
-          SERIAL_ECHOPAIR("  G29 S3 X", (int)px + 1);
1582
-          SERIAL_ECHOPAIR(" Y", (int)py + 1);
1583
-          SERIAL_ECHOPGM(" Z");
1584
-          SERIAL_PROTOCOL_F(LINEAR_UNIT(mbl.z_values[px][py]), 5);
1585
-          SERIAL_EOL();
1587
+          ubl.echo_name();
1588
+          SERIAL_ECHOLNPGM(":");
1586 1589
         }
1587
-      }
1590
+        CONFIG_ECHO_START;
1588 1591
 
1589
-    #elif ENABLED(AUTO_BED_LEVELING_UBL)
1592
+      #elif HAS_ABL
1590 1593
 
1591
-      if (!forReplay) {
1594
+        if (!forReplay) {
1595
+          CONFIG_ECHO_START;
1596
+          SERIAL_ECHOLNPGM("Auto Bed Leveling:");
1597
+        }
1592 1598
         CONFIG_ECHO_START;
1593
-        ubl.echo_name();
1594
-        SERIAL_ECHOLNPGM(":");
1595
-      }
1599
+
1600
+      #endif
1601
+
1596 1602
       CONFIG_ECHO_START;
1597
-      SERIAL_ECHOPAIR("  M420 S", leveling_is_active() ? 1 : 0);
1603
+      SERIAL_ECHOPAIR("  M420 S", planner.leveling_active ? 1 : 0);
1598 1604
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1599
-        SERIAL_ECHOPAIR(" Z", planner.z_fade_height);
1605
+        SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1600 1606
       #endif
1601 1607
       SERIAL_EOL();
1602 1608
 
1603
-      if (!forReplay) {
1604
-        SERIAL_EOL();
1605
-        ubl.report_state();
1606
-        SERIAL_ECHOLNPAIR("\nActive Mesh Slot: ", ubl.state.storage_slot);
1607
-        SERIAL_ECHOPAIR("EEPROM can hold ", calc_num_meshes());
1608
-        SERIAL_ECHOLNPGM(" meshes.\n");
1609
-      }
1609
+      #if ENABLED(MESH_BED_LEVELING)
1610 1610
 
1611
-    #elif HAS_ABL
1611
+        for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
1612
+          for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
1613
+            CONFIG_ECHO_START;
1614
+            SERIAL_ECHOPAIR("  G29 S3 X", (int)px + 1);
1615
+            SERIAL_ECHOPAIR(" Y", (int)py + 1);
1616
+            SERIAL_ECHOPGM(" Z");
1617
+            SERIAL_PROTOCOL_F(LINEAR_UNIT(mbl.z_values[px][py]), 5);
1618
+            SERIAL_EOL();
1619
+          }
1620
+        }
1621
+
1622
+      #elif ENABLED(AUTO_BED_LEVELING_UBL)
1623
+
1624
+        if (!forReplay) {
1625
+          SERIAL_EOL();
1626
+          ubl.report_state();
1627
+          SERIAL_ECHOLNPAIR("\nActive Mesh Slot: ", ubl.storage_slot);
1628
+          SERIAL_ECHOPAIR("EEPROM can hold ", calc_num_meshes());
1629
+          SERIAL_ECHOLNPGM(" meshes.\n");
1630
+        }
1612 1631
 
1613
-      if (!forReplay) {
1614
-        CONFIG_ECHO_START;
1615
-        SERIAL_ECHOLNPGM("Auto Bed Leveling:");
1616
-      }
1617
-      CONFIG_ECHO_START;
1618
-      SERIAL_ECHOPAIR("  M420 S", leveling_is_active() ? 1 : 0);
1619
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1620
-        SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1621 1632
       #endif
1622
-      SERIAL_EOL();
1623 1633
 
1624
-    #endif
1634
+    #endif // HAS_LEVELING
1625 1635
 
1626 1636
     #if ENABLED(DELTA)
1627 1637
       if (!forReplay) {
@@ -1757,7 +1767,7 @@ void MarlinSettings::reset() {
1757 1767
     #endif // FWRETRACT
1758 1768
 
1759 1769
     /**
1760
-     * Auto Bed Leveling
1770
+     * Probe Offset
1761 1771
      */
1762 1772
     #if HAS_BED_PROBE
1763 1773
       if (!forReplay) {

+ 2
- 2
Marlin/mesh_bed_leveling.cpp Целия файл

@@ -26,7 +26,7 @@
26 26
 
27 27
   mesh_bed_leveling mbl;
28 28
 
29
-  uint8_t mesh_bed_leveling::status;
29
+  bool mesh_bed_leveling::has_mesh;
30 30
 
31 31
   float mesh_bed_leveling::z_offset,
32 32
         mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
@@ -42,7 +42,7 @@
42 42
   }
43 43
 
44 44
   void mesh_bed_leveling::reset() {
45
-    status = MBL_STATUS_NONE;
45
+    has_mesh = false;
46 46
     z_offset = 0;
47 47
     ZERO(z_values);
48 48
   }

+ 1
- 12
Marlin/mesh_bed_leveling.h Целия файл

@@ -33,18 +33,12 @@
33 33
     MeshReset
34 34
   };
35 35
 
36
-  enum MBLStatus {
37
-    MBL_STATUS_NONE = 0,
38
-    MBL_STATUS_HAS_MESH_BIT = 0,
39
-    MBL_STATUS_ACTIVE_BIT = 1
40
-  };
41
-
42 36
   #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_POINTS_X - 1))
43 37
   #define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y)) / (GRID_MAX_POINTS_Y - 1))
44 38
 
45 39
   class mesh_bed_leveling {
46 40
   public:
47
-    static uint8_t status; // Has Mesh and Is Active bits
41
+    static bool has_mesh;
48 42
     static float z_offset,
49 43
                  z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
50 44
                  index_to_xpos[GRID_MAX_POINTS_X],
@@ -56,11 +50,6 @@
56 50
 
57 51
     static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
58 52
 
59
-    static bool active()                       { return TEST(status, MBL_STATUS_ACTIVE_BIT); }
60
-    static void set_active(const bool onOff)   { onOff ? SBI(status, MBL_STATUS_ACTIVE_BIT) : CBI(status, MBL_STATUS_ACTIVE_BIT); }
61
-    static bool has_mesh()                     { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
62
-    static void set_has_mesh(const bool onOff) { onOff ? SBI(status, MBL_STATUS_HAS_MESH_BIT) : CBI(status, MBL_STATUS_HAS_MESH_BIT); }
63
-
64 53
     static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
65 54
       px = index % (GRID_MAX_POINTS_X);
66 55
       py = index / (GRID_MAX_POINTS_X);

+ 58
- 81
Marlin/planner.cpp Целия файл

@@ -104,17 +104,16 @@ float Planner::min_feedrate_mm_s,
104 104
       Planner::max_jerk[XYZE],       // The largest speed change requiring no acceleration
105 105
       Planner::min_travel_feedrate_mm_s;
106 106
 
107
-#if HAS_ABL
108
-  bool Planner::abl_enabled = false; // Flag that auto bed leveling is enabled
109
-#endif
110
-
111
-#if ABL_PLANAR
112
-  matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
113
-#endif
114
-
115
-#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
116
-  float Planner::z_fade_height, // Initialized by settings.load()
117
-        Planner::inverse_z_fade_height;
107
+#if HAS_LEVELING
108
+  bool Planner::leveling_active = false; // Flag that auto bed leveling is enabled
109
+  #if ABL_PLANAR
110
+    matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
111
+  #endif
112
+  #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
113
+    float Planner::z_fade_height,      // Initialized by settings.load()
114
+          Planner::inverse_z_fade_height,
115
+          Planner::last_raw_lz;
116
+  #endif
118 117
 #endif
119 118
 
120 119
 #if ENABLED(AUTOTEMP)
@@ -528,46 +527,31 @@ void Planner::check_axes_activity() {
528 527
    */
529 528
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
530 529
 
531
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
532
-      if (!ubl.state.active) return;
533
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
534
-        // if z_fade_height enabled (nonzero) and raw_z above it, no leveling required
535
-        if (planner.z_fade_height && planner.z_fade_height <= RAW_Z_POSITION(lz)) return;
536
-        lz += ubl.get_z_correction(lx, ly) * ubl.fade_scaling_factor_for_z(lz);
537
-      #else // no fade
538
-        lz += ubl.get_z_correction(lx, ly);
539
-      #endif // FADE
540
-    #endif // UBL
541
-
542
-    #if HAS_ABL
543
-      if (!abl_enabled) return;
544
-    #endif
530
+    if (!leveling_active) return;
545 531
 
546
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_UBL)
547
-      static float z_fade_factor = 1.0, last_raw_lz = -999.0;
548
-      if (z_fade_height) {
549
-        const float raw_lz = RAW_Z_POSITION(lz);
550
-        if (raw_lz >= z_fade_height) return;
551
-        if (last_raw_lz != raw_lz) {
552
-          last_raw_lz = raw_lz;
553
-          z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
554
-        }
555
-      }
556
-      else
557
-        z_fade_factor = 1.0;
532
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
533
+      const float fade_scaling_factor = fade_scaling_factor_for_z(lz);
534
+      if (!fade_scaling_factor) return;
535
+    #else
536
+      constexpr float fade_scaling_factor = 1.0;
558 537
     #endif
559 538
 
560
-    #if ENABLED(MESH_BED_LEVELING)
539
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
561 540
 
562
-      if (mbl.active())
563
-        lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
564
-          #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
565
-            , z_fade_factor
566
-          #endif
567
-          );
541
+      lz += ubl.get_z_correction(lx, ly) * fade_scaling_factor;
542
+
543
+    #elif ENABLED(MESH_BED_LEVELING)
544
+
545
+      lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
546
+        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
547
+          , fade_scaling_factor
548
+        #endif
549
+      );
568 550
 
569 551
     #elif ABL_PLANAR
570 552
 
553
+      UNUSED(fade_scaling_factor);
554
+
571 555
       float dx = RAW_X_POSITION(lx) - (X_TILT_FULCRUM),
572 556
             dy = RAW_Y_POSITION(ly) - (Y_TILT_FULCRUM),
573 557
             dz = RAW_Z_POSITION(lz);
@@ -581,63 +565,56 @@ void Planner::check_axes_activity() {
581 565
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
582 566
 
583 567
       float tmp[XYZ] = { lx, ly, 0 };
584
-      lz += bilinear_z_offset(tmp)
585
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
586
-          * z_fade_factor
587
-        #endif
588
-      ;
568
+      lz += bilinear_z_offset(tmp) * fade_scaling_factor;
589 569
 
590 570
     #endif
591 571
   }
592 572
 
593 573
   void Planner::unapply_leveling(float logical[XYZ]) {
594 574
 
595
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
575
+    #if HAS_LEVELING
576
+      if (!leveling_active) return;
577
+    #endif
596 578
 
597
-      if (ubl.state.active) {
579
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
580
+      if (!leveling_active_at_z(logical[Z_AXIS])) return;
581
+    #endif
598 582
 
599
-        const float z_physical = RAW_Z_POSITION(logical[Z_AXIS]),
600
-                    z_correct = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]),
601
-                    z_virtual = z_physical - z_correct;
602
-              float z_logical = LOGICAL_Z_POSITION(z_virtual);
583
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
603 584
 
604
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
585
+      const float z_physical = RAW_Z_POSITION(logical[Z_AXIS]),
586
+                  z_correct = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]),
587
+                  z_virtual = z_physical - z_correct;
588
+            float z_logical = LOGICAL_Z_POSITION(z_virtual);
605 589
 
606
-          // for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
607
-          // Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
608
-          //  then L=P-M(1-L/H)
609
-          //    so L=P-M+ML/H
610
-          //    so L-ML/H=P-M
611
-          //    so L(1-M/H)=P-M
612
-          //    so L=(P-M)/(1-M/H) for L<H
590
+      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
613 591
 
614
-          if (planner.z_fade_height) {
615
-            if (z_logical >= planner.z_fade_height)
616
-              z_logical = LOGICAL_Z_POSITION(z_physical);
617
-            else
618
-              z_logical /= 1.0 - z_correct * planner.inverse_z_fade_height;
619
-          }
592
+        // for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
593
+        // Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
594
+        //  then L=P-M(1-L/H)
595
+        //    so L=P-M+ML/H
596
+        //    so L-ML/H=P-M
597
+        //    so L(1-M/H)=P-M
598
+        //    so L=(P-M)/(1-M/H) for L<H
599
+
600
+        if (planner.z_fade_height) {
601
+          if (z_logical >= planner.z_fade_height)
602
+            z_logical = LOGICAL_Z_POSITION(z_physical);
603
+          else
604
+            z_logical /= 1.0 - z_correct * planner.inverse_z_fade_height;
605
+        }
620 606
 
621
-        #endif // ENABLE_LEVELING_FADE_HEIGHT
607
+      #endif // ENABLE_LEVELING_FADE_HEIGHT
622 608
 
623
-        logical[Z_AXIS] = z_logical;
624
-      }
609
+      logical[Z_AXIS] = z_logical;
625 610
 
626 611
       return; // don't fall thru to other ENABLE_LEVELING_FADE_HEIGHT logic
627 612
 
628 613
     #endif
629 614
 
630
-    #if HAS_ABL
631
-      if (!abl_enabled) return;
632
-    #endif
633
-
634
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
635
-      if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
636
-    #endif
637
-
638 615
     #if ENABLED(MESH_BED_LEVELING)
639 616
 
640
-      if (mbl.active()) {
617
+      if (leveling_active) {
641 618
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
642 619
           const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0);
643 620
           logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);

+ 55
- 6
Marlin/planner.h Целия файл

@@ -154,15 +154,14 @@ class Planner {
154 154
                  max_jerk[XYZE],       // The largest speed change requiring no acceleration
155 155
                  min_travel_feedrate_mm_s;
156 156
 
157
-    #if HAS_ABL
158
-      static bool abl_enabled;              // Flag that bed leveling is enabled
157
+    #if HAS_LEVELING
158
+      static bool leveling_active;          // Flag that bed leveling is enabled
159 159
       #if ABL_PLANAR
160 160
         static matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
161 161
       #endif
162
-    #endif
163
-
164
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
165
-      static float z_fade_height, inverse_z_fade_height;
162
+      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
163
+        static float z_fade_height, inverse_z_fade_height;
164
+      #endif
166 165
     #endif
167 166
 
168 167
     #if ENABLED(LIN_ADVANCE)
@@ -192,6 +191,10 @@ class Planner {
192 191
      */
193 192
     static uint32_t cutoff_long;
194 193
 
194
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
195
+      static float last_raw_lz;
196
+    #endif
197
+
195 198
     #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
196 199
       /**
197 200
        * Counters to manage disabling inactive extruders
@@ -243,6 +246,52 @@ class Planner {
243 246
 
244 247
     static bool is_full() { return (block_buffer_tail == BLOCK_MOD(block_buffer_head + 1)); }
245 248
 
249
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
250
+
251
+      /**
252
+       * Get the Z leveling fade factor based on the given Z height,
253
+       * re-calculating only when needed.
254
+       *
255
+       *  Returns 1.0 if planner.z_fade_height is 0.0.
256
+       *  Returns 0.0 if Z is past the specified 'Fade Height'.
257
+       */
258
+      inline static float fade_scaling_factor_for_z(const float &lz) {
259
+        static float z_fade_factor = 1.0;
260
+        if (z_fade_height) {
261
+          const float raw_lz = RAW_Z_POSITION(lz);
262
+          if (raw_lz >= z_fade_height) return 0.0;
263
+          if (last_raw_lz != raw_lz) {
264
+            last_raw_lz = raw_lz;
265
+            z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
266
+          }
267
+          return z_fade_factor;
268
+        }
269
+        return 1.0;
270
+      }
271
+
272
+      FORCE_INLINE static void force_fade_recalc() { last_raw_lz = -999.999; }
273
+
274
+      FORCE_INLINE static void set_z_fade_height(const float &zfh) {
275
+        z_fade_height = zfh > 0 ? zfh : 0;
276
+        inverse_z_fade_height = RECIPROCAL(z_fade_height);
277
+        force_fade_recalc();
278
+      }
279
+
280
+      FORCE_INLINE static bool leveling_active_at_z(const float &lz) {
281
+        return !z_fade_height || RAW_Z_POSITION(lz) < z_fade_height;
282
+      }
283
+
284
+    #else
285
+
286
+      FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) {
287
+        UNUSED(lz);
288
+        return 1.0;
289
+      }
290
+
291
+      FORCE_INLINE static bool leveling_active_at_z(const float &lz) { return true; }
292
+
293
+    #endif
294
+
246 295
     #if PLANNER_LEVELING
247 296
 
248 297
       #define ARG_X float lx

+ 2
- 1
Marlin/temperature.cpp Целия файл

@@ -2093,7 +2093,8 @@ void Temperature::isr() {
2093 2093
   } // temp_count >= OVERSAMPLENR
2094 2094
 
2095 2095
   // Go to the next state, up to SensorsReady
2096
-  adc_sensor_state = (ADCSensorState)((int(adc_sensor_state) + 1) % int(StartupDelay));
2096
+  adc_sensor_state = (ADCSensorState)(int(adc_sensor_state) + 1);
2097
+  if (adc_sensor_state > SensorsReady) adc_sensor_state = (ADCSensorState)0;
2097 2098
 
2098 2099
   #if ENABLED(BABYSTEPPING)
2099 2100
     LOOP_XYZ(axis) {

+ 6
- 9
Marlin/ubl.cpp Целия файл

@@ -28,8 +28,7 @@
28 28
   #include "ubl.h"
29 29
   #include "hex_print_routines.h"
30 30
   #include "temperature.h"
31
-
32
-  extern Planner planner;
31
+  #include "planner.h"
33 32
 
34 33
   /**
35 34
    * These support functions allow the use of large bit arrays of flags that take very
@@ -48,7 +47,7 @@
48 47
   void unified_bed_leveling::report_state() {
49 48
     echo_name();
50 49
     SERIAL_PROTOCOLPGM(" System v" UBL_VERSION " ");
51
-    if (!state.active) SERIAL_PROTOCOLPGM("in");
50
+    if (!planner.leveling_active) SERIAL_PROTOCOLPGM("in");
52 51
     SERIAL_PROTOCOLLNPGM("active.");
53 52
     safe_delay(50);
54 53
   }
@@ -62,10 +61,9 @@
62 61
     safe_delay(10);
63 62
   }
64 63
 
65
-  ubl_state unified_bed_leveling::state;
64
+  int8_t unified_bed_leveling::storage_slot;
66 65
 
67
-  float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
68
-        unified_bed_leveling::last_specified_z;
66
+  float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
69 67
 
70 68
   // 15 is the maximum nubmer of grid points supported + 1 safety margin for now,
71 69
   // until determinism prevails
@@ -84,12 +82,11 @@
84 82
 
85 83
   void unified_bed_leveling::reset() {
86 84
     set_bed_leveling_enabled(false);
87
-    state.storage_slot = -1;
85
+    storage_slot = -1;
88 86
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
89
-      planner.z_fade_height = 10.0;
87
+      planner.set_z_fade_height(10.0);
90 88
     #endif
91 89
     ZERO(z_values);
92
-    last_specified_z = -999.9;
93 90
   }
94 91
 
95 92
   void unified_bed_leveling::invalidate() {

+ 1
- 33
Marlin/ubl.h Целия файл

@@ -76,16 +76,9 @@
76 76
   #define MESH_X_DIST (float(UBL_MESH_MAX_X - (UBL_MESH_MIN_X)) / float(GRID_MAX_POINTS_X - 1))
77 77
   #define MESH_Y_DIST (float(UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)) / float(GRID_MAX_POINTS_Y - 1))
78 78
 
79
-  typedef struct {
80
-    bool active = false;
81
-    int8_t storage_slot = -1;
82
-  } ubl_state;
83
-
84 79
   class unified_bed_leveling {
85 80
     private:
86 81
 
87
-      static float last_specified_z;
88
-
89 82
       static int    g29_verbose_level,
90 83
                     g29_phase_value,
91 84
                     g29_repetition_cnt,
@@ -167,7 +160,7 @@
167 160
         static void G26();
168 161
       #endif
169 162
 
170
-      static ubl_state state;
163
+      static int8_t storage_slot;
171 164
 
172 165
       static float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
173 166
 
@@ -361,31 +354,6 @@
361 354
         return z0;
362 355
       }
363 356
 
364
-      /**
365
-       * This function sets the Z leveling fade factor based on the given Z height,
366
-       * only re-calculating when necessary.
367
-       *
368
-       *  Returns 1.0 if planner.z_fade_height is 0.0.
369
-       *  Returns 0.0 if Z is past the specified 'Fade Height'.
370
-       */
371
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
372
-        static inline float fade_scaling_factor_for_z(const float &lz) {
373
-          if (planner.z_fade_height == 0.0) return 1.0;
374
-          static float fade_scaling_factor = 1.0;
375
-          const float rz = RAW_Z_POSITION(lz);
376
-          if (last_specified_z != rz) {
377
-            last_specified_z = rz;
378
-            fade_scaling_factor =
379
-              rz < planner.z_fade_height
380
-                ? 1.0 - (rz * planner.inverse_z_fade_height)
381
-                : 0.0;
382
-          }
383
-          return fade_scaling_factor;
384
-        }
385
-      #else
386
-        FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) { return 1.0; }
387
-      #endif
388
-
389 357
       FORCE_INLINE static float mesh_index_to_xpos(const uint8_t i) {
390 358
         return i < GRID_MAX_POINTS_X ? pgm_read_float(&_mesh_index_to_xpos[i]) : UBL_MESH_MIN_X + i * (MESH_X_DIST);
391 359
       }

+ 9
- 9
Marlin/ubl_G29.cpp Целия файл

@@ -423,8 +423,8 @@
423 423
     #endif // HAS_BED_PROBE
424 424
 
425 425
     if (parser.seen('P')) {
426
-      if (WITHIN(g29_phase_value, 0, 1) && state.storage_slot == -1) {
427
-        state.storage_slot = 0;
426
+      if (WITHIN(g29_phase_value, 0, 1) && storage_slot == -1) {
427
+        storage_slot = 0;
428 428
         SERIAL_PROTOCOLLNPGM("Default storage slot 0 selected.");
429 429
       }
430 430
 
@@ -603,7 +603,7 @@
603 603
     //
604 604
 
605 605
     if (parser.seen('L')) {     // Load Current Mesh Data
606
-      g29_storage_slot = parser.has_value() ? parser.value_int() : state.storage_slot;
606
+      g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot;
607 607
 
608 608
       int16_t a = settings.calc_num_meshes();
609 609
 
@@ -619,7 +619,7 @@
619 619
       }
620 620
 
621 621
       settings.load_mesh(g29_storage_slot);
622
-      state.storage_slot = g29_storage_slot;
622
+      storage_slot = g29_storage_slot;
623 623
 
624 624
       SERIAL_PROTOCOLLNPGM("Done.");
625 625
     }
@@ -629,7 +629,7 @@
629 629
     //
630 630
 
631 631
     if (parser.seen('S')) {     // Store (or Save) Current Mesh Data
632
-      g29_storage_slot = parser.has_value() ? parser.value_int() : state.storage_slot;
632
+      g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot;
633 633
 
634 634
       if (g29_storage_slot == -1) {                     // Special case, we are going to 'Export' the mesh to the
635 635
         SERIAL_ECHOLNPGM("G29 I 999");              // host in a form it can be reconstructed on a different machine
@@ -661,7 +661,7 @@
661 661
       }
662 662
 
663 663
       settings.store_mesh(g29_storage_slot);
664
-      state.storage_slot = g29_storage_slot;
664
+      storage_slot = g29_storage_slot;
665 665
 
666 666
       SERIAL_PROTOCOLLNPGM("Done.");
667 667
     }
@@ -1165,7 +1165,7 @@
1165 1165
 
1166 1166
       return;
1167 1167
     }
1168
-    ubl_state_at_invocation = state.active;
1168
+    ubl_state_at_invocation = planner.leveling_active;
1169 1169
     set_bed_leveling_enabled(false);
1170 1170
   }
1171 1171
 
@@ -1190,10 +1190,10 @@
1190 1190
   void unified_bed_leveling::g29_what_command() {
1191 1191
     report_state();
1192 1192
 
1193
-    if (state.storage_slot == -1)
1193
+    if (storage_slot == -1)
1194 1194
       SERIAL_PROTOCOLPGM("No Mesh Loaded.");
1195 1195
     else {
1196
-      SERIAL_PROTOCOLPAIR("Mesh ", state.storage_slot);
1196
+      SERIAL_PROTOCOLPAIR("Mesh ", storage_slot);
1197 1197
       SERIAL_PROTOCOLPGM(" Loaded.");
1198 1198
     }
1199 1199
     SERIAL_EOL();

+ 15
- 21
Marlin/ubl_motion.cpp Целия файл

@@ -186,7 +186,7 @@
186 186
       // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
187 187
 
188 188
       const float yratio = (RAW_Y_POSITION(end[Y_AXIS]) - mesh_index_to_ypos(cell_dest_yi)) * (1.0 / (MESH_Y_DIST));
189
-      float z0 = cell_dest_yi < GRID_MAX_POINTS_Y - 1 ? (z1 + (z2 - z1) * yratio) * fade_scaling_factor_for_z(end[Z_AXIS]) : 0.0;
189
+      float z0 = cell_dest_yi < GRID_MAX_POINTS_Y - 1 ? (z1 + (z2 - z1) * yratio) * planner.fade_scaling_factor_for_z(end[Z_AXIS]) : 0.0;
190 190
 
191 191
       /**
192 192
        * If part of the Mesh is undefined, it will show up as NAN
@@ -270,9 +270,8 @@
270 270
          */
271 271
         const float x = inf_m_flag ? start[X_AXIS] : (next_mesh_line_y - c) / m;
272 272
 
273
-        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi);
274
-
275
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
273
+        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi)
274
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
276 275
 
277 276
         /**
278 277
          * If part of the Mesh is undefined, it will show up as NAN
@@ -335,9 +334,8 @@
335 334
         const float next_mesh_line_x = LOGICAL_X_POSITION(mesh_index_to_xpos(current_xi)),
336 335
                     y = m * next_mesh_line_x + c;   // Calculate Y at the next X mesh line
337 336
 
338
-        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi);
339
-
340
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
337
+        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi)
338
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
341 339
 
342 340
         /**
343 341
          * If part of the Mesh is undefined, it will show up as NAN
@@ -408,9 +406,8 @@
408 406
 
409 407
       if (left_flag == (x > next_mesh_line_x)) { // Check if we hit the Y line first
410 408
         // Yes!  Crossing a Y Mesh Line next
411
-        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi - left_flag, current_yi + dyi);
412
-
413
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
409
+        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi - left_flag, current_yi + dyi)
410
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
414 411
 
415 412
         /**
416 413
          * If part of the Mesh is undefined, it will show up as NAN
@@ -436,9 +433,8 @@
436 433
       }
437 434
       else {
438 435
         // Yes!  Crossing a X Mesh Line next
439
-        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi + dxi, current_yi - down_flag);
440
-
441
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
436
+        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi + dxi, current_yi - down_flag)
437
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
442 438
 
443 439
         /**
444 440
          * If part of the Mesh is undefined, it will show up as NAN
@@ -603,7 +599,7 @@
603 599
 
604 600
       // Only compute leveling per segment if ubl active and target below z_fade_height.
605 601
 
606
-      if (!state.active || above_fade_height) {   // no mesh leveling
602
+      if (!planner.leveling_active || !planner.leveling_active_at_z(ltarget[Z_AXIS])) {   // no mesh leveling
607 603
 
608 604
         do {
609 605
 
@@ -629,7 +625,9 @@
629 625
       // Otherwise perform per-segment leveling
630 626
 
631 627
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
632
-        const float fade_scaling_factor = fade_scaling_factor_for_z(ltarget[Z_AXIS]);
628
+        const float fade_scaling_factor = planner.fade_scaling_factor_for_z(ltarget[Z_AXIS]);
629
+      #else
630
+        constexpr float fade_scaling_factor = 1.0;
633 631
       #endif
634 632
 
635 633
       // increment to first segment destination
@@ -661,7 +659,7 @@
661 659
               z_x0y1 = z_values[cell_xi  ][cell_yi+1],  // z at lower right corner
662 660
               z_x1y1 = z_values[cell_xi+1][cell_yi+1];  // z at upper right corner
663 661
 
664
-        if (isnan(z_x0y0)) z_x0y0 = 0;              // ideally activating state.active (G29 A)
662
+        if (isnan(z_x0y0)) z_x0y0 = 0;              // ideally activating planner.leveling_active (G29 A)
665 663
         if (isnan(z_x1y0)) z_x1y0 = 0;              //   should refuse if any invalid mesh points
666 664
         if (isnan(z_x0y1)) z_x0y1 = 0;              //   in order to avoid isnan tests per cell,
667 665
         if (isnan(z_x1y1)) z_x1y1 = 0;              //   thus guessing zero for undefined points
@@ -690,11 +688,7 @@
690 688
 
691 689
         for(;;) {  // for all segments within this mesh cell
692 690
 
693
-          float z_cxcy = z_cxy0 + z_cxym * cy;      // interpolated mesh z height along cx at cy
694
-
695
-          #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
696
-            z_cxcy *= fade_scaling_factor;          // apply fade factor to interpolated mesh height
697
-          #endif
691
+          float z_cxcy = (z_cxy0 + z_cxym * cy) * fade_scaling_factor; // interpolated mesh z height along cx at cy, scaled for fade
698 692
 
699 693
           if (--segments == 0) {                    // if this is last segment, use ltarget for exact
700 694
             seg_rx = RAW_X_POSITION(ltarget[X_AXIS]);

+ 31
- 17
Marlin/ultralcd.cpp Целия файл

@@ -50,6 +50,11 @@
50 50
 #if ENABLED(AUTO_BED_LEVELING_UBL)
51 51
   #include "ubl.h"
52 52
   bool ubl_lcd_map_control = false;
53
+#elif HAS_ABL
54
+  #include "planner.h"
55
+#elif ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
56
+  #include "mesh_bed_leveling.h"
57
+  extern void mesh_probing_done();
53 58
 #endif
54 59
 
55 60
 // Initialized by settings.load()
@@ -194,11 +199,6 @@ uint16_t max_display_update_time = 0;
194 199
     void lcd_delta_calibrate_menu();
195 200
   #endif
196 201
 
197
-  #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
198
-    #include "mesh_bed_leveling.h"
199
-    extern void mesh_probing_done();
200
-  #endif
201
-
202 202
   ////////////////////////////////////////////
203 203
   //////////// Menu System Actions ///////////
204 204
   ////////////////////////////////////////////
@@ -1089,7 +1089,7 @@ void kill_screen(const char* lcd_msg) {
1089 1089
           const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
1090 1090
           if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
1091 1091
 
1092
-            if (planner.abl_enabled)
1092
+            if (planner.leveling_active)
1093 1093
               thermalManager.babystep_axis(Z_AXIS, babystep_increment);
1094 1094
 
1095 1095
             zprobe_zoffset = new_zoffset;
@@ -1791,7 +1791,7 @@ void kill_screen(const char* lcd_msg) {
1791 1791
 
1792 1792
             _lcd_after_probing();
1793 1793
 
1794
-            mbl.set_has_mesh(true);
1794
+            mbl.has_mesh = true;
1795 1795
             mesh_probing_done();
1796 1796
 
1797 1797
           #endif
@@ -1909,11 +1909,12 @@ void kill_screen(const char* lcd_msg) {
1909 1909
       enqueue_and_echo_commands_P(PSTR("G28"));
1910 1910
     }
1911 1911
 
1912
-    static bool _level_state;
1913
-    void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(_level_state); }
1912
+    static bool new_level_state;
1913
+    void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(new_level_state); }
1914 1914
 
1915 1915
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1916
-      void _lcd_set_z_fade_height() { set_z_fade_height(planner.z_fade_height); }
1916
+      static float new_z_fade_height;
1917
+      void _lcd_set_z_fade_height() { set_z_fade_height(new_z_fade_height); }
1917 1918
     #endif
1918 1919
 
1919 1920
     /**
@@ -1936,14 +1937,11 @@ void kill_screen(const char* lcd_msg) {
1936 1937
 
1937 1938
       if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
1938 1939
         MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
1939
-      else if (leveling_is_valid()) {
1940
-        _level_state = leveling_is_active();
1941
-        MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &_level_state, _lcd_toggle_bed_leveling);
1942
-      }
1940
+      else if (leveling_is_valid())
1941
+        MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &new_level_state, _lcd_toggle_bed_leveling);
1943 1942
 
1944 1943
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1945
-        set_z_fade_height(planner.z_fade_height);
1946
-        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &planner.z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
1944
+        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
1947 1945
       #endif
1948 1946
 
1949 1947
       //
@@ -1974,6 +1972,16 @@ void kill_screen(const char* lcd_msg) {
1974 1972
       END_MENU();
1975 1973
     }
1976 1974
 
1975
+    void _lcd_goto_bed_leveling() {
1976
+      currentScreen = lcd_bed_leveling;
1977
+      #if ENABLED(LCD_BED_LEVELING)
1978
+        new_level_state = planner.leveling_active;
1979
+      #endif
1980
+      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1981
+        new_z_fade_height = planner.z_fade_height;
1982
+      #endif
1983
+    }
1984
+
1977 1985
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
1978 1986
 
1979 1987
     void _lcd_ubl_level_bed();
@@ -2542,7 +2550,13 @@ void kill_screen(const char* lcd_msg) {
2542 2550
       #if ENABLED(PROBE_MANUALLY)
2543 2551
         if (!g29_in_progress)
2544 2552
       #endif
2545
-      MENU_ITEM(submenu, MSG_BED_LEVELING, lcd_bed_leveling);
2553
+          MENU_ITEM(submenu, MSG_BED_LEVELING,
2554
+            #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
2555
+              _lcd_goto_bed_leveling
2556
+            #else
2557
+              lcd_bed_leveling
2558
+            #endif
2559
+          );
2546 2560
     #else
2547 2561
       #if PLANNER_LEVELING
2548 2562
         MENU_ITEM(gcode, MSG_BED_LEVELING, PSTR("G28\nG29"));

+ 3
- 3
Marlin/ultralcd_impl_HD44780.h Целия файл

@@ -792,7 +792,7 @@ static void lcd_implementation_status_screen() {
792 792
     lcd.print(ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
793 793
 
794 794
     #if HAS_LEVELING
795
-      lcd.write(leveling_is_active() || blink ? '_' : ' ');
795
+      lcd.write(planner.leveling_active || blink ? '_' : ' ');
796 796
     #endif
797 797
 
798 798
   #endif // LCD_HEIGHT > 2
@@ -1145,9 +1145,9 @@ static void lcd_implementation_status_screen() {
1145 1145
       return ret_val;
1146 1146
     }
1147 1147
 
1148
-    coordinate pixel_location(uint8_t x, uint8_t y) { return pixel_location((int16_t)x, (int16_t)y); }
1148
+    inline coordinate pixel_location(const uint8_t x, const uint8_t y) { return pixel_location((int16_t)x, (int16_t)y); }
1149 1149
 
1150
-    void lcd_implementation_ubl_plot(uint8_t x, uint8_t inverted_y) {
1150
+    void lcd_implementation_ubl_plot(const uint8_t x, const uint8_t inverted_y) {
1151 1151
 
1152 1152
       #if LCD_WIDTH >= 20
1153 1153
         #define _LCD_W_POS 12

Loading…
Отказ
Запис