@@ -87,6 +87,11 @@ Endstops::endstop_mask_t Endstops::live_state = 0;
87
87
volatile bool Endstops::z_probe_enabled = false ;
88
88
#endif
89
89
90
+ #if ENABLED(CALIBRATION_GCODE)
91
+ volatile bool Endstops::calibration_probe_enabled = false ;
92
+ volatile bool Endstops::calibration_stop_state;
93
+ #endif
94
+
90
95
// Initialized by settings.load()
91
96
#if ENABLED(X_DUAL_ENDSTOPS)
92
97
float Endstops::x2_endstop_adj;
@@ -203,7 +208,7 @@ void Endstops::init() {
203
208
_INIT_ENDSTOP (MAX,W,);
204
209
#endif
205
210
206
- #if PIN_EXISTS(CALIBRATION)
211
+ #if USE_CALIBRATION
207
212
#if ENABLED(CALIBRATION_PIN_PULLUP)
208
213
SET_INPUT_PULLUP (CALIBRATION_PIN);
209
214
#elif ENABLED(CALIBRATION_PIN_PULLDOWN)
@@ -283,6 +288,17 @@ void Endstops::not_homing() {
283
288
}
284
289
#endif
285
290
291
+ // Enable / disable calibration probe checking
292
+ #if ENABLED(CALIBRATION_GCODE)
293
+ void Endstops::enable_calibration_probe (const bool onoff, const bool stop_state) {
294
+ // Avoid race condition by setting stop state first
295
+ if (onoff) calibration_stop_state = stop_state;
296
+ calibration_probe_enabled = onoff;
297
+
298
+ resync ();
299
+ }
300
+ #endif
301
+
286
302
// Get the stable endstop states when enabled
287
303
void Endstops::resync () {
288
304
if (!abort_enabled ()) return ; // If endstops/probes are disabled the loop below can hang
@@ -485,6 +501,9 @@ void __O2 Endstops::report_states() {
485
501
#if USE_Z_MIN_PROBE
486
502
print_es_state (PROBE_TRIGGERED (), F (STR_Z_PROBE));
487
503
#endif
504
+ #if USE_CALIBRATION
505
+ print_es_state (READ (CALIBRATION_PIN) != CALIBRATION_PIN_INVERTING, F (STR_CALIBRATION));
506
+ #endif
488
507
#if MULTI_FILAMENT_SENSOR
489
508
#define _CASE_RUNOUT (N ) case N: pin = FIL_RUNOUT##N##_PIN; state = FIL_RUNOUT##N##_STATE; break ;
490
509
for (uint8_t i = 1 ; i <= NUM_RUNOUT_SENSORS; ++i) {
@@ -530,6 +549,16 @@ void Endstops::update() {
530
549
if (G38_move) UPDATE_LIVE_STATE (Z, TERN (USE_Z_MIN_PROBE, MIN_PROBE, MIN));
531
550
#endif
532
551
552
+ #if ENABLED(CALIBRATION_GCODE)
553
+ if (calibration_probe_enabled) {
554
+ #if HAS_CALIBRATION_STATE
555
+ SET_BIT_TO (live_state, CALIBRATION, READ (CALIBRATION_PIN) != CALIBRATION_PIN_INVERTING);
556
+ #else
557
+ UPDATE_LIVE_STATE (Z, TERN (USE_Z_MIN_PROBE, MIN_PROBE, MIN));
558
+ #endif
559
+ }
560
+ #endif
561
+
533
562
// With Dual X, endstops are only checked in the homing direction for the active extruder
534
563
#define X_MIN_TEST () TERN1(DUAL_X_CARRIAGE, stepper.last_moved_extruder == 0 ) // Check min for the left carriage
535
564
#define X_MAX_TEST () TERN1(DUAL_X_CARRIAGE, stepper.last_moved_extruder != 0 ) // Check max for the right carriage
@@ -797,6 +826,15 @@ void Endstops::update() {
797
826
}
798
827
#endif
799
828
829
+ #if ENABLED(CALIBRATION_GCODE)
830
+ if (calibration_probe_enabled) {
831
+ #if HAS_CALIBRATION_STATE
832
+ if (TEST (live_state, CALIBRATION) == calibration_stop_state) stepper.quick_stop ();
833
+ #else
834
+ if (TEST (live_state, Z_MIN_PROBE) == calibration_stop_state) stepper.quick_stop ();
835
+ #endif
836
+ }
837
+ #endif
800
838
// Signal, after validation, if an endstop limit is pressed or not
801
839
802
840
bool moving_neg;
@@ -1173,6 +1211,9 @@ void Endstops::update() {
1173
1211
#if USE_Z_MIN_PROBE
1174
1212
ES_GET_STATE (Z_MIN_PROBE);
1175
1213
#endif
1214
+ #if USE_CALIBRATION
1215
+ ES_GET_STATE (CALIBRATION);
1216
+ #endif
1176
1217
#if USE_X2_MIN
1177
1218
ES_GET_STATE (X2_MIN);
1178
1219
#endif
@@ -1265,6 +1306,9 @@ void Endstops::update() {
1265
1306
#if USE_Z_MIN_PROBE
1266
1307
ES_REPORT_CHANGE (Z_MIN_PROBE);
1267
1308
#endif
1309
+ #if USE_CALIBRATION
1310
+ ES_REPORT_STATE (CALIBRATION);
1311
+ #endif
1268
1312
#if USE_X2_MIN
1269
1313
ES_REPORT_CHANGE (X2_MIN);
1270
1314
#endif
0 commit comments