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
 
945
 
946
     if (commands_in_queue < BUFSIZE) get_available_commands();
946
     if (commands_in_queue < BUFSIZE) get_available_commands();
947
     advance_command_queue();
947
     advance_command_queue();
948
-    endstops.report_state();
948
+    endstops.event_handler();
949
     idle();
949
     idle();
950
   }
950
   }
951
 }
951
 }

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

216
 
216
 
217
 } // Endstops::init
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
 void Endstops::poll() {
220
 void Endstops::poll() {
221
 
221
 
222
   #if ENABLED(PINS_DEBUGGING)
222
   #if ENABLED(PINS_DEBUGGING)
258
 
258
 
259
 // If the last move failed to trigger an endstop, call kill
259
 // If the last move failed to trigger an endstop, call kill
260
 void Endstops::validate_homing_move() {
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
 // Enable / disable endstop z-probe checking
265
 // Enable / disable endstop z-probe checking
283
   }
283
   }
284
 #endif
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
     #if ENABLED(ULTRA_LCD)
289
     #if ENABLED(ULTRA_LCD)
289
       char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
290
       char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
290
       #define _SET_STOP_CHAR(A,C) (chr## A = C)
291
       #define _SET_STOP_CHAR(A,C) (chr## A = C)
320
       lcd_status_printf_P(0, PSTR(MSG_LCD_ENDSTOPS " %c %c %c %c"), chrX, chrY, chrZ, chrP);
321
       lcd_status_printf_P(0, PSTR(MSG_LCD_ENDSTOPS " %c %c %c %c"), chrX, chrY, chrZ, chrP);
321
     #endif
322
     #endif
322
 
323
 
323
-    hit_on_purpose();
324
-
325
     #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
324
     #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
326
       if (planner.abort_on_endstop_hit) {
325
       if (planner.abort_on_endstop_hit) {
327
         card.sdprinting = false;
326
         card.sdprinting = false;
331
       }
330
       }
332
     #endif
331
     #endif
333
   }
332
   }
333
+  prev_hit_state = hit_state;
334
 } // Endstops::report_state
334
 } // Endstops::report_state
335
 
335
 
336
 void Endstops::M119() {
336
 void Endstops::M119() {
392
 #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
392
 #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
393
 #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
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
 void Endstops::update() {
396
 void Endstops::update() {
397
 
397
 
398
   #if DISABLED(ENDSTOP_NOISE_FILTER)
398
   #if DISABLED(ENDSTOP_NOISE_FILTER)
567
     if (dual_hit) { \
567
     if (dual_hit) { \
568
       _ENDSTOP_HIT(AXIS1, MINMAX); \
568
       _ENDSTOP_HIT(AXIS1, MINMAX); \
569
       /* if not performing home or if both endstops were trigged during homing... */ \
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
         planner.endstop_triggered(_AXIS(AXIS1)); \
571
         planner.endstop_triggered(_AXIS(AXIS1)); \
572
     } \
572
     } \
573
   }while(0)
573
   }while(0)

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

128
     /**
128
     /**
129
      * Report endstop hits to serial. Called from loop().
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
      * Report endstop positions in response to M119
134
      * Report endstop positions in response to M119

Loading…
Cancel
Save