2017-09-06 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-16 09:06:28 +00:00
|
|
|
#include "../../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(PINS_DEBUGGING)
|
2017-09-08 03:33:16 +00:00
|
|
|
|
2017-09-16 09:06:28 +00:00
|
|
|
#include "../gcode.h"
|
|
|
|
#include "../../Marlin.h" // for pin_is_protected
|
2017-09-06 11:28:31 +00:00
|
|
|
#include "../../pins/pinsDebug.h"
|
2017-09-16 09:06:28 +00:00
|
|
|
#include "../../module/endstops.h"
|
|
|
|
|
2018-04-02 04:54:12 +00:00
|
|
|
#if HAS_Z_SERVO_PROBE
|
2017-09-16 09:06:28 +00:00
|
|
|
#include "../../module/probe.h"
|
2017-11-19 19:39:46 +00:00
|
|
|
#include "../../module/servo.h"
|
2017-09-16 09:06:28 +00:00
|
|
|
#endif
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
inline void toggle_pins() {
|
2018-06-10 22:45:39 +00:00
|
|
|
const bool ignore_protection = parser.boolval('I');
|
2017-09-06 11:28:31 +00:00
|
|
|
const int repeat = parser.intval('R', 1),
|
2017-10-26 18:37:26 +00:00
|
|
|
start = PARSED_PIN_INDEX('S', 0),
|
2018-11-05 03:24:56 +00:00
|
|
|
end = PARSED_PIN_INDEX('L', NUM_DIGITAL_PINS - 1),
|
2017-09-06 11:28:31 +00:00
|
|
|
wait = parser.intval('W', 500);
|
|
|
|
|
2017-10-26 18:37:26 +00:00
|
|
|
for (uint8_t i = start; i <= end; i++) {
|
|
|
|
pin_t pin = GET_PIN_MAP_PIN(i);
|
2018-06-10 22:45:39 +00:00
|
|
|
//report_pin_state_extended(pin, ignore_protection, false);
|
2017-09-06 11:28:31 +00:00
|
|
|
if (!VALID_PIN(pin)) continue;
|
2018-06-10 22:45:39 +00:00
|
|
|
if (!ignore_protection && pin_is_protected(pin)) {
|
|
|
|
report_pin_state_extended(pin, ignore_protection, true, "Untouched ");
|
2017-09-06 11:28:31 +00:00
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
else {
|
2018-06-10 22:45:39 +00:00
|
|
|
report_pin_state_extended(pin, ignore_protection, true, "Pulsing ");
|
2017-09-06 11:28:31 +00:00
|
|
|
#if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
|
|
|
|
if (pin == TEENSY_E2) {
|
|
|
|
SET_OUTPUT(TEENSY_E2);
|
|
|
|
for (int16_t j = 0; j < repeat; j++) {
|
|
|
|
WRITE(TEENSY_E2, LOW); safe_delay(wait);
|
|
|
|
WRITE(TEENSY_E2, HIGH); safe_delay(wait);
|
|
|
|
WRITE(TEENSY_E2, LOW); safe_delay(wait);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pin == TEENSY_E3) {
|
|
|
|
SET_OUTPUT(TEENSY_E3);
|
|
|
|
for (int16_t j = 0; j < repeat; j++) {
|
|
|
|
WRITE(TEENSY_E3, LOW); safe_delay(wait);
|
|
|
|
WRITE(TEENSY_E3, HIGH); safe_delay(wait);
|
|
|
|
WRITE(TEENSY_E3, LOW); safe_delay(wait);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
pinMode(pin, OUTPUT);
|
|
|
|
for (int16_t j = 0; j < repeat; j++) {
|
|
|
|
digitalWrite(pin, 0); safe_delay(wait);
|
|
|
|
digitalWrite(pin, 1); safe_delay(wait);
|
|
|
|
digitalWrite(pin, 0); safe_delay(wait);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
SERIAL_ECHOLNPGM("Done.");
|
|
|
|
|
|
|
|
} // toggle_pins
|
|
|
|
|
|
|
|
inline void servo_probe_test() {
|
|
|
|
#if !(NUM_SERVOS > 0 && HAS_SERVO_0)
|
|
|
|
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ERROR_MSG("SERVO not setup");
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2018-04-02 04:54:12 +00:00
|
|
|
#elif !HAS_Z_SERVO_PROBE
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ERROR_MSG("Z_PROBE_SERVO_NR not setup");
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2018-04-02 04:54:12 +00:00
|
|
|
#else // HAS_Z_SERVO_PROBE
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2018-04-02 04:54:12 +00:00
|
|
|
const uint8_t probe_index = parser.byteval('P', Z_PROBE_SERVO_NR);
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("Servo probe test");
|
|
|
|
SERIAL_ECHOLNPAIR(". using index: ", probe_index);
|
|
|
|
SERIAL_ECHOLNPAIR(". deploy angle: ", servo_angles[probe_index][0]);
|
|
|
|
SERIAL_ECHOLNPAIR(". stow angle: ", servo_angles[probe_index][1]);
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
bool probe_inverting;
|
|
|
|
|
|
|
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
|
|
|
|
|
|
|
#define PROBE_TEST_PIN Z_MIN_PIN
|
|
|
|
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPAIR(". probe uses Z_MIN pin: ", PROBE_TEST_PIN);
|
|
|
|
SERIAL_ECHOLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)");
|
|
|
|
SERIAL_ECHOPGM(". Z_MIN_ENDSTOP_INVERTING: ");
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
#if Z_MIN_ENDSTOP_INVERTING
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("true");
|
2017-09-06 11:28:31 +00:00
|
|
|
#else
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("false");
|
2017-09-06 11:28:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
probe_inverting = Z_MIN_ENDSTOP_INVERTING;
|
|
|
|
|
|
|
|
#elif ENABLED(Z_MIN_PROBE_ENDSTOP)
|
|
|
|
|
|
|
|
#define PROBE_TEST_PIN Z_MIN_PROBE_PIN
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN);
|
|
|
|
SERIAL_ECHOLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)");
|
|
|
|
SERIAL_ECHOPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
#if Z_MIN_PROBE_ENDSTOP_INVERTING
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("true");
|
2017-09-06 11:28:31 +00:00
|
|
|
#else
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("false");
|
2017-09-06 11:28:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM(". deploy & stow 4 times");
|
2017-09-06 11:28:31 +00:00
|
|
|
SET_INPUT_PULLUP(PROBE_TEST_PIN);
|
2017-09-30 21:06:43 +00:00
|
|
|
uint8_t i = 0;
|
2017-09-06 11:28:31 +00:00
|
|
|
bool deploy_state, stow_state;
|
2017-09-30 21:06:43 +00:00
|
|
|
do {
|
2018-08-25 02:53:42 +00:00
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
2017-09-06 11:28:31 +00:00
|
|
|
safe_delay(500);
|
|
|
|
deploy_state = READ(PROBE_TEST_PIN);
|
2018-08-25 02:53:42 +00:00
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
2017-09-06 11:28:31 +00:00
|
|
|
safe_delay(500);
|
|
|
|
stow_state = READ(PROBE_TEST_PIN);
|
2017-09-30 21:06:43 +00:00
|
|
|
} while (++i < 4);
|
2018-11-29 22:58:58 +00:00
|
|
|
if (probe_inverting != deploy_state) SERIAL_ECHOLNPGM("WARNING - INVERTING setting probably backwards");
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
if (deploy_state != stow_state) {
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("BLTouch clone detected");
|
2017-09-06 11:28:31 +00:00
|
|
|
if (deploy_state) {
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM(". DEPLOYED state: HIGH (logic 1)");
|
|
|
|
SERIAL_ECHOLNPGM(". STOWED (triggered) state: LOW (logic 0)");
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM(". DEPLOYED state: LOW (logic 0)");
|
|
|
|
SERIAL_ECHOLNPGM(". STOWED (triggered) state: HIGH (logic 1)");
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
|
|
|
#if ENABLED(BLTOUCH)
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("ERROR: BLTOUCH enabled - set this device up as a Z Servo Probe with inverting as true.");
|
2017-09-06 11:28:31 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else { // measure active signal length
|
2018-08-25 02:53:42 +00:00
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
2017-09-06 11:28:31 +00:00
|
|
|
safe_delay(500);
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("please trigger probe");
|
2017-09-06 11:28:31 +00:00
|
|
|
uint16_t probe_counter = 0;
|
|
|
|
|
|
|
|
// Allow 30 seconds max for operator to trigger probe
|
|
|
|
for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) {
|
|
|
|
|
|
|
|
safe_delay(2);
|
|
|
|
|
2018-03-22 00:30:06 +00:00
|
|
|
if (0 == j % (500 * 1)) gcode.reset_stepper_timeout(); // Keep steppers powered
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered
|
|
|
|
|
|
|
|
for (probe_counter = 1; probe_counter < 50 && deploy_state != READ(PROBE_TEST_PIN); ++probe_counter)
|
|
|
|
safe_delay(2);
|
|
|
|
|
|
|
|
if (probe_counter == 50)
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("Z Servo Probe detected"); // >= 100mS active time
|
2017-09-06 11:28:31 +00:00
|
|
|
else if (probe_counter >= 2)
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2); // allow 4 - 100mS pulse
|
2017-09-06 11:28:31 +00:00
|
|
|
else
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("noise detected - please re-run test"); // less than 2mS pulse
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2018-08-25 02:53:42 +00:00
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
} // pulse detected
|
|
|
|
|
|
|
|
} // for loop waiting for trigger
|
|
|
|
|
2018-11-29 22:58:58 +00:00
|
|
|
if (probe_counter == 0) SERIAL_ECHOLNPGM("trigger not detected");
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
} // measure active signal length
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // servo_probe_test
|
|
|
|
|
|
|
|
/**
|
|
|
|
* M43: Pin debug - report pin state, watch pins, toggle pins and servo probe test/report
|
|
|
|
*
|
|
|
|
* M43 - report name and state of pin(s)
|
|
|
|
* P<pin> Pin to read or watch. If omitted, reads all pins.
|
|
|
|
* I Flag to ignore Marlin's pin protection.
|
|
|
|
*
|
|
|
|
* M43 W - Watch pins -reporting changes- until reset, click, or M108.
|
|
|
|
* P<pin> Pin to read or watch. If omitted, read/watch all pins.
|
|
|
|
* I Flag to ignore Marlin's pin protection.
|
|
|
|
*
|
|
|
|
* M43 E<bool> - Enable / disable background endstop monitoring
|
|
|
|
* - Machine continues to operate
|
|
|
|
* - Reports changes to endstops
|
|
|
|
* - Toggles LED_PIN when an endstop changes
|
2017-10-07 18:34:25 +00:00
|
|
|
* - Cannot reliably catch the 5mS pulse from BLTouch type probes
|
2017-09-06 11:28:31 +00:00
|
|
|
*
|
|
|
|
* M43 T - Toggle pin(s) and report which pin is being toggled
|
|
|
|
* S<pin> - Start Pin number. If not given, will default to 0
|
|
|
|
* L<pin> - End Pin number. If not given, will default to last pin defined for this board
|
|
|
|
* I<bool> - Flag to ignore Marlin's pin protection. Use with caution!!!!
|
|
|
|
* R - Repeat pulses on each pin this number of times before continueing to next pin
|
|
|
|
* W - Wait time (in miliseconds) between pulses. If not given will default to 500
|
|
|
|
*
|
|
|
|
* M43 S - Servo probe test
|
|
|
|
* P<index> - Probe index (optional - defaults to 0
|
|
|
|
*/
|
2017-09-16 09:06:28 +00:00
|
|
|
void GcodeSuite::M43() {
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
if (parser.seen('T')) { // must be first or else its "S" and "E" parameters will execute endstop or servo test
|
|
|
|
toggle_pins();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable or disable endstop monitoring
|
|
|
|
if (parser.seen('E')) {
|
2017-09-18 10:55:09 +00:00
|
|
|
endstops.monitor_flag = parser.value_bool();
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOPGM("endstop monitor ");
|
2017-09-18 10:55:09 +00:00
|
|
|
serialprintPGM(endstops.monitor_flag ? PSTR("en") : PSTR("dis"));
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("abled");
|
2017-09-06 11:28:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.seen('S')) {
|
|
|
|
servo_probe_test();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the range of pins to test or watch
|
2018-01-01 22:11:56 +00:00
|
|
|
uint8_t first_pin = PARSED_PIN_INDEX('P', 0),
|
|
|
|
last_pin = parser.seenval('P') ? first_pin : NUMBER_PINS_TOTAL - 1;
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
if (first_pin > last_pin) return;
|
|
|
|
|
|
|
|
const bool ignore_protection = parser.boolval('I');
|
|
|
|
|
|
|
|
// Watch until click, M108, or reset
|
|
|
|
if (parser.boolval('W')) {
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOLNPGM("Watching pins");
|
2018-01-05 16:10:55 +00:00
|
|
|
|
2018-01-01 22:11:56 +00:00
|
|
|
#ifdef ARDUINO_ARCH_SAM
|
|
|
|
NOLESS(first_pin, 2); // don't hijack the UART pins
|
|
|
|
#endif
|
2017-09-06 11:28:31 +00:00
|
|
|
uint8_t pin_state[last_pin - first_pin + 1];
|
2017-10-26 18:37:26 +00:00
|
|
|
for (uint8_t i = first_pin; i <= last_pin; i++) {
|
|
|
|
pin_t pin = GET_PIN_MAP_PIN(i);
|
2017-09-06 11:28:31 +00:00
|
|
|
if (!VALID_PIN(pin)) continue;
|
2018-06-10 22:45:39 +00:00
|
|
|
if (!ignore_protection && pin_is_protected(pin)) continue;
|
2017-09-06 11:28:31 +00:00
|
|
|
pinMode(pin, INPUT_PULLUP);
|
|
|
|
delay(1);
|
|
|
|
/*
|
|
|
|
if (IS_ANALOG(pin))
|
|
|
|
pin_state[pin - first_pin] = analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)); // int16_t pin_state[...]
|
|
|
|
else
|
|
|
|
//*/
|
2017-10-26 18:37:26 +00:00
|
|
|
pin_state[i - first_pin] = digitalRead(pin);
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if HAS_RESUME_CONTINUE
|
|
|
|
wait_for_user = true;
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (;;) {
|
2017-10-26 18:37:26 +00:00
|
|
|
for (uint8_t i = first_pin; i <= last_pin; i++) {
|
|
|
|
pin_t pin = GET_PIN_MAP_PIN(i);
|
2017-09-06 11:28:31 +00:00
|
|
|
if (!VALID_PIN(pin)) continue;
|
2018-06-10 22:45:39 +00:00
|
|
|
if (!ignore_protection && pin_is_protected(pin)) continue;
|
2017-09-06 11:28:31 +00:00
|
|
|
const byte val =
|
|
|
|
/*
|
|
|
|
IS_ANALOG(pin)
|
|
|
|
? analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)) : // int16_t val
|
|
|
|
:
|
|
|
|
//*/
|
|
|
|
digitalRead(pin);
|
2017-10-26 18:37:26 +00:00
|
|
|
if (val != pin_state[i - first_pin]) {
|
2017-09-06 11:28:31 +00:00
|
|
|
report_pin_state_extended(pin, ignore_protection, false);
|
2017-10-26 18:37:26 +00:00
|
|
|
pin_state[i - first_pin] = val;
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAS_RESUME_CONTINUE
|
|
|
|
if (!wait_for_user) {
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
safe_delay(200);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report current state of selected pin(s)
|
2017-10-26 18:37:26 +00:00
|
|
|
for (uint8_t i = first_pin; i <= last_pin; i++) {
|
|
|
|
pin_t pin = GET_PIN_MAP_PIN(i);
|
2017-09-06 11:28:31 +00:00
|
|
|
if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true);
|
2017-10-26 18:37:26 +00:00
|
|
|
}
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
2017-09-16 09:06:28 +00:00
|
|
|
|
|
|
|
#endif // PINS_DEBUGGING
|