Browse Source

report_state > event_handler

Make the endstop report method track endstop changes on its own.
Scott Lahteine 6 years ago
parent
commit
566d05006d
3 changed files with 11 additions and 11 deletions
  1. 1
    1
      Marlin/src/Marlin.cpp
  2. 9
    9
      Marlin/src/module/endstops.cpp
  3. 1
    1
      Marlin/src/module/endstops.h

+ 1
- 1
Marlin/src/Marlin.cpp View File

@@ -945,7 +945,7 @@ void loop() {
945 945
 
946 946
     if (commands_in_queue < BUFSIZE) get_available_commands();
947 947
     advance_command_queue();
948
-    endstops.report_state();
948
+    endstops.event_handler();
949 949
     idle();
950 950
   }
951 951
 }

+ 9
- 9
Marlin/src/module/endstops.cpp View File

@@ -216,7 +216,7 @@ void Endstops::init() {
216 216
 
217 217
 } // Endstops::init
218 218
 
219
-// Called from ISR: Poll endstop state if required
219
+// Called at ~1KHz from Temperature ISR: Poll endstop state if required
220 220
 void Endstops::poll() {
221 221
 
222 222
   #if ENABLED(PINS_DEBUGGING)
@@ -258,8 +258,8 @@ void Endstops::not_homing() {
258 258
 
259 259
 // If the last move failed to trigger an endstop, call kill
260 260
 void Endstops::validate_homing_move() {
261
-  if (!trigger_state()) kill(PSTR(MSG_ERR_HOMING_FAILED));
262
-  hit_on_purpose();
261
+  if (trigger_state()) hit_on_purpose();
262
+  else kill(PSTR(MSG_ERR_HOMING_FAILED));
263 263
 }
264 264
 
265 265
 // Enable / disable endstop z-probe checking
@@ -283,8 +283,9 @@ void Endstops::validate_homing_move() {
283 283
   }
284 284
 #endif
285 285
 
286
-void Endstops::report_state() {
287
-  if (hit_state) {
286
+void Endstops::event_handler() {
287
+  static uint8_t prev_hit_state; // = 0
288
+  if (hit_state && hit_state != prev_hit_state) {
288 289
     #if ENABLED(ULTRA_LCD)
289 290
       char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
290 291
       #define _SET_STOP_CHAR(A,C) (chr## A = C)
@@ -320,8 +321,6 @@ void Endstops::report_state() {
320 321
       lcd_status_printf_P(0, PSTR(MSG_LCD_ENDSTOPS " %c %c %c %c"), chrX, chrY, chrZ, chrP);
321 322
     #endif
322 323
 
323
-    hit_on_purpose();
324
-
325 324
     #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
326 325
       if (planner.abort_on_endstop_hit) {
327 326
         card.sdprinting = false;
@@ -331,6 +330,7 @@ void Endstops::report_state() {
331 330
       }
332 331
     #endif
333 332
   }
333
+  prev_hit_state = hit_state;
334 334
 } // Endstops::report_state
335 335
 
336 336
 void Endstops::M119() {
@@ -392,7 +392,7 @@ void Endstops::M119() {
392 392
 #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
393 393
 #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
394 394
 
395
-// Check endstops - Could be called from ISR!
395
+// Check endstops - Could be called from Temperature ISR!
396 396
 void Endstops::update() {
397 397
 
398 398
   #if DISABLED(ENDSTOP_NOISE_FILTER)
@@ -567,7 +567,7 @@ void Endstops::update() {
567 567
     if (dual_hit) { \
568 568
       _ENDSTOP_HIT(AXIS1, MINMAX); \
569 569
       /* if not performing home or if both endstops were trigged during homing... */ \
570
-      if (!stepper.homing_dual_axis || dual_hit == 0x3) \
570
+      if (!stepper.homing_dual_axis || dual_hit == 0b11) \
571 571
         planner.endstop_triggered(_AXIS(AXIS1)); \
572 572
     } \
573 573
   }while(0)

+ 1
- 1
Marlin/src/module/endstops.h View File

@@ -128,7 +128,7 @@ class Endstops {
128 128
     /**
129 129
      * Report endstop hits to serial. Called from loop().
130 130
      */
131
-    static void report_state();
131
+    static void event_handler();
132 132
 
133 133
     /**
134 134
      * Report endstop positions in response to M119

Loading…
Cancel
Save