Browse Source

Use bit flags for homed/known

Scott Lahteine 6 years ago
parent
commit
f2c3b0d476

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

@@ -161,7 +161,7 @@ bool Running = true;
161 161
  *   Flags that the position is known in each linear axis. Set when homed.
162 162
  *   Cleared whenever a stepper powers off, potentially losing its position.
163 163
  */
164
-bool axis_homed[XYZ] = { false }, axis_known_position[XYZ] = { false };
164
+uint8_t axis_homed, axis_known_position; // = 0
165 165
 
166 166
 #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
167 167
   TempUnit input_temp_units = TEMPUNIT_C;

+ 12
- 8
Marlin/src/Marlin.h View File

@@ -44,10 +44,10 @@ void manage_inactivity(const bool ignore_stepper_queue=false);
44 44
 
45 45
 #if HAS_X2_ENABLE
46 46
   #define  enable_X() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0)
47
-  #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
47
+  #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); CBI(axis_known_position, X_AXIS); }while(0)
48 48
 #elif HAS_X_ENABLE
49 49
   #define  enable_X() X_ENABLE_WRITE( X_ENABLE_ON)
50
-  #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
50
+  #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); CBI(axis_known_position, X_AXIS); }while(0)
51 51
 #else
52 52
   #define  enable_X() NOOP
53 53
   #define disable_X() NOOP
@@ -55,10 +55,10 @@ void manage_inactivity(const bool ignore_stepper_queue=false);
55 55
 
56 56
 #if HAS_Y2_ENABLE
57 57
   #define  enable_Y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0)
58
-  #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
58
+  #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); CBI(axis_known_position, Y_AXIS); }while(0)
59 59
 #elif HAS_Y_ENABLE
60 60
   #define  enable_Y() Y_ENABLE_WRITE( Y_ENABLE_ON)
61
-  #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
61
+  #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); CBI(axis_known_position, Y_AXIS); }while(0)
62 62
 #else
63 63
   #define  enable_Y() NOOP
64 64
   #define disable_Y() NOOP
@@ -66,10 +66,10 @@ void manage_inactivity(const bool ignore_stepper_queue=false);
66 66
 
67 67
 #if HAS_Z2_ENABLE
68 68
   #define  enable_Z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
69
-  #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
69
+  #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); CBI(axis_known_position, Z_AXIS); }while(0)
70 70
 #elif HAS_Z_ENABLE
71 71
   #define  enable_Z() Z_ENABLE_WRITE( Z_ENABLE_ON)
72
-  #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
72
+  #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); CBI(axis_known_position, Z_AXIS); }while(0)
73 73
 #else
74 74
   #define  enable_Z() NOOP
75 75
   #define disable_Z() NOOP
@@ -169,8 +169,12 @@ extern bool Running;
169 169
 inline bool IsRunning() { return  Running; }
170 170
 inline bool IsStopped() { return !Running; }
171 171
 
172
-extern bool axis_known_position[XYZ];
173
-extern bool axis_homed[XYZ];
172
+extern uint8_t axis_homed, axis_known_position;
173
+
174
+constexpr uint8_t xyz_bits = _BV(X_AXIS) | _BV(Y_AXIS) | _BV(Z_AXIS);
175
+FORCE_INLINE bool all_axes_homed() { return (axis_homed & xyz_bits) == xyz_bits; }
176
+FORCE_INLINE bool all_axes_known() { return (axis_known_position & xyz_bits) == xyz_bits; }
177
+
174 178
 extern volatile bool wait_for_heatup;
175 179
 
176 180
 #if HAS_RESUME_CONTINUE

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

@@ -88,7 +88,7 @@
88 88
   inline void home_z_safely() {
89 89
 
90 90
     // Disallow Z homing if X or Y are unknown
91
-    if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
91
+    if (!TEST(axis_known_position, X_AXIS) || !TEST(axis_known_position, Y_AXIS)) {
92 92
       LCD_MESSAGEPGM(MSG_ERR_Z_HOMING);
93 93
       SERIAL_ECHO_START();
94 94
       SERIAL_ECHOLNPGM(MSG_ERR_Z_HOMING);
@@ -172,7 +172,7 @@ void GcodeSuite::G28(const bool always_home_all) {
172 172
     }
173 173
   #endif
174 174
 
175
-  if ((axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]) && parser.boolval('O')) { // home only if needed
175
+  if (all_axes_known() && parser.boolval('O')) { // home only if needed
176 176
     #if ENABLED(DEBUG_LEVELING_FEATURE)
177 177
       if (DEBUGGING(LEVELING)) {
178 178
         SERIAL_ECHOLNPGM("> homing not needed, skip");
@@ -246,7 +246,7 @@ void GcodeSuite::G28(const bool always_home_all) {
246 246
 
247 247
     const float z_homing_height = (
248 248
       #if ENABLED(UNKNOWN_Z_NO_RAISE)
249
-        !axis_known_position[Z_AXIS] ? 0 :
249
+        !TEST(axis_known_position, Z_AXIS) ? 0 :
250 250
       #endif
251 251
           (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT)
252 252
     );

+ 1
- 1
Marlin/src/gcode/feature/trinamic/M911-M915.cpp View File

@@ -332,7 +332,7 @@ void GcodeSuite::M912() {
332 332
     const uint16_t _rms = parser.seenval('S') ? parser.value_int() : CALIBRATION_CURRENT,
333 333
                    _z = parser.seenval('Z') ? parser.value_linear_units() : CALIBRATION_EXTRA_HEIGHT;
334 334
 
335
-    if (!axis_known_position[Z_AXIS]) {
335
+    if (!TEST(axis_known_position, Z_AXIS)) {
336 336
       SERIAL_ECHOLNPGM("\nPlease home Z axis first");
337 337
       return;
338 338
     }

+ 2
- 2
Marlin/src/lcd/dogm/status_screen_DOGM.h View File

@@ -108,11 +108,11 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
108 108
   if (blink)
109 109
     lcd_put_u8str(value);
110 110
   else {
111
-    if (!axis_homed[axis])
111
+    if (!TEST(axis_homed, axis))
112 112
       while (const char c = *value++) lcd_put_wchar(c <= '.' ? c : '?');
113 113
     else {
114 114
       #if DISABLED(HOME_AFTER_DEACTIVATE) && DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
115
-        if (!axis_known_position[axis])
115
+        if (!TEST(axis_known_position, axis))
116 116
           lcd_put_u8str_P(axis == Z_AXIS ? PSTR("      ") : PSTR("    "));
117 117
         else
118 118
       #endif

+ 1
- 3
Marlin/src/lcd/dogm/status_screen_lite_ST7920.h View File

@@ -868,9 +868,7 @@ void ST7920_Lite_Status_Screen::update_status_or_position(bool forceUpdate) {
868 868
         #if ENABLED(DISABLE_REDUCED_ACCURACY_WARNING)
869 869
           true
870 870
         #else
871
-          axis_known_position[X_AXIS] &&
872
-          axis_known_position[Y_AXIS] &&
873
-          axis_known_position[Z_AXIS]
871
+          all_axes_known()
874 872
         #endif
875 873
       );
876 874
     }

+ 14
- 16
Marlin/src/lcd/ultralcd.cpp View File

@@ -2026,8 +2026,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2026 2026
     void _lcd_level_bed_homing() {
2027 2027
       if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
2028 2028
       lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
2029
-      if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
2030
-        lcd_goto_screen(_lcd_level_bed_homing_done);
2029
+      if (all_axes_homed()) lcd_goto_screen(_lcd_level_bed_homing_done);
2031 2030
     }
2032 2031
 
2033 2032
     #if ENABLED(PROBE_MANUALLY)
@@ -2039,7 +2038,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2039 2038
      */
2040 2039
     void _lcd_level_bed_continue() {
2041 2040
       defer_return_to_status = true;
2042
-      axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
2041
+      axis_homed = 0;
2043 2042
       lcd_goto_screen(_lcd_level_bed_homing);
2044 2043
       enqueue_and_echo_commands_P(PSTR("G28"));
2045 2044
     }
@@ -2369,7 +2368,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2369 2368
       defer_return_to_status = true;
2370 2369
       if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT < 3 ? 0 : (LCD_HEIGHT > 4 ? 2 : 1), PSTR(MSG_LEVEL_BED_HOMING));
2371 2370
       lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
2372
-      if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
2371
+      if (all_axes_homed()) {
2373 2372
         ubl.lcd_map_control = true; // Return to the map screen
2374 2373
         lcd_goto_screen(_lcd_ubl_output_map_lcd);
2375 2374
       }
@@ -2414,7 +2413,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2414 2413
     void _lcd_ubl_output_map_lcd() {
2415 2414
       static int16_t step_scaler = 0;
2416 2415
 
2417
-      if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
2416
+      if (!all_axes_known())
2418 2417
         return lcd_goto_screen(_lcd_ubl_map_homing);
2419 2418
 
2420 2419
       if (use_click()) return _lcd_ubl_map_lcd_edit_cmd();
@@ -2463,8 +2462,8 @@ void lcd_quick_feedback(const bool clear_buttons) {
2463 2462
      * UBL Homing before LCD map
2464 2463
      */
2465 2464
     void _lcd_ubl_output_map_lcd_cmd() {
2466
-      if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS])) {
2467
-        axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
2465
+      if (!all_axes_known()) {
2466
+        axis_homed = 0;
2468 2467
         enqueue_and_echo_commands_P(PSTR("G28"));
2469 2468
       }
2470 2469
       lcd_goto_screen(_lcd_ubl_map_homing);
@@ -2592,7 +2591,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2592 2591
       START_MENU();
2593 2592
       MENU_BACK(MSG_PREPARE);
2594 2593
 
2595
-      const bool is_homed = axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS];
2594
+      const bool is_homed = all_axes_known();
2596 2595
 
2597 2596
       // Auto Home if not using manual probing
2598 2597
       #if DISABLED(PROBE_MANUALLY) && DISABLED(MESH_BED_LEVELING)
@@ -2634,8 +2633,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2634 2633
 
2635 2634
       #if ENABLED(LEVEL_BED_CORNERS)
2636 2635
         // Move to the next corner for leveling
2637
-        if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
2638
-          MENU_ITEM(submenu, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
2636
+        if (all_axes_homed()) MENU_ITEM(submenu, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
2639 2637
       #endif
2640 2638
 
2641 2639
       #if ENABLED(EEPROM_SETTINGS)
@@ -2665,7 +2663,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2665 2663
     // Move Axis
2666 2664
     //
2667 2665
     #if ENABLED(DELTA)
2668
-      if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
2666
+      if (all_axes_homed())
2669 2667
     #endif
2670 2668
         MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
2671 2669
 
@@ -2709,7 +2707,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2709 2707
     #endif
2710 2708
 
2711 2709
     #if ENABLED(LEVEL_BED_CORNERS) && DISABLED(LCD_BED_LEVELING)
2712
-      if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
2710
+      if (all_axes_homed())
2713 2711
         MENU_ITEM(function, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
2714 2712
     #endif
2715 2713
 
@@ -2839,7 +2837,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2839 2837
     void _lcd_calibrate_homing() {
2840 2838
       if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
2841 2839
       lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
2842
-      if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
2840
+      if (all_axes_homed())
2843 2841
         lcd_goto_previous_menu();
2844 2842
     }
2845 2843
 
@@ -2894,7 +2892,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2894 2892
       MENU_ITEM(submenu, MSG_DELTA_SETTINGS, lcd_delta_settings);
2895 2893
       #if ENABLED(DELTA_CALIBRATION_MENU)
2896 2894
         MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
2897
-        if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
2895
+        if (all_axes_homed()) {
2898 2896
           MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
2899 2897
           MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
2900 2898
           MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
@@ -3190,7 +3188,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
3190 3188
    */
3191 3189
 
3192 3190
   #if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
3193
-    #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
3191
+    #define _MOVE_XYZ_ALLOWED (all_axes_homed())
3194 3192
   #else
3195 3193
     #define _MOVE_XYZ_ALLOWED true
3196 3194
   #endif
@@ -4930,7 +4928,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
4930 4928
           if (REPRAPWORLD_KEYPAD_MOVE_Z_UP)     reprapworld_keypad_move_z_up();
4931 4929
         #endif
4932 4930
 
4933
-        if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
4931
+        if (all_axes_homed()) {
4934 4932
           #if ENABLED(DELTA) || Z_HOME_DIR != -1
4935 4933
             if (REPRAPWORLD_KEYPAD_MOVE_Z_UP)   reprapworld_keypad_move_z_up();
4936 4934
           #endif

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

@@ -493,11 +493,11 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
493 493
   if (blink)
494 494
     lcd_put_u8str(value);
495 495
   else {
496
-    if (!axis_homed[axis])
496
+    if (!TEST(axis_homed, axis))
497 497
       while (const char c = *value++) lcd_put_wchar(c <= '.' ? c : '?');
498 498
     else {
499 499
       #if DISABLED(HOME_AFTER_DEACTIVATE) && DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
500
-        if (!axis_known_position[axis])
500
+        if (!TEST(axis_known_position, axis))
501 501
           lcd_put_u8str_P(axis == Z_AXIS ? PSTR("      ") : PSTR("    "));
502 502
         else
503 503
       #endif

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

@@ -73,7 +73,7 @@ void recalc_delta_settings() {
73 73
   delta_diagonal_rod_2_tower[B_AXIS] = sq(delta_diagonal_rod + drt[B_AXIS]);
74 74
   delta_diagonal_rod_2_tower[C_AXIS] = sq(delta_diagonal_rod + drt[C_AXIS]);
75 75
   update_software_endstops(Z_AXIS);
76
-  axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
76
+  axis_homed = 0;
77 77
 }
78 78
 
79 79
 /**

+ 8
- 7
Marlin/src/module/motion.cpp View File

@@ -957,13 +957,13 @@ void prepare_move_to_destination() {
957 957
 
958 958
   bool axis_unhomed_error(const bool x/*=true*/, const bool y/*=true*/, const bool z/*=true*/) {
959 959
     #if ENABLED(HOME_AFTER_DEACTIVATE)
960
-      const bool xx = x && !axis_known_position[X_AXIS],
961
-                 yy = y && !axis_known_position[Y_AXIS],
962
-                 zz = z && !axis_known_position[Z_AXIS];
960
+      const bool xx = x && !TEST(axis_known_position, X_AXIS),
961
+                 yy = y && !TEST(axis_known_position, Y_AXIS),
962
+                 zz = z && !TEST(axis_known_position, Z_AXIS);
963 963
     #else
964
-      const bool xx = x && !axis_homed[X_AXIS],
965
-                 yy = y && !axis_homed[Y_AXIS],
966
-                 zz = z && !axis_homed[Z_AXIS];
964
+      const bool xx = x && !TEST(axis_homed, X_AXIS),
965
+                 yy = y && !TEST(axis_homed, Y_AXIS),
966
+                 zz = z && !TEST(axis_homed, Z_AXIS);
967 967
     #endif
968 968
     if (xx || yy || zz) {
969 969
       SERIAL_ECHO_START();
@@ -1173,7 +1173,8 @@ void set_axis_is_at_home(const AxisEnum axis) {
1173 1173
     }
1174 1174
   #endif
1175 1175
 
1176
-  axis_known_position[axis] = axis_homed[axis] = true;
1176
+  SBI(axis_known_position, axis);
1177
+  SBI(axis_homed, axis);
1177 1178
 
1178 1179
   #if HAS_POSITION_SHIFT
1179 1180
     position_shift[axis] = 0;

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

@@ -386,7 +386,7 @@ bool set_probe_deployed(const bool deploy) {
386 386
 
387 387
   // For beds that fall when Z is powered off only raise for trusted Z
388 388
   #if ENABLED(UNKNOWN_Z_NO_RAISE)
389
-    const bool unknown_condition = axis_known_position[Z_AXIS];
389
+    const bool unknown_condition = TEST(axis_known_position, Z_AXIS);
390 390
   #else
391 391
     constexpr float unknown_condition = true;
392 392
   #endif
@@ -562,7 +562,7 @@ static float run_z_probe() {
562 562
 
563 563
   // Stop the probe before it goes too low to prevent damage.
564 564
   // If Z isn't known then probe to -10mm.
565
-  const float z_probe_low_point = axis_known_position[Z_AXIS] ? -zprobe_zoffset + Z_PROBE_LOW_POINT : -10.0;
565
+  const float z_probe_low_point = TEST(axis_known_position, Z_AXIS) ? -zprobe_zoffset + Z_PROBE_LOW_POINT : -10.0;
566 566
 
567 567
   // Double-probing does a fast probe followed by a slow probe
568 568
   #if MULTIPLE_PROBING == 2

+ 2
- 2
Marlin/src/module/temperature.h View File

@@ -31,7 +31,7 @@
31 31
 #include "../inc/MarlinConfig.h"
32 32
 
33 33
 #if ENABLED(BABYSTEPPING)
34
-  extern bool axis_known_position[XYZ];
34
+  extern uint8_t axis_known_position;
35 35
 #endif
36 36
 
37 37
 #if ENABLED(AUTO_POWER_CONTROL)
@@ -504,7 +504,7 @@ class Temperature {
504 504
     #if ENABLED(BABYSTEPPING)
505 505
 
506 506
       static void babystep_axis(const AxisEnum axis, const int16_t distance) {
507
-        if (axis_known_position[axis]) {
507
+        if (TEST(axis_known_position, axis)) {
508 508
           #if IS_CORE
509 509
             #if ENABLED(BABYSTEP_XY)
510 510
               switch (axis) {

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

@@ -80,7 +80,7 @@
80 80
     }
81 81
   }
82 82
 
83
-#endif // SWITCHING_EXTRUDER
83
+#endif // DO_SWITCH_EXTRUDER
84 84
 
85 85
 #if ENABLED(SWITCHING_NOZZLE)
86 86
 

Loading…
Cancel
Save