Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions Marlin/src/module/endstops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

Endstops endstops;

// public:
// private:

bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
volatile uint8_t Endstops::hit_state;
Expand Down Expand Up @@ -259,15 +259,13 @@ void Endstops::poll() {

void Endstops::enable_globally(const bool onoff) {
enabled_globally = enabled = onoff;

update();
resync();
}

// Enable / disable endstop checking
void Endstops::enable(const bool onoff) {
enabled = onoff;

update();
resync();
}

// Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
Expand All @@ -287,11 +285,24 @@ void Endstops::not_homing() {
#if HAS_BED_PROBE
void Endstops::enable_z_probe(const bool onoff) {
z_probe_enabled = onoff;

update();
resync();
}
#endif

// Get the stable endstop states when enabled
void Endstops::resync() {
if (!abort_enabled()) return; // If endstops/probes are disabled the loop below can hang

#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) && !ENDSTOP_NOISE_THRESHOLD
update();
#else
safe_delay(2); // Wait for Temperature ISR (runs at 1KHz)
#endif
#if ENDSTOP_NOISE_THRESHOLD
while (endstop_poll_count) safe_delay(1);
#endif
}

#if ENABLED(PINS_DEBUGGING)
void Endstops::run_monitor() {
if (!monitor_flag) return;
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/module/endstops.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class Endstops {
static void enable_z_probe(const bool onoff=true);
#endif

static void resync();

// Debugging of endstops
#if ENABLED(PINS_DEBUGGING)
static bool monitor_flag;
Expand Down