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
 
42
 
43
 Endstops endstops;
43
 Endstops endstops;
44
 
44
 
45
-// public:
45
+// private:
46
 
46
 
47
 bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
47
 bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
48
 volatile uint8_t Endstops::hit_state;
48
 volatile uint8_t Endstops::hit_state;
259
 
259
 
260
 void Endstops::enable_globally(const bool onoff) {
260
 void Endstops::enable_globally(const bool onoff) {
261
   enabled_globally = enabled = onoff;
261
   enabled_globally = enabled = onoff;
262
-
263
-  update();
262
+  resync();
264
 }
263
 }
265
 
264
 
266
 // Enable / disable endstop checking
265
 // Enable / disable endstop checking
267
 void Endstops::enable(const bool onoff) {
266
 void Endstops::enable(const bool onoff) {
268
   enabled = onoff;
267
   enabled = onoff;
269
-
270
-  update();
268
+  resync();
271
 }
269
 }
272
 
270
 
273
 // Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
271
 // Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
287
 #if HAS_BED_PROBE
285
 #if HAS_BED_PROBE
288
   void Endstops::enable_z_probe(const bool onoff) {
286
   void Endstops::enable_z_probe(const bool onoff) {
289
     z_probe_enabled = onoff;
287
     z_probe_enabled = onoff;
290
-
291
-    update();
288
+    resync();
292
   }
289
   }
293
 #endif
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
 #if ENABLED(PINS_DEBUGGING)
306
 #if ENABLED(PINS_DEBUGGING)
296
   void Endstops::run_monitor() {
307
   void Endstops::run_monitor() {
297
     if (!monitor_flag) return;
308
     if (!monitor_flag) return;

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

162
       static void enable_z_probe(const bool onoff=true);
162
       static void enable_z_probe(const bool onoff=true);
163
     #endif
163
     #endif
164
 
164
 
165
+    static void resync();
166
+
165
     // Debugging of endstops
167
     // Debugging of endstops
166
     #if ENABLED(PINS_DEBUGGING)
168
     #if ENABLED(PINS_DEBUGGING)
167
       static bool monitor_flag;
169
       static bool monitor_flag;

Loading…
Cancel
Save