Browse Source

Make leveling_is_active a macro

Scott Lahteine 7 years ago
parent
commit
9a930ebec2

+ 2
- 2
Marlin/src/core/utility.cpp View File

@@ -333,7 +333,7 @@ void safe_delay(millis_t ms) {
333 333
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
334 334
         SERIAL_ECHOPGM("UBL");
335 335
       #endif
336
-      if (leveling_is_active()) {
336
+      if (LEVELING_IS_ACTIVE()) {
337 337
         SERIAL_ECHOLNPGM(" (enabled)");
338 338
         #if ABL_PLANAR
339 339
           const float diff[XYZ] = {
@@ -364,7 +364,7 @@ void safe_delay(millis_t ms) {
364 364
     #elif ENABLED(MESH_BED_LEVELING)
365 365
 
366 366
       SERIAL_ECHOPGM("Mesh Bed Leveling");
367
-      if (leveling_is_active()) {
367
+      if (LEVELING_IS_ACTIVE()) {
368 368
         float lz = current_position[Z_AXIS];
369 369
         planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], lz);
370 370
         SERIAL_ECHOLNPGM(" (enabled)");

+ 2
- 14
Marlin/src/feature/bedlevel/bedlevel.cpp View File

@@ -55,18 +55,6 @@ bool leveling_is_valid() {
55 55
   ;
56 56
 }
57 57
 
58
-bool leveling_is_active() {
59
-  return
60
-    #if ENABLED(MESH_BED_LEVELING)
61
-      mbl.active()
62
-    #elif ENABLED(AUTO_BED_LEVELING_UBL)
63
-      ubl.state.active
64
-    #else // OLDSCHOOL_ABL
65
-      planner.abl_enabled
66
-    #endif
67
-  ;
68
-}
69
-
70 58
 /**
71 59
  * Turn bed leveling on or off, fixing the current
72 60
  * position as-needed.
@@ -82,7 +70,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
82 70
     constexpr bool can_change = true;
83 71
   #endif
84 72
 
85
-  if (can_change && enable != leveling_is_active()) {
73
+  if (can_change && enable != LEVELING_IS_ACTIVE()) {
86 74
 
87 75
     #if ENABLED(MESH_BED_LEVELING)
88 76
 
@@ -143,7 +131,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
143 131
 
144 132
   void set_z_fade_height(const float zfh) {
145 133
 
146
-    const bool level_active = leveling_is_active();
134
+    const bool level_active = LEVELING_IS_ACTIVE();
147 135
 
148 136
     #if ENABLED(AUTO_BED_LEVELING_UBL)
149 137
 

+ 10
- 1
Marlin/src/feature/bedlevel/bedlevel.h View File

@@ -40,10 +40,19 @@
40 40
 #endif
41 41
 
42 42
 bool leveling_is_valid();
43
-bool leveling_is_active();
44 43
 void set_bed_leveling_enabled(const bool enable=true);
45 44
 void reset_bed_level();
46 45
 
46
+#if ENABLED(MESH_BED_LEVELING)
47
+  #define LEVELING_IS_ACTIVE() (mbl.active())
48
+#elif ENABLED(AUTO_BED_LEVELING_UBL)
49
+  #define LEVELING_IS_ACTIVE() (ubl.state.active)
50
+#elif HAS_ABL
51
+  #define LEVELING_IS_ACTIVE() (planner.abl_enabled)
52
+#else
53
+  #define LEVELING_IS_ACTIVE() (false)
54
+#endif
55
+
47 56
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
48 57
   void set_z_fade_height(const float zfh);
49 58
 #endif

+ 1
- 1
Marlin/src/gcode/bedlevel/M420.cpp View File

@@ -112,7 +112,7 @@ void GcodeSuite::M420() {
112 112
     if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units());
113 113
   #endif
114 114
 
115
-  const bool new_status = leveling_is_active();
115
+  const bool new_status = LEVELING_IS_ACTIVE();
116 116
 
117 117
   if (to_enable && !new_status) {
118 118
     SERIAL_ERROR_START();

+ 2
- 2
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

@@ -247,7 +247,7 @@ void GcodeSuite::G29() {
247 247
       abl_probe_index = -1;
248 248
     #endif
249 249
 
250
-    abl_should_enable = leveling_is_active();
250
+    abl_should_enable = LEVELING_IS_ACTIVE();
251 251
 
252 252
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
253 253
 
@@ -964,7 +964,7 @@ void GcodeSuite::G29() {
964 964
 
965 965
   KEEPALIVE_STATE(IN_HANDLER);
966 966
 
967
-  if (planner.abl_enabled)
967
+  if (LEVELING_IS_ACTIVE())
968 968
     SYNC_PLAN_POSITION_KINEMATIC();
969 969
 }
970 970
 

+ 1
- 1
Marlin/src/gcode/bedlevel/mbl/G29.cpp View File

@@ -92,7 +92,7 @@ void GcodeSuite::G29() {
92 92
   switch (state) {
93 93
     case MeshReport:
94 94
       if (leveling_is_valid()) {
95
-        SERIAL_PROTOCOLLNPAIR("State: ", leveling_is_active() ? MSG_ON : MSG_OFF);
95
+        SERIAL_PROTOCOLLNPAIR("State: ", LEVELING_IS_ACTIVE() ? MSG_ON : MSG_OFF);
96 96
         mbl_mesh_report();
97 97
       }
98 98
       else

+ 1
- 1
Marlin/src/gcode/calibrate/G28.cpp View File

@@ -157,7 +157,7 @@ void GcodeSuite::G28(const bool always_home_all) {
157 157
   // Disable the leveling matrix before homing
158 158
   #if HAS_LEVELING
159 159
     #if ENABLED(AUTO_BED_LEVELING_UBL)
160
-      const bool ubl_state_at_entry = leveling_is_active();
160
+      const bool ubl_state_at_entry = LEVELING_IS_ACTIVE();
161 161
     #endif
162 162
     set_bed_leveling_enabled(false);
163 163
   #endif

+ 5
- 1
Marlin/src/gcode/calibrate/M48.cpp View File

@@ -32,6 +32,10 @@
32 32
   #include "../../feature/bedlevel/bedlevel.h"
33 33
 #endif
34 34
 
35
+#if HAS_LEVELING
36
+  #include "../../module/planner.h"
37
+#endif
38
+
35 39
 /**
36 40
  * M48: Z probe repeatability measurement function.
37 41
  *
@@ -115,7 +119,7 @@ void GcodeSuite::M48() {
115 119
   // Disable bed level correction in M48 because we want the raw data when we probe
116 120
 
117 121
   #if HAS_LEVELING
118
-    const bool was_enabled = leveling_is_active();
122
+    const bool was_enabled = LEVELING_IS_ACTIVE();
119 123
     set_bed_leveling_enabled(false);
120 124
   #endif
121 125
 

+ 2
- 2
Marlin/src/lcd/ultralcd.cpp View File

@@ -1086,7 +1086,7 @@ void kill_screen(const char* lcd_msg) {
1086 1086
           const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
1087 1087
           if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
1088 1088
 
1089
-            if (leveling_is_active())
1089
+            if (LEVELING_IS_ACTIVE())
1090 1090
               thermalManager.babystep_axis(Z_AXIS, babystep_increment);
1091 1091
 
1092 1092
             zprobe_zoffset = new_zoffset;
@@ -1934,7 +1934,7 @@ void kill_screen(const char* lcd_msg) {
1934 1934
       if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
1935 1935
         MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
1936 1936
       else if (leveling_is_valid()) {
1937
-        _level_state = leveling_is_active();
1937
+        _level_state = LEVELING_IS_ACTIVE();
1938 1938
         MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &_level_state, _lcd_toggle_bed_leveling);
1939 1939
       }
1940 1940
 

+ 1
- 1
Marlin/src/lcd/ultralcd_impl_HD44780.h View File

@@ -795,7 +795,7 @@ static void lcd_implementation_status_screen() {
795 795
     lcd.print(ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
796 796
 
797 797
     #if HAS_LEVELING
798
-      lcd.write(leveling_is_active() || blink ? '_' : ' ');
798
+      lcd.write(LEVELING_IS_ACTIVE() || blink ? '_' : ' ');
799 799
     #endif
800 800
 
801 801
   #endif // LCD_HEIGHT > 2

+ 2
- 2
Marlin/src/module/configuration_store.cpp View File

@@ -1556,7 +1556,7 @@ void MarlinSettings::reset() {
1556 1556
         SERIAL_ECHOLNPGM(":");
1557 1557
       }
1558 1558
       CONFIG_ECHO_START;
1559
-      SERIAL_ECHOPAIR("  M420 S", leveling_is_active() ? 1 : 0);
1559
+      SERIAL_ECHOPAIR("  M420 S", LEVELING_IS_ACTIVE() ? 1 : 0);
1560 1560
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1561 1561
         SERIAL_ECHOPAIR(" Z", planner.z_fade_height);
1562 1562
       #endif
@@ -1578,7 +1578,7 @@ void MarlinSettings::reset() {
1578 1578
         SERIAL_ECHOLNPGM("Auto Bed Leveling:");
1579 1579
       }
1580 1580
       CONFIG_ECHO_START;
1581
-      SERIAL_ECHOPAIR("  M420 S", leveling_is_active() ? 1 : 0);
1581
+      SERIAL_ECHOPAIR("  M420 S", LEVELING_IS_ACTIVE() ? 1 : 0);
1582 1582
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1583 1583
         SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1584 1584
       #endif

+ 2
- 2
Marlin/src/module/motion.cpp View File

@@ -490,14 +490,14 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
490 490
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
491 491
     #if ENABLED(DELTA)
492 492
       #define ADJUST_DELTA(V) \
493
-        if (planner.abl_enabled) { \
493
+        if (LEVELING_IS_ACTIVE()) { \
494 494
           const float zadj = bilinear_z_offset(V); \
495 495
           delta[A_AXIS] += zadj; \
496 496
           delta[B_AXIS] += zadj; \
497 497
           delta[C_AXIS] += zadj; \
498 498
         }
499 499
     #else
500
-      #define ADJUST_DELTA(V) if (planner.abl_enabled) { delta[Z_AXIS] += bilinear_z_offset(V); }
500
+      #define ADJUST_DELTA(V) if (LEVELING_IS_ACTIVE()) { delta[Z_AXIS] += bilinear_z_offset(V); }
501 501
     #endif
502 502
   #else
503 503
     #define ADJUST_DELTA(V) NOOP

+ 14
- 22
Marlin/src/module/planner.cpp View File

@@ -555,8 +555,9 @@ void Planner::calculate_volumetric_multipliers() {
555 555
    */
556 556
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
557 557
 
558
+    if (!LEVELING_IS_ACTIVE()) return;
559
+
558 560
     #if ENABLED(AUTO_BED_LEVELING_UBL)
559
-      if (!ubl.state.active) return;
560 561
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
561 562
         // if z_fade_height enabled (nonzero) and raw_z above it, no leveling required
562 563
         if (planner.z_fade_height && planner.z_fade_height <= RAW_Z_POSITION(lz)) return;
@@ -566,10 +567,6 @@ void Planner::calculate_volumetric_multipliers() {
566 567
       #endif // FADE
567 568
     #endif // UBL
568 569
 
569
-    #if OLDSCHOOL_ABL
570
-      if (!abl_enabled) return;
571
-    #endif
572
-
573 570
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_UBL)
574 571
       static float z_fade_factor = 1.0, last_raw_lz = -999.0;
575 572
       if (z_fade_height) {
@@ -586,12 +583,11 @@ void Planner::calculate_volumetric_multipliers() {
586 583
 
587 584
     #if ENABLED(MESH_BED_LEVELING)
588 585
 
589
-      if (mbl.active())
590
-        lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
591
-          #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
592
-            , z_fade_factor
593
-          #endif
594
-          );
586
+      lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
587
+        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
588
+          , z_fade_factor
589
+        #endif
590
+        );
595 591
 
596 592
     #elif ABL_PLANAR
597 593
 
@@ -654,9 +650,7 @@ void Planner::calculate_volumetric_multipliers() {
654 650
 
655 651
     #endif
656 652
 
657
-    #if OLDSCHOOL_ABL
658
-      if (!abl_enabled) return;
659
-    #endif
653
+    if (!LEVELING_IS_ACTIVE()) return;
660 654
 
661 655
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
662 656
       if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
@@ -664,14 +658,12 @@ void Planner::calculate_volumetric_multipliers() {
664 658
 
665 659
     #if ENABLED(MESH_BED_LEVELING)
666 660
 
667
-      if (mbl.active()) {
668
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
669
-          const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0);
670
-          logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);
671
-        #else
672
-          logical[Z_AXIS] -= mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]));
673
-        #endif
674
-      }
661
+      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
662
+        const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0);
663
+        logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);
664
+      #else
665
+        logical[Z_AXIS] -= mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]));
666
+      #endif
675 667
 
676 668
     #elif ABL_PLANAR
677 669
 

+ 1
- 1
Marlin/src/module/probe.cpp View File

@@ -679,7 +679,7 @@ void refresh_zprobe_zoffset(const bool no_babystep/*=false*/) {
679 679
     #endif
680 680
 
681 681
     #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
682
-      if (!no_babystep && leveling_is_active())
682
+      if (!no_babystep && LEVELING_IS_ACTIVE())
683 683
         thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS]));
684 684
     #else
685 685
       UNUSED(no_babystep);

+ 1
- 1
Marlin/src/module/tool_change.cpp View File

@@ -464,7 +464,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
464 464
 
465 465
             #if ENABLED(MESH_BED_LEVELING)
466 466
 
467
-              if (leveling_is_active()) {
467
+              if (LEVELING_IS_ACTIVE()) {
468 468
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
469 469
                   if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
470 470
                 #endif

Loading…
Cancel
Save