Browse Source

Refine endstops fixes (#12413)

When endstops/probe are enabled `ENDSTOP_NOISE_THRESHOLD` calls to `update` are required to properly re-sync endstops/probe status.
Giuliano Zaro 6 years ago
parent
commit
d631267548
2 changed files with 20 additions and 7 deletions
  1. 18
    7
      Marlin/src/module/endstops.cpp
  2. 2
    0
      Marlin/src/module/endstops.h

+ 18
- 7
Marlin/src/module/endstops.cpp View File

@@ -42,7 +42,7 @@
42 42
 
43 43
 Endstops endstops;
44 44
 
45
-// public:
45
+// private:
46 46
 
47 47
 bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
48 48
 volatile uint8_t Endstops::hit_state;
@@ -259,15 +259,13 @@ void Endstops::poll() {
259 259
 
260 260
 void Endstops::enable_globally(const bool onoff) {
261 261
   enabled_globally = enabled = onoff;
262
-
263
-  update();
262
+  resync();
264 263
 }
265 264
 
266 265
 // Enable / disable endstop checking
267 266
 void Endstops::enable(const bool onoff) {
268 267
   enabled = onoff;
269
-
270
-  update();
268
+  resync();
271 269
 }
272 270
 
273 271
 // Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
@@ -287,11 +285,24 @@ void Endstops::not_homing() {
287 285
 #if HAS_BED_PROBE
288 286
   void Endstops::enable_z_probe(const bool onoff) {
289 287
     z_probe_enabled = onoff;
290
-
291
-    update();
288
+    resync();
292 289
   }
293 290
 #endif
294 291
 
292
+// Get the stable endstop states when enabled
293
+void Endstops::resync() {
294
+  if (!abort_enabled()) return;     // If endstops/probes are disabled the loop below can hang
295
+
296
+  #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) && !ENDSTOP_NOISE_THRESHOLD
297
+    update();
298
+  #else
299
+    safe_delay(2);  // Wait for Temperature ISR (runs at 1KHz)
300
+  #endif
301
+  #if ENDSTOP_NOISE_THRESHOLD
302
+    while (endstop_poll_count) safe_delay(1);
303
+  #endif
304
+}
305
+
295 306
 #if ENABLED(PINS_DEBUGGING)
296 307
   void Endstops::run_monitor() {
297 308
     if (!monitor_flag) return;

+ 2
- 0
Marlin/src/module/endstops.h View File

@@ -162,6 +162,8 @@ class Endstops {
162 162
       static void enable_z_probe(const bool onoff=true);
163 163
     #endif
164 164
 
165
+    static void resync();
166
+
165 167
     // Debugging of endstops
166 168
     #if ENABLED(PINS_DEBUGGING)
167 169
       static bool monitor_flag;

Loading…
Cancel
Save