mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-26 13:25:54 +00:00
Use bit flags for homed/known
This commit is contained in:
parent
4ed92f838f
commit
4bc5e9341e
@ -60,10 +60,10 @@ extern const char axis_codes[XYZE];
|
||||
|
||||
#if HAS_X2_ENABLE
|
||||
#define enable_X() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0)
|
||||
#define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
|
||||
#define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); CBI(axis_known_position, X_AXIS); }while(0)
|
||||
#elif HAS_X_ENABLE
|
||||
#define enable_X() X_ENABLE_WRITE( X_ENABLE_ON)
|
||||
#define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
|
||||
#define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); CBI(axis_known_position, X_AXIS); }while(0)
|
||||
#else
|
||||
#define enable_X() NOOP
|
||||
#define disable_X() NOOP
|
||||
@ -71,10 +71,10 @@ extern const char axis_codes[XYZE];
|
||||
|
||||
#if HAS_Y2_ENABLE
|
||||
#define enable_Y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0)
|
||||
#define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
|
||||
#define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); CBI(axis_known_position, Y_AXIS); }while(0)
|
||||
#elif HAS_Y_ENABLE
|
||||
#define enable_Y() Y_ENABLE_WRITE( Y_ENABLE_ON)
|
||||
#define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
|
||||
#define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); CBI(axis_known_position, Y_AXIS); }while(0)
|
||||
#else
|
||||
#define enable_Y() NOOP
|
||||
#define disable_Y() NOOP
|
||||
@ -82,10 +82,10 @@ extern const char axis_codes[XYZE];
|
||||
|
||||
#if HAS_Z2_ENABLE
|
||||
#define enable_Z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
|
||||
#define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
|
||||
#define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); CBI(axis_known_position, Z_AXIS); }while(0)
|
||||
#elif HAS_Z_ENABLE
|
||||
#define enable_Z() Z_ENABLE_WRITE( Z_ENABLE_ON)
|
||||
#define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
|
||||
#define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); CBI(axis_known_position, Z_AXIS); }while(0)
|
||||
#else
|
||||
#define enable_Z() NOOP
|
||||
#define disable_Z() NOOP
|
||||
@ -222,9 +222,14 @@ extern int16_t feedrate_percentage;
|
||||
|
||||
#define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01)
|
||||
|
||||
extern bool axis_relative_modes[];
|
||||
extern bool axis_known_position[XYZ];
|
||||
extern bool axis_homed[XYZ];
|
||||
extern bool axis_relative_modes[XYZE];
|
||||
|
||||
extern uint8_t axis_homed, axis_known_position;
|
||||
|
||||
constexpr uint8_t xyz_bits = _BV(X_AXIS) | _BV(Y_AXIS) | _BV(Z_AXIS);
|
||||
FORCE_INLINE bool all_axes_homed() { return (axis_homed & xyz_bits) == xyz_bits; }
|
||||
FORCE_INLINE bool all_axes_known() { return (axis_known_position & xyz_bits) == xyz_bits; }
|
||||
|
||||
extern volatile bool wait_for_heatup;
|
||||
|
||||
#if HAS_RESUME_CONTINUE
|
||||
|
@ -397,7 +397,7 @@ float destination[XYZE] = { 0.0 };
|
||||
* Flags that the position is known in each linear axis. Set when homed.
|
||||
* Cleared whenever a stepper powers off, potentially losing its position.
|
||||
*/
|
||||
bool axis_homed[XYZ] = { false }, axis_known_position[XYZ] = { false };
|
||||
uint8_t axis_homed, axis_known_position; // = 0
|
||||
|
||||
/**
|
||||
* GCode line number handling. Hosts may opt to include line numbers when
|
||||
@ -451,7 +451,7 @@ static float saved_feedrate_mm_s;
|
||||
int16_t feedrate_percentage = 100, saved_feedrate_percentage;
|
||||
|
||||
// Initialized by settings.load()
|
||||
bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
|
||||
bool axis_relative_modes[XYZE] = AXIS_RELATIVE_MODES;
|
||||
|
||||
#if HAS_WORKSPACE_OFFSET
|
||||
#if HAS_POSITION_SHIFT
|
||||
@ -1428,7 +1428,8 @@ static void set_axis_is_at_home(const AxisEnum axis) {
|
||||
}
|
||||
#endif
|
||||
|
||||
axis_known_position[axis] = axis_homed[axis] = true;
|
||||
SBI(axis_known_position, axis);
|
||||
SBI(axis_homed, axis);
|
||||
|
||||
#if HAS_POSITION_SHIFT
|
||||
position_shift[axis] = 0;
|
||||
@ -1753,13 +1754,13 @@ void clean_up_after_endstop_or_probe_move() {
|
||||
|
||||
bool axis_unhomed_error(const bool x/*=true*/, const bool y/*=true*/, const bool z/*=true*/) {
|
||||
#if ENABLED(HOME_AFTER_DEACTIVATE)
|
||||
const bool xx = x && !axis_known_position[X_AXIS],
|
||||
yy = y && !axis_known_position[Y_AXIS],
|
||||
zz = z && !axis_known_position[Z_AXIS];
|
||||
const bool xx = x && !TEST(axis_known_position, X_AXIS),
|
||||
yy = y && !TEST(axis_known_position, Y_AXIS),
|
||||
zz = z && !TEST(axis_known_position, Z_AXIS);
|
||||
#else
|
||||
const bool xx = x && !axis_homed[X_AXIS],
|
||||
yy = y && !axis_homed[Y_AXIS],
|
||||
zz = z && !axis_homed[Z_AXIS];
|
||||
const bool xx = x && !TEST(axis_homed, X_AXIS),
|
||||
yy = y && !TEST(axis_homed, Y_AXIS),
|
||||
zz = z && !TEST(axis_homed, Z_AXIS);
|
||||
#endif
|
||||
if (xx || yy || zz) {
|
||||
SERIAL_ECHO_START();
|
||||
@ -2110,7 +2111,7 @@ void clean_up_after_endstop_or_probe_move() {
|
||||
|
||||
// For beds that fall when Z is powered off only raise for trusted Z
|
||||
#if ENABLED(UNKNOWN_Z_NO_RAISE)
|
||||
const bool unknown_condition = axis_known_position[Z_AXIS];
|
||||
const bool unknown_condition = TEST(axis_known_position, Z_AXIS);
|
||||
#else
|
||||
constexpr float unknown_condition = true;
|
||||
#endif
|
||||
@ -2271,7 +2272,7 @@ void clean_up_after_endstop_or_probe_move() {
|
||||
|
||||
// Stop the probe before it goes too low to prevent damage.
|
||||
// If Z isn't known then probe to -10mm.
|
||||
const float z_probe_low_point = axis_known_position[Z_AXIS] ? -zprobe_zoffset + Z_PROBE_LOW_POINT : -10.0;
|
||||
const float z_probe_low_point = TEST(axis_known_position, Z_AXIS) ? -zprobe_zoffset + Z_PROBE_LOW_POINT : -10.0;
|
||||
|
||||
// Double-probing does a fast probe followed by a slow probe
|
||||
#if MULTIPLE_PROBING == 2
|
||||
@ -3978,7 +3979,7 @@ inline void gcode_G4() {
|
||||
inline void home_z_safely() {
|
||||
|
||||
// Disallow Z homing if X or Y are unknown
|
||||
if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
|
||||
if (!TEST(axis_known_position, X_AXIS) || !TEST(axis_known_position, Y_AXIS)) {
|
||||
LCD_MESSAGEPGM(MSG_ERR_Z_HOMING);
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOLNPGM(MSG_ERR_Z_HOMING);
|
||||
@ -4130,7 +4131,7 @@ inline void gcode_G28(const bool always_home_all) {
|
||||
|
||||
const float z_homing_height = (
|
||||
#if ENABLED(UNKNOWN_Z_NO_RAISE)
|
||||
!axis_known_position[Z_AXIS] ? 0 :
|
||||
!TEST(axis_known_position, Z_AXIS) ? 0 :
|
||||
#endif
|
||||
(parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT)
|
||||
);
|
||||
@ -11277,7 +11278,7 @@ inline void gcode_M502() {
|
||||
const uint16_t _rms = parser.seenval('S') ? parser.value_int() : CALIBRATION_CURRENT,
|
||||
_z = parser.seenval('Z') ? parser.value_linear_units() : CALIBRATION_EXTRA_HEIGHT;
|
||||
|
||||
if (!axis_known_position[Z_AXIS]) {
|
||||
if (!TEST(axis_known_position, Z_AXIS)) {
|
||||
SERIAL_ECHOLNPGM("\nPlease home Z axis first");
|
||||
return;
|
||||
}
|
||||
@ -12772,7 +12773,7 @@ void ok_to_send() {
|
||||
delta_diagonal_rod_2_tower[B_AXIS] = sq(delta_diagonal_rod + drt[B_AXIS]);
|
||||
delta_diagonal_rod_2_tower[C_AXIS] = sq(delta_diagonal_rod + drt[C_AXIS]);
|
||||
update_software_endstops(Z_AXIS);
|
||||
axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
|
||||
axis_homed = 0;
|
||||
}
|
||||
|
||||
#if ENABLED(DELTA_FAST_SQRT)
|
||||
|
@ -108,11 +108,11 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
|
||||
if (blink)
|
||||
lcd_print(value);
|
||||
else {
|
||||
if (!axis_homed[axis])
|
||||
if (!TEST(axis_homed, axis))
|
||||
while (const char c = *value++) lcd_print(c <= '.' ? c : '?');
|
||||
else {
|
||||
#if DISABLED(HOME_AFTER_DEACTIVATE) && DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
|
||||
if (!axis_known_position[axis])
|
||||
if (!TEST(axis_known_position, axis))
|
||||
lcd_printPGM(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
|
||||
else
|
||||
#endif
|
||||
|
@ -868,9 +868,7 @@ void ST7920_Lite_Status_Screen::update_status_or_position(bool forceUpdate) {
|
||||
#if ENABLED(DISABLE_REDUCED_ACCURACY_WARNING)
|
||||
true
|
||||
#else
|
||||
axis_known_position[X_AXIS] &&
|
||||
axis_known_position[Y_AXIS] &&
|
||||
axis_known_position[Z_AXIS]
|
||||
all_axes_known()
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ class Temperature {
|
||||
#if ENABLED(BABYSTEPPING)
|
||||
|
||||
static void babystep_axis(const AxisEnum axis, const int16_t distance) {
|
||||
if (axis_known_position[axis]) {
|
||||
if (TEST(axis_known_position, axis)) {
|
||||
#if IS_CORE
|
||||
#if ENABLED(BABYSTEP_XY)
|
||||
switch (axis) {
|
||||
|
@ -2016,7 +2016,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
void _lcd_level_bed_homing() {
|
||||
if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
|
||||
lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
|
||||
if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
|
||||
if (all_axes_homed())
|
||||
lcd_goto_screen(_lcd_level_bed_homing_done);
|
||||
}
|
||||
|
||||
@ -2029,7 +2029,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
*/
|
||||
void _lcd_level_bed_continue() {
|
||||
defer_return_to_status = true;
|
||||
axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
|
||||
axis_homed = 0;
|
||||
lcd_goto_screen(_lcd_level_bed_homing);
|
||||
enqueue_and_echo_commands_P(PSTR("G28"));
|
||||
}
|
||||
@ -2359,7 +2359,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
defer_return_to_status = true;
|
||||
if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT < 3 ? 0 : (LCD_HEIGHT > 4 ? 2 : 1), PSTR(MSG_LEVEL_BED_HOMING));
|
||||
lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
|
||||
if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
|
||||
if (all_axes_homed()) {
|
||||
ubl.lcd_map_control = true; // Return to the map screen
|
||||
lcd_goto_screen(_lcd_ubl_output_map_lcd);
|
||||
}
|
||||
@ -2403,7 +2403,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
void _lcd_ubl_output_map_lcd() {
|
||||
static int16_t step_scaler = 0;
|
||||
|
||||
if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
|
||||
if (!all_axes_known())
|
||||
return lcd_goto_screen(_lcd_ubl_map_homing);
|
||||
|
||||
if (use_click()) return _lcd_ubl_map_lcd_edit_cmd();
|
||||
@ -2452,8 +2452,8 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
* UBL Homing before LCD map
|
||||
*/
|
||||
void _lcd_ubl_output_map_lcd_cmd() {
|
||||
if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS])) {
|
||||
axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
|
||||
if (!all_axes_known()) {
|
||||
axis_homed = 0;
|
||||
enqueue_and_echo_commands_P(PSTR("G28"));
|
||||
}
|
||||
lcd_goto_screen(_lcd_ubl_map_homing);
|
||||
@ -2581,7 +2581,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
START_MENU();
|
||||
MENU_BACK(MSG_PREPARE);
|
||||
|
||||
const bool is_homed = axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS];
|
||||
const bool is_homed = all_axes_known();
|
||||
|
||||
// Auto Home if not using manual probing
|
||||
#if DISABLED(PROBE_MANUALLY) && DISABLED(MESH_BED_LEVELING)
|
||||
@ -2623,7 +2623,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
|
||||
#if ENABLED(LEVEL_BED_CORNERS)
|
||||
// Move to the next corner for leveling
|
||||
if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
|
||||
if (all_axes_homed())
|
||||
MENU_ITEM(submenu, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
|
||||
#endif
|
||||
|
||||
@ -2654,7 +2654,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
// Move Axis
|
||||
//
|
||||
#if ENABLED(DELTA)
|
||||
if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
|
||||
if (all_axes_homed())
|
||||
#endif
|
||||
MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
|
||||
|
||||
@ -2698,7 +2698,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
#endif
|
||||
|
||||
#if ENABLED(LEVEL_BED_CORNERS) && DISABLED(LCD_BED_LEVELING)
|
||||
if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
|
||||
if (all_axes_homed())
|
||||
MENU_ITEM(function, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
|
||||
#endif
|
||||
|
||||
@ -2828,7 +2828,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
void _lcd_calibrate_homing() {
|
||||
if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
|
||||
lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
|
||||
if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
|
||||
if (all_axes_homed())
|
||||
lcd_goto_previous_menu();
|
||||
}
|
||||
|
||||
@ -2883,7 +2883,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
MENU_ITEM(submenu, MSG_DELTA_SETTINGS, lcd_delta_settings);
|
||||
#if ENABLED(DELTA_CALIBRATION_MENU)
|
||||
MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
|
||||
if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
|
||||
if (all_axes_homed()) {
|
||||
MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
|
||||
MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
|
||||
MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
|
||||
@ -3179,7 +3179,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
*/
|
||||
|
||||
#if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
|
||||
#define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
|
||||
#define _MOVE_XYZ_ALLOWED (all_axes_homed())
|
||||
#else
|
||||
#define _MOVE_XYZ_ALLOWED true
|
||||
#endif
|
||||
@ -4919,7 +4919,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
|
||||
if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
|
||||
#endif
|
||||
|
||||
if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
|
||||
if (all_axes_homed()) {
|
||||
#if ENABLED(DELTA) || Z_HOME_DIR != -1
|
||||
if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
|
||||
#endif
|
||||
|
@ -636,11 +636,11 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
|
||||
if (blink)
|
||||
lcd.print(value);
|
||||
else {
|
||||
if (!axis_homed[axis])
|
||||
if (!TEST(axis_homed, axis))
|
||||
while (const char c = *value++) lcd_print(c <= '.' ? c : '?');
|
||||
else {
|
||||
#if DISABLED(HOME_AFTER_DEACTIVATE) && DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
|
||||
if (!axis_known_position[axis])
|
||||
if (!TEST(axis_known_position, axis))
|
||||
lcd_printPGM(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
|
||||
else
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user