Browse Source

♻️ Refactor axis homing/trusted state bits

vanilla_fb_2.0.x
Scott Lahteine 4 years ago
committed by Scott Lahteine
parent
commit
57eef65d9c
  1. 20
      Marlin/src/module/motion.cpp
  2. 21
      Marlin/src/module/motion.h

20
Marlin/src/module/motion.cpp

@ -1181,18 +1181,20 @@ void prepare_line_to_destination() {
#if HAS_ENDSTOPS #if HAS_ENDSTOPS
uint8_t axis_homed, axis_trusted; // = 0 linear_axis_bits_t axis_homed, axis_trusted; // = 0
uint8_t axes_should_home(uint8_t axis_bits/*=0x07*/) { linear_axis_bits_t axes_should_home(linear_axis_bits_t axis_bits/*=linear_bits*/) {
#define SHOULD_HOME(A) TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(A) auto set_should = [](linear_axis_bits_t &b, AxisEnum a) {
// Clear test bits that are trusted if (TEST(b, a) && TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(a))
if (TEST(axis_bits, X_AXIS) && SHOULD_HOME(X_AXIS)) CBI(axis_bits, X_AXIS); CBI(b, a);
if (TEST(axis_bits, Y_AXIS) && SHOULD_HOME(Y_AXIS)) CBI(axis_bits, Y_AXIS); };
if (TEST(axis_bits, Z_AXIS) && SHOULD_HOME(Z_AXIS)) CBI(axis_bits, Z_AXIS); set_should(axis_bits, X_AXIS); // Clear test bits that are trusted
set_should(axis_bits, Y_AXIS);
set_should(axis_bits, Z_AXIS);
return axis_bits; return axis_bits;
} }
bool homing_needed_error(uint8_t axis_bits/*=0x07*/) { bool homing_needed_error(linear_axis_bits_t axis_bits/*=linear_bits*/) {
if ((axis_bits = axes_should_home(axis_bits))) { if ((axis_bits = axes_should_home(axis_bits))) {
PGM_P home_first = GET_TEXT(MSG_HOME_FIRST); PGM_P home_first = GET_TEXT(MSG_HOME_FIRST);
char msg[strlen_P(home_first)+1]; char msg[strlen_P(home_first)+1];

21
Marlin/src/module/motion.h

@ -326,7 +326,8 @@ void do_z_clearance(const_float_t zclear, const bool lower_allowed=false);
/** /**
* Homing and Trusted Axes * Homing and Trusted Axes
*/ */
constexpr uint8_t xyz_bits = _BV(X_AXIS) | _BV(Y_AXIS) | _BV(Z_AXIS); typedef IF<(LINEAR_AXES>8), uint16_t, uint8_t>::type linear_axis_bits_t;
constexpr linear_axis_bits_t linear_bits = _BV(LINEAR_AXES) - 1;
void set_axis_is_at_home(const AxisEnum axis); void set_axis_is_at_home(const AxisEnum axis);
@ -340,23 +341,23 @@ void set_axis_is_at_home(const AxisEnum axis);
* Flags that the position is trusted in each linear axis. Set when homed. * Flags that the position is trusted in each linear axis. Set when homed.
* Cleared whenever a stepper powers off, potentially losing its position. * Cleared whenever a stepper powers off, potentially losing its position.
*/ */
extern uint8_t axis_homed, axis_trusted; extern linear_axis_bits_t axis_homed, axis_trusted;
void homeaxis(const AxisEnum axis); void homeaxis(const AxisEnum axis);
void set_axis_never_homed(const AxisEnum axis); void set_axis_never_homed(const AxisEnum axis);
uint8_t axes_should_home(uint8_t axis_bits=0x07); linear_axis_bits_t axes_should_home(linear_axis_bits_t axis_bits=linear_bits);
bool homing_needed_error(uint8_t axis_bits=0x07); bool homing_needed_error(linear_axis_bits_t axis_bits=linear_bits);
FORCE_INLINE void set_axis_unhomed(const AxisEnum axis) { CBI(axis_homed, axis); } FORCE_INLINE void set_axis_unhomed(const AxisEnum axis) { CBI(axis_homed, axis); }
FORCE_INLINE void set_axis_untrusted(const AxisEnum axis) { CBI(axis_trusted, axis); } FORCE_INLINE void set_axis_untrusted(const AxisEnum axis) { CBI(axis_trusted, axis); }
FORCE_INLINE void set_all_unhomed() { axis_homed = axis_trusted = 0; } FORCE_INLINE void set_all_unhomed() { axis_homed = axis_trusted = 0; }
FORCE_INLINE void set_axis_homed(const AxisEnum axis) { SBI(axis_homed, axis); } FORCE_INLINE void set_axis_homed(const AxisEnum axis) { SBI(axis_homed, axis); }
FORCE_INLINE void set_axis_trusted(const AxisEnum axis) { SBI(axis_trusted, axis); } FORCE_INLINE void set_axis_trusted(const AxisEnum axis) { SBI(axis_trusted, axis); }
FORCE_INLINE void set_all_homed() { axis_homed = axis_trusted = xyz_bits; } FORCE_INLINE void set_all_homed() { axis_homed = axis_trusted = linear_bits; }
#else #else
constexpr uint8_t axis_homed = xyz_bits, axis_trusted = xyz_bits; // Zero-endstop machines are always homed and trusted constexpr linear_axis_bits_t axis_homed = linear_bits, axis_trusted = linear_bits; // Zero-endstop machines are always homed and trusted
FORCE_INLINE void homeaxis(const AxisEnum axis) {} FORCE_INLINE void homeaxis(const AxisEnum axis) {}
FORCE_INLINE void set_axis_never_homed(const AxisEnum) {} FORCE_INLINE void set_axis_never_homed(const AxisEnum) {}
FORCE_INLINE uint8_t axes_should_home(uint8_t=0x07) { return false; } FORCE_INLINE linear_axis_bits_t axes_should_home(linear_axis_bits_t=linear_bits) { return false; }
FORCE_INLINE bool homing_needed_error(uint8_t=0x07) { return false; } FORCE_INLINE bool homing_needed_error(linear_axis_bits_t=linear_bits) { return false; }
FORCE_INLINE void set_axis_unhomed(const AxisEnum axis) {} FORCE_INLINE void set_axis_unhomed(const AxisEnum axis) {}
FORCE_INLINE void set_axis_untrusted(const AxisEnum axis) {} FORCE_INLINE void set_axis_untrusted(const AxisEnum axis) {}
FORCE_INLINE void set_all_unhomed() {} FORCE_INLINE void set_all_unhomed() {}
@ -369,9 +370,9 @@ FORCE_INLINE bool axis_was_homed(const AxisEnum axis) { return TEST(axis_h
FORCE_INLINE bool axis_is_trusted(const AxisEnum axis) { return TEST(axis_trusted, axis); } FORCE_INLINE bool axis_is_trusted(const AxisEnum axis) { return TEST(axis_trusted, axis); }
FORCE_INLINE bool axis_should_home(const AxisEnum axis) { return (axes_should_home() & _BV(axis)) != 0; } FORCE_INLINE bool axis_should_home(const AxisEnum axis) { return (axes_should_home() & _BV(axis)) != 0; }
FORCE_INLINE bool no_axes_homed() { return !axis_homed; } FORCE_INLINE bool no_axes_homed() { return !axis_homed; }
FORCE_INLINE bool all_axes_homed() { return xyz_bits == (axis_homed & xyz_bits); } FORCE_INLINE bool all_axes_homed() { return linear_bits == (axis_homed & linear_bits); }
FORCE_INLINE bool homing_needed() { return !all_axes_homed(); } FORCE_INLINE bool homing_needed() { return !all_axes_homed(); }
FORCE_INLINE bool all_axes_trusted() { return xyz_bits == (axis_trusted & xyz_bits); } FORCE_INLINE bool all_axes_trusted() { return linear_bits == (axis_trusted & linear_bits); }
#if ENABLED(NO_MOTION_BEFORE_HOMING) #if ENABLED(NO_MOTION_BEFORE_HOMING)
#define MOTION_CONDITIONS (IsRunning() && !homing_needed_error()) #define MOTION_CONDITIONS (IsRunning() && !homing_needed_error())

Loading…
Cancel
Save