|
@@ -34,6 +34,10 @@
|
34
|
34
|
#include "../../module/servo.h"
|
35
|
35
|
#endif
|
36
|
36
|
|
|
37
|
+#if ENABLED(BLTOUCH)
|
|
38
|
+ #include "../../feature/bltouch.h"
|
|
39
|
+#endif
|
|
40
|
+
|
37
|
41
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
38
|
42
|
#include "../../feature/host_actions.h"
|
39
|
43
|
#endif
|
|
@@ -91,122 +95,152 @@ inline void toggle_pins() {
|
91
|
95
|
} // toggle_pins
|
92
|
96
|
|
93
|
97
|
inline void servo_probe_test() {
|
|
98
|
+
|
94
|
99
|
#if !(NUM_SERVOS > 0 && HAS_SERVO_0)
|
95
|
100
|
|
96
|
|
- SERIAL_ERROR_MSG("SERVO not setup");
|
|
101
|
+ SERIAL_ERROR_MSG("SERVO not set up.");
|
97
|
102
|
|
98
|
103
|
#elif !HAS_Z_SERVO_PROBE
|
99
|
104
|
|
100
|
|
- SERIAL_ERROR_MSG("Z_PROBE_SERVO_NR not setup");
|
|
105
|
+ SERIAL_ERROR_MSG("Z_PROBE_SERVO_NR not set up.");
|
101
|
106
|
|
102
|
107
|
#else // HAS_Z_SERVO_PROBE
|
103
|
108
|
|
104
|
109
|
const uint8_t probe_index = parser.byteval('P', Z_PROBE_SERVO_NR);
|
105
|
110
|
|
106
|
|
- SERIAL_ECHOLNPGM("Servo probe test");
|
107
|
|
- SERIAL_ECHOLNPAIR(". using index: ", probe_index);
|
108
|
|
- SERIAL_ECHOLNPAIR(". deploy angle: ", servo_angles[probe_index][0]);
|
109
|
|
- SERIAL_ECHOLNPAIR(". stow angle: ", servo_angles[probe_index][1]);
|
|
111
|
+ SERIAL_ECHOLNPAIR("Servo probe test\n"
|
|
112
|
+ ". using index: ", int(probe_index),
|
|
113
|
+ ", deploy angle: ", servo_angles[probe_index][0],
|
|
114
|
+ ", stow angle: ", servo_angles[probe_index][1]
|
|
115
|
+ );
|
110
|
116
|
|
111
|
|
- bool probe_inverting;
|
|
117
|
+ bool deploy_state, stow_state;
|
112
|
118
|
|
113
|
119
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
114
|
120
|
|
115
|
121
|
#define PROBE_TEST_PIN Z_MIN_PIN
|
|
122
|
+ constexpr bool probe_inverting = Z_MIN_ENDSTOP_INVERTING;
|
116
|
123
|
|
117
|
|
- SERIAL_ECHOLNPAIR(". probe uses Z_MIN pin: ", PROBE_TEST_PIN);
|
118
|
|
- SERIAL_ECHOLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)");
|
|
124
|
+ SERIAL_ECHOLNPAIR(". Probe Z_MIN_PIN: ", int(PROBE_TEST_PIN));
|
119
|
125
|
SERIAL_ECHOPGM(". Z_MIN_ENDSTOP_INVERTING: ");
|
120
|
126
|
|
121
|
|
- #if Z_MIN_ENDSTOP_INVERTING
|
122
|
|
- SERIAL_ECHOLNPGM("true");
|
123
|
|
- #else
|
124
|
|
- SERIAL_ECHOLNPGM("false");
|
125
|
|
- #endif
|
126
|
|
-
|
127
|
|
- probe_inverting = Z_MIN_ENDSTOP_INVERTING;
|
128
|
|
-
|
129
|
|
- #elif USES_Z_MIN_PROBE_ENDSTOP
|
|
127
|
+ #else
|
130
|
128
|
|
131
|
129
|
#define PROBE_TEST_PIN Z_MIN_PROBE_PIN
|
132
|
|
- SERIAL_ECHOLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN);
|
133
|
|
- SERIAL_ECHOLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)");
|
134
|
|
- SERIAL_ECHOPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
|
135
|
|
-
|
136
|
|
- #if Z_MIN_PROBE_ENDSTOP_INVERTING
|
137
|
|
- SERIAL_ECHOLNPGM("true");
|
138
|
|
- #else
|
139
|
|
- SERIAL_ECHOLNPGM("false");
|
140
|
|
- #endif
|
|
130
|
+ constexpr bool probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
|
141
|
131
|
|
142
|
|
- probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
|
|
132
|
+ SERIAL_ECHOLNPAIR(". Probe Z_MIN_PROBE_PIN: ", int(PROBE_TEST_PIN));
|
|
133
|
+ SERIAL_ECHOPGM( ". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
|
143
|
134
|
|
144
|
135
|
#endif
|
145
|
136
|
|
146
|
|
- SERIAL_ECHOLNPGM(". deploy & stow 4 times");
|
|
137
|
+ serialprint_truefalse(probe_inverting);
|
|
138
|
+ SERIAL_EOL();
|
|
139
|
+
|
147
|
140
|
SET_INPUT_PULLUP(PROBE_TEST_PIN);
|
148
|
|
- uint8_t i = 0;
|
149
|
|
- bool deploy_state, stow_state;
|
150
|
|
- do {
|
151
|
|
- MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
152
|
|
- safe_delay(500);
|
153
|
|
- deploy_state = READ(PROBE_TEST_PIN);
|
154
|
|
- MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
155
|
|
- safe_delay(500);
|
156
|
|
- stow_state = READ(PROBE_TEST_PIN);
|
157
|
|
- } while (++i < 4);
|
158
|
|
- if (probe_inverting != deploy_state) SERIAL_ECHOLNPGM("WARNING - INVERTING setting probably backwards");
|
159
|
|
-
|
160
|
|
- if (deploy_state != stow_state) {
|
161
|
|
- SERIAL_ECHOLNPGM("BLTouch clone detected");
|
162
|
|
- if (deploy_state) {
|
163
|
|
- SERIAL_ECHOLNPGM(". DEPLOYED state: HIGH (logic 1)");
|
164
|
|
- SERIAL_ECHOLNPGM(". STOWED (triggered) state: LOW (logic 0)");
|
165
|
|
- }
|
166
|
|
- else {
|
167
|
|
- SERIAL_ECHOLNPGM(". DEPLOYED state: LOW (logic 0)");
|
168
|
|
- SERIAL_ECHOLNPGM(". STOWED (triggered) state: HIGH (logic 1)");
|
|
141
|
+
|
|
142
|
+ // First, check for a probe that recognizes an advanced BLTouch sequence.
|
|
143
|
+ // In addition to STOW and DEPLOY, it uses SW MODE (and RESET in the beginning)
|
|
144
|
+ // to see if this is one of the following: BLTOUCH Classic 1.2, 1.3, or
|
|
145
|
+ // BLTouch Smart 1.0, 2.0, 2.2, 3.0, 3.1. But only if the user has actually
|
|
146
|
+ // configured a BLTouch as being present. If the user has not configured this,
|
|
147
|
+ // the BLTouch will be detected in the last phase of these tests (see further on).
|
|
148
|
+ bool blt = false;
|
|
149
|
+ // This code will try to detect a BLTouch probe or clone
|
|
150
|
+ #if ENABLED(BLTOUCH)
|
|
151
|
+ SERIAL_ECHOLNPGM(". Check for BLTOUCH");
|
|
152
|
+ bltouch._reset();
|
|
153
|
+ bltouch._stow();
|
|
154
|
+ if (probe_inverting == READ(PROBE_TEST_PIN)) {
|
|
155
|
+ bltouch._set_SW_mode();
|
|
156
|
+ if (probe_inverting != READ(PROBE_TEST_PIN)) {
|
|
157
|
+ bltouch._deploy();
|
|
158
|
+ if (probe_inverting == READ(PROBE_TEST_PIN)) {
|
|
159
|
+ bltouch._stow();
|
|
160
|
+ SERIAL_ECHOLNPGM("= BLTouch Classic 1.2, 1.3, Smart 1.0, 2.0, 2.2, 3.0, 3.1 detected.");
|
|
161
|
+ // Check for a 3.1 by letting the user trigger it, later
|
|
162
|
+ blt = true;
|
|
163
|
+ }
|
169
|
164
|
}
|
170
|
|
- #if ENABLED(BLTOUCH)
|
171
|
|
- SERIAL_ECHOLNPGM("ERROR: BLTOUCH enabled - set this device up as a Z Servo Probe with inverting as true.");
|
172
|
|
- #endif
|
173
|
165
|
}
|
174
|
|
- else { // measure active signal length
|
175
|
|
- MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
176
|
|
- safe_delay(500);
|
177
|
|
- SERIAL_ECHOLNPGM("please trigger probe");
|
178
|
|
- uint16_t probe_counter = 0;
|
179
|
|
-
|
180
|
|
- // Allow 30 seconds max for operator to trigger probe
|
181
|
|
- for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) {
|
182
|
|
-
|
183
|
|
- safe_delay(2);
|
184
|
|
-
|
185
|
|
- if (0 == j % (500 * 1)) gcode.reset_stepper_timeout(); // Keep steppers powered
|
186
|
|
-
|
187
|
|
- if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered
|
188
|
|
-
|
189
|
|
- for (probe_counter = 1; probe_counter < 50 && deploy_state != READ(PROBE_TEST_PIN); ++probe_counter)
|
190
|
|
- safe_delay(2);
|
191
|
|
-
|
192
|
|
- if (probe_counter == 50)
|
193
|
|
- SERIAL_ECHOLNPGM("Z Servo Probe detected"); // >= 100mS active time
|
194
|
|
- else if (probe_counter >= 2)
|
195
|
|
- SERIAL_ECHOLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2); // allow 4 - 100mS pulse
|
196
|
|
- else
|
197
|
|
- SERIAL_ECHOLNPGM("noise detected - please re-run test"); // less than 2mS pulse
|
198
|
|
-
|
199
|
|
- MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
|
166
|
+ #endif
|
200
|
167
|
|
201
|
|
- } // pulse detected
|
|
168
|
+ // The following code is common to all kinds of servo probes.
|
|
169
|
+ // Since it could be a real servo or a BLTouch (any kind) or a clone,
|
|
170
|
+ // use only "common" functions - i.e. SERVO_MOVE. No bltouch.xxxx stuff.
|
|
171
|
+
|
|
172
|
+ // If it is already recognised as a being a BLTouch, no need for this test
|
|
173
|
+ if (!blt) {
|
|
174
|
+ // DEPLOY and STOW 4 times and see if the signal follows
|
|
175
|
+ // Then it is a mechanical switch
|
|
176
|
+ uint8_t i = 0;
|
|
177
|
+ SERIAL_ECHOLNPGM(". Deploy & stow 4 times");
|
|
178
|
+ do {
|
|
179
|
+ MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
|
180
|
+ safe_delay(500);
|
|
181
|
+ deploy_state = READ(PROBE_TEST_PIN);
|
|
182
|
+ MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
|
183
|
+ safe_delay(500);
|
|
184
|
+ stow_state = READ(PROBE_TEST_PIN);
|
|
185
|
+ } while (++i < 4);
|
|
186
|
+
|
|
187
|
+ if (probe_inverting != deploy_state) SERIAL_ECHOLNPGM("WARNING: INVERTING setting probably backwards.");
|
|
188
|
+
|
|
189
|
+ if (deploy_state != stow_state) {
|
|
190
|
+ SERIAL_ECHOLNPGM("= Mechanical Switch detected");
|
|
191
|
+ if (deploy_state) {
|
|
192
|
+ SERIAL_ECHOLNPAIR(" DEPLOYED state: HIGH (logic 1)",
|
|
193
|
+ " STOWED (triggered) state: LOW (logic 0)");
|
|
194
|
+ }
|
|
195
|
+ else {
|
|
196
|
+ SERIAL_ECHOLNPAIR(" DEPLOYED state: LOW (logic 0)",
|
|
197
|
+ " STOWED (triggered) state: HIGH (logic 1)");
|
|
198
|
+ }
|
|
199
|
+ #if ENABLED(BLTOUCH)
|
|
200
|
+ SERIAL_ECHOLNPGM("FAIL: BLTOUCH enabled - Set up this device as a Servo Probe with INVERTING set to 'true'.");
|
|
201
|
+ #endif
|
|
202
|
+ return;
|
|
203
|
+ }
|
|
204
|
+ }
|
202
|
205
|
|
203
|
|
- } // for loop waiting for trigger
|
|
206
|
+ // Ask the user for a trigger event and measure the pulse width.
|
|
207
|
+ MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
|
208
|
+ safe_delay(500);
|
|
209
|
+ SERIAL_ECHOLNPGM("** Please trigger probe within 30 sec **");
|
|
210
|
+ uint16_t probe_counter = 0;
|
|
211
|
+
|
|
212
|
+ // Wait 30 seconds for user to trigger probe
|
|
213
|
+ for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) {
|
|
214
|
+ safe_delay(2);
|
|
215
|
+
|
|
216
|
+ if (0 == j % (500 * 1)) gcode.reset_stepper_timeout(); // Keep steppers powered
|
|
217
|
+
|
|
218
|
+ if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered
|
|
219
|
+ for (probe_counter = 0; probe_counter < 15 && deploy_state != READ(PROBE_TEST_PIN); ++probe_counter) safe_delay(2);
|
|
220
|
+
|
|
221
|
+ if (probe_counter = 15)
|
|
222
|
+ SERIAL_ECHOLNPGM(". Pulse width: 30ms or more");
|
|
223
|
+ else
|
|
224
|
+ SERIAL_ECHOLNPAIR(". Pulse width (+/- 4ms): ", probe_counter * 2);
|
|
225
|
+
|
|
226
|
+ if (probe_counter >= 4) {
|
|
227
|
+ if (probe_counter == 15) {
|
|
228
|
+ if (blt) SERIAL_ECHOPGM("= BLTouch V3.1");
|
|
229
|
+ else SERIAL_ECHOPGM("= Z Servo Probe");
|
|
230
|
+ }
|
|
231
|
+ else SERIAL_ECHOPGM("= BLTouch pre V3.1 or compatible probe");
|
|
232
|
+ SERIAL_ECHOLNPGM(" detected.");
|
|
233
|
+ }
|
|
234
|
+ else SERIAL_ECHOLNPGM("FAIL: Noise detected - please re-run test");
|
204
|
235
|
|
205
|
|
- if (probe_counter == 0) SERIAL_ECHOLNPGM("trigger not detected");
|
|
236
|
+ MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
|
237
|
+ return;
|
|
238
|
+ }
|
|
239
|
+ }
|
206
|
240
|
|
207
|
|
- } // measure active signal length
|
|
241
|
+ if (!probe_counter) SERIAL_ECHOLNPGM("FAIL: Trigger not detected");
|
208
|
242
|
|
209
|
|
- #endif
|
|
243
|
+ #endif // HAS_Z_SERVO_PROBE
|
210
|
244
|
|
211
|
245
|
} // servo_probe_test
|
212
|
246
|
|
|
@@ -239,12 +273,10 @@ inline void servo_probe_test() {
|
239
|
273
|
*/
|
240
|
274
|
void GcodeSuite::M43() {
|
241
|
275
|
|
242
|
|
- if (parser.seen('T')) { // must be first or else its "S" and "E" parameters will execute endstop or servo test
|
243
|
|
- toggle_pins();
|
244
|
|
- return;
|
245
|
|
- }
|
|
276
|
+ // 'T' must be first. It uses 'S' and 'E' differently.
|
|
277
|
+ if (parser.seen('T')) return toggle_pins();
|
246
|
278
|
|
247
|
|
- // Enable or disable endstop monitoring
|
|
279
|
+ // 'E' Enable or disable endstop monitoring and return
|
248
|
280
|
if (parser.seen('E')) {
|
249
|
281
|
endstops.monitor_flag = parser.value_bool();
|
250
|
282
|
SERIAL_ECHOPGM("endstop monitor ");
|
|
@@ -253,25 +285,23 @@ void GcodeSuite::M43() {
|
253
|
285
|
return;
|
254
|
286
|
}
|
255
|
287
|
|
256
|
|
- if (parser.seen('S')) {
|
257
|
|
- servo_probe_test();
|
258
|
|
- return;
|
259
|
|
- }
|
|
288
|
+ // 'S' Run servo probe test and return
|
|
289
|
+ if (parser.seen('S')) return servo_probe_test();
|
260
|
290
|
|
261
|
|
- // Get the range of pins to test or watch
|
|
291
|
+ // 'P' Get the range of pins to test or watch
|
262
|
292
|
uint8_t first_pin = PARSED_PIN_INDEX('P', 0),
|
263
|
293
|
last_pin = parser.seenval('P') ? first_pin : NUMBER_PINS_TOTAL - 1;
|
264
|
294
|
|
265
|
295
|
if (first_pin > last_pin) return;
|
266
|
296
|
|
|
297
|
+ // 'I' to ignore protected pins
|
267
|
298
|
const bool ignore_protection = parser.boolval('I');
|
268
|
299
|
|
269
|
|
- // Watch until click, M108, or reset
|
|
300
|
+ // 'W' Watch until click, M108, or reset
|
270
|
301
|
if (parser.boolval('W')) {
|
271
|
302
|
SERIAL_ECHOLNPGM("Watching pins");
|
272
|
|
-
|
273
|
303
|
#ifdef ARDUINO_ARCH_SAM
|
274
|
|
- NOLESS(first_pin, 2); // don't hijack the UART pins
|
|
304
|
+ NOLESS(first_pin, 2); // Don't hijack the UART pins
|
275
|
305
|
#endif
|
276
|
306
|
uint8_t pin_state[last_pin - first_pin + 1];
|
277
|
307
|
for (uint8_t i = first_pin; i <= last_pin; i++) {
|
|
@@ -280,11 +310,11 @@ void GcodeSuite::M43() {
|
280
|
310
|
if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
|
281
|
311
|
pinMode(pin, INPUT_PULLUP);
|
282
|
312
|
delay(1);
|
283
|
|
- /*
|
|
313
|
+ /*
|
284
|
314
|
if (IS_ANALOG(pin))
|
285
|
315
|
pin_state[pin - first_pin] = analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)); // int16_t pin_state[...]
|
286
|
316
|
else
|
287
|
|
- //*/
|
|
317
|
+ //*/
|
288
|
318
|
pin_state[i - first_pin] = extDigitalRead(pin);
|
289
|
319
|
}
|
290
|
320
|
|
|
@@ -303,9 +333,9 @@ void GcodeSuite::M43() {
|
303
|
333
|
if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
|
304
|
334
|
const byte val =
|
305
|
335
|
/*
|
306
|
|
- IS_ANALOG(pin)
|
307
|
|
- ? analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)) : // int16_t val
|
308
|
|
- :
|
|
336
|
+ IS_ANALOG(pin)
|
|
337
|
+ ? analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)) : // int16_t val
|
|
338
|
+ :
|
309
|
339
|
//*/
|
310
|
340
|
extDigitalRead(pin);
|
311
|
341
|
if (val != pin_state[i - first_pin]) {
|
|
@@ -315,21 +345,18 @@ void GcodeSuite::M43() {
|
315
|
345
|
}
|
316
|
346
|
|
317
|
347
|
#if HAS_RESUME_CONTINUE
|
318
|
|
- if (!wait_for_user) {
|
319
|
|
- KEEPALIVE_STATE(IN_HANDLER);
|
320
|
|
- break;
|
321
|
|
- }
|
|
348
|
+ if (!wait_for_user) { KEEPALIVE_STATE(IN_HANDLER); break; }
|
322
|
349
|
#endif
|
323
|
350
|
|
324
|
351
|
safe_delay(200);
|
325
|
352
|
}
|
326
|
|
- return;
|
327
|
353
|
}
|
328
|
|
-
|
329
|
|
- // Report current state of selected pin(s)
|
330
|
|
- for (uint8_t i = first_pin; i <= last_pin; i++) {
|
331
|
|
- pin_t pin = GET_PIN_MAP_PIN(i);
|
332
|
|
- if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true);
|
|
354
|
+ else {
|
|
355
|
+ // Report current state of selected pin(s)
|
|
356
|
+ for (uint8_t i = first_pin; i <= last_pin; i++) {
|
|
357
|
+ pin_t pin = GET_PIN_MAP_PIN(i);
|
|
358
|
+ if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true);
|
|
359
|
+ }
|
333
|
360
|
}
|
334
|
361
|
}
|
335
|
362
|
|