report_state > event_handler
Make the endstop report method track endstop changes on its own.
This commit is contained in:
		@@ -945,7 +945,7 @@ void loop() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (commands_in_queue < BUFSIZE) get_available_commands();
 | 
					    if (commands_in_queue < BUFSIZE) get_available_commands();
 | 
				
			||||||
    advance_command_queue();
 | 
					    advance_command_queue();
 | 
				
			||||||
    endstops.report_state();
 | 
					    endstops.event_handler();
 | 
				
			||||||
    idle();
 | 
					    idle();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -216,7 +216,7 @@ void Endstops::init() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
} // Endstops::init
 | 
					} // Endstops::init
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Called from ISR: Poll endstop state if required
 | 
					// Called at ~1KHz from Temperature ISR: Poll endstop state if required
 | 
				
			||||||
void Endstops::poll() {
 | 
					void Endstops::poll() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  #if ENABLED(PINS_DEBUGGING)
 | 
					  #if ENABLED(PINS_DEBUGGING)
 | 
				
			||||||
@@ -258,8 +258,8 @@ void Endstops::not_homing() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// If the last move failed to trigger an endstop, call kill
 | 
					// If the last move failed to trigger an endstop, call kill
 | 
				
			||||||
void Endstops::validate_homing_move() {
 | 
					void Endstops::validate_homing_move() {
 | 
				
			||||||
  if (!trigger_state()) kill(PSTR(MSG_ERR_HOMING_FAILED));
 | 
					  if (trigger_state()) hit_on_purpose();
 | 
				
			||||||
  hit_on_purpose();
 | 
					  else kill(PSTR(MSG_ERR_HOMING_FAILED));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Enable / disable endstop z-probe checking
 | 
					// Enable / disable endstop z-probe checking
 | 
				
			||||||
@@ -283,8 +283,9 @@ void Endstops::validate_homing_move() {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Endstops::report_state() {
 | 
					void Endstops::event_handler() {
 | 
				
			||||||
  if (hit_state) {
 | 
					  static uint8_t prev_hit_state; // = 0
 | 
				
			||||||
 | 
					  if (hit_state && hit_state != prev_hit_state) {
 | 
				
			||||||
    #if ENABLED(ULTRA_LCD)
 | 
					    #if ENABLED(ULTRA_LCD)
 | 
				
			||||||
      char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
 | 
					      char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
 | 
				
			||||||
      #define _SET_STOP_CHAR(A,C) (chr## A = C)
 | 
					      #define _SET_STOP_CHAR(A,C) (chr## A = C)
 | 
				
			||||||
@@ -320,8 +321,6 @@ void Endstops::report_state() {
 | 
				
			|||||||
      lcd_status_printf_P(0, PSTR(MSG_LCD_ENDSTOPS " %c %c %c %c"), chrX, chrY, chrZ, chrP);
 | 
					      lcd_status_printf_P(0, PSTR(MSG_LCD_ENDSTOPS " %c %c %c %c"), chrX, chrY, chrZ, chrP);
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    hit_on_purpose();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
 | 
					    #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
 | 
				
			||||||
      if (planner.abort_on_endstop_hit) {
 | 
					      if (planner.abort_on_endstop_hit) {
 | 
				
			||||||
        card.sdprinting = false;
 | 
					        card.sdprinting = false;
 | 
				
			||||||
@@ -331,6 +330,7 @@ void Endstops::report_state() {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  prev_hit_state = hit_state;
 | 
				
			||||||
} // Endstops::report_state
 | 
					} // Endstops::report_state
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Endstops::M119() {
 | 
					void Endstops::M119() {
 | 
				
			||||||
@@ -392,7 +392,7 @@ void Endstops::M119() {
 | 
				
			|||||||
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
 | 
					#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
 | 
				
			||||||
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
 | 
					#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Check endstops - Could be called from ISR!
 | 
					// Check endstops - Could be called from Temperature ISR!
 | 
				
			||||||
void Endstops::update() {
 | 
					void Endstops::update() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  #if DISABLED(ENDSTOP_NOISE_FILTER)
 | 
					  #if DISABLED(ENDSTOP_NOISE_FILTER)
 | 
				
			||||||
@@ -567,7 +567,7 @@ void Endstops::update() {
 | 
				
			|||||||
    if (dual_hit) { \
 | 
					    if (dual_hit) { \
 | 
				
			||||||
      _ENDSTOP_HIT(AXIS1, MINMAX); \
 | 
					      _ENDSTOP_HIT(AXIS1, MINMAX); \
 | 
				
			||||||
      /* if not performing home or if both endstops were trigged during homing... */ \
 | 
					      /* if not performing home or if both endstops were trigged during homing... */ \
 | 
				
			||||||
      if (!stepper.homing_dual_axis || dual_hit == 0x3) \
 | 
					      if (!stepper.homing_dual_axis || dual_hit == 0b11) \
 | 
				
			||||||
        planner.endstop_triggered(_AXIS(AXIS1)); \
 | 
					        planner.endstop_triggered(_AXIS(AXIS1)); \
 | 
				
			||||||
    } \
 | 
					    } \
 | 
				
			||||||
  }while(0)
 | 
					  }while(0)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -128,7 +128,7 @@ class Endstops {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Report endstop hits to serial. Called from loop().
 | 
					     * Report endstop hits to serial. Called from loop().
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    static void report_state();
 | 
					    static void event_handler();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Report endstop positions in response to M119
 | 
					     * Report endstop positions in response to M119
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user