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

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

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
  * Turn bed leveling on or off, fixing the current
59
  * Turn bed leveling on or off, fixing the current
72
  * position as-needed.
60
  * position as-needed.
82
     constexpr bool can_change = true;
70
     constexpr bool can_change = true;
83
   #endif
71
   #endif
84
 
72
 
85
-  if (can_change && enable != leveling_is_active()) {
73
+  if (can_change && enable != LEVELING_IS_ACTIVE()) {
86
 
74
 
87
     #if ENABLED(MESH_BED_LEVELING)
75
     #if ENABLED(MESH_BED_LEVELING)
88
 
76
 
143
 
131
 
144
   void set_z_fade_height(const float zfh) {
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
     #if ENABLED(AUTO_BED_LEVELING_UBL)
136
     #if ENABLED(AUTO_BED_LEVELING_UBL)
149
 
137
 

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

40
 #endif
40
 #endif
41
 
41
 
42
 bool leveling_is_valid();
42
 bool leveling_is_valid();
43
-bool leveling_is_active();
44
 void set_bed_leveling_enabled(const bool enable=true);
43
 void set_bed_leveling_enabled(const bool enable=true);
45
 void reset_bed_level();
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
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
56
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
48
   void set_z_fade_height(const float zfh);
57
   void set_z_fade_height(const float zfh);
49
 #endif
58
 #endif

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

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

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

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

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

92
   switch (state) {
92
   switch (state) {
93
     case MeshReport:
93
     case MeshReport:
94
       if (leveling_is_valid()) {
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
         mbl_mesh_report();
96
         mbl_mesh_report();
97
       }
97
       }
98
       else
98
       else

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

157
   // Disable the leveling matrix before homing
157
   // Disable the leveling matrix before homing
158
   #if HAS_LEVELING
158
   #if HAS_LEVELING
159
     #if ENABLED(AUTO_BED_LEVELING_UBL)
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
     #endif
161
     #endif
162
     set_bed_leveling_enabled(false);
162
     set_bed_leveling_enabled(false);
163
   #endif
163
   #endif

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

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

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

1086
           const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
1086
           const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
1087
           if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
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
               thermalManager.babystep_axis(Z_AXIS, babystep_increment);
1090
               thermalManager.babystep_axis(Z_AXIS, babystep_increment);
1091
 
1091
 
1092
             zprobe_zoffset = new_zoffset;
1092
             zprobe_zoffset = new_zoffset;
1934
       if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
1934
       if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
1935
         MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
1935
         MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
1936
       else if (leveling_is_valid()) {
1936
       else if (leveling_is_valid()) {
1937
-        _level_state = leveling_is_active();
1937
+        _level_state = LEVELING_IS_ACTIVE();
1938
         MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &_level_state, _lcd_toggle_bed_leveling);
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
     lcd.print(ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
795
     lcd.print(ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
796
 
796
 
797
     #if HAS_LEVELING
797
     #if HAS_LEVELING
798
-      lcd.write(leveling_is_active() || blink ? '_' : ' ');
798
+      lcd.write(LEVELING_IS_ACTIVE() || blink ? '_' : ' ');
799
     #endif
799
     #endif
800
 
800
 
801
   #endif // LCD_HEIGHT > 2
801
   #endif // LCD_HEIGHT > 2

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

1556
         SERIAL_ECHOLNPGM(":");
1556
         SERIAL_ECHOLNPGM(":");
1557
       }
1557
       }
1558
       CONFIG_ECHO_START;
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
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1560
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1561
         SERIAL_ECHOPAIR(" Z", planner.z_fade_height);
1561
         SERIAL_ECHOPAIR(" Z", planner.z_fade_height);
1562
       #endif
1562
       #endif
1578
         SERIAL_ECHOLNPGM("Auto Bed Leveling:");
1578
         SERIAL_ECHOLNPGM("Auto Bed Leveling:");
1579
       }
1579
       }
1580
       CONFIG_ECHO_START;
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
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1582
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1583
         SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1583
         SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1584
       #endif
1584
       #endif

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

490
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
490
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
491
     #if ENABLED(DELTA)
491
     #if ENABLED(DELTA)
492
       #define ADJUST_DELTA(V) \
492
       #define ADJUST_DELTA(V) \
493
-        if (planner.abl_enabled) { \
493
+        if (LEVELING_IS_ACTIVE()) { \
494
           const float zadj = bilinear_z_offset(V); \
494
           const float zadj = bilinear_z_offset(V); \
495
           delta[A_AXIS] += zadj; \
495
           delta[A_AXIS] += zadj; \
496
           delta[B_AXIS] += zadj; \
496
           delta[B_AXIS] += zadj; \
497
           delta[C_AXIS] += zadj; \
497
           delta[C_AXIS] += zadj; \
498
         }
498
         }
499
     #else
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
     #endif
501
     #endif
502
   #else
502
   #else
503
     #define ADJUST_DELTA(V) NOOP
503
     #define ADJUST_DELTA(V) NOOP

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

555
    */
555
    */
556
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
556
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
557
 
557
 
558
+    if (!LEVELING_IS_ACTIVE()) return;
559
+
558
     #if ENABLED(AUTO_BED_LEVELING_UBL)
560
     #if ENABLED(AUTO_BED_LEVELING_UBL)
559
-      if (!ubl.state.active) return;
560
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
561
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
561
         // if z_fade_height enabled (nonzero) and raw_z above it, no leveling required
562
         // if z_fade_height enabled (nonzero) and raw_z above it, no leveling required
562
         if (planner.z_fade_height && planner.z_fade_height <= RAW_Z_POSITION(lz)) return;
563
         if (planner.z_fade_height && planner.z_fade_height <= RAW_Z_POSITION(lz)) return;
566
       #endif // FADE
567
       #endif // FADE
567
     #endif // UBL
568
     #endif // UBL
568
 
569
 
569
-    #if OLDSCHOOL_ABL
570
-      if (!abl_enabled) return;
571
-    #endif
572
-
573
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_UBL)
570
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_UBL)
574
       static float z_fade_factor = 1.0, last_raw_lz = -999.0;
571
       static float z_fade_factor = 1.0, last_raw_lz = -999.0;
575
       if (z_fade_height) {
572
       if (z_fade_height) {
586
 
583
 
587
     #if ENABLED(MESH_BED_LEVELING)
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
     #elif ABL_PLANAR
592
     #elif ABL_PLANAR
597
 
593
 
654
 
650
 
655
     #endif
651
     #endif
656
 
652
 
657
-    #if OLDSCHOOL_ABL
658
-      if (!abl_enabled) return;
659
-    #endif
653
+    if (!LEVELING_IS_ACTIVE()) return;
660
 
654
 
661
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
655
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
662
       if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
656
       if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
664
 
658
 
665
     #if ENABLED(MESH_BED_LEVELING)
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
     #elif ABL_PLANAR
668
     #elif ABL_PLANAR
677
 
669
 

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

679
     #endif
679
     #endif
680
 
680
 
681
     #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
681
     #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
682
-      if (!no_babystep && leveling_is_active())
682
+      if (!no_babystep && LEVELING_IS_ACTIVE())
683
         thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS]));
683
         thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS]));
684
     #else
684
     #else
685
       UNUSED(no_babystep);
685
       UNUSED(no_babystep);

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

464
 
464
 
465
             #if ENABLED(MESH_BED_LEVELING)
465
             #if ENABLED(MESH_BED_LEVELING)
466
 
466
 
467
-              if (leveling_is_active()) {
467
+              if (LEVELING_IS_ACTIVE()) {
468
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
468
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
469
                   if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
469
                   if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
470
                 #endif
470
                 #endif

Loading…
Cancel
Save