diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index a22e6dc90..d19103c24 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1045,7 +1045,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 1c610e0b5..db35dedee 100755 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -90,7 +90,7 @@ * M33 - Get the longname version of a path. (Requires LONG_FILENAME_HOST_SUPPORT) * M34 - Set SD Card sorting options. (Requires SDCARD_SORT_ALPHA) * M42 - Change pin status via gcode: M42 P S. LED pin assumed if P is omitted. - * M43 - Monitor pins & report changes - report active pins + * M43 - Display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins * M48 - Measure Z Probe repeatability: M48 P X Y V E L. (Requires Z_MIN_PROBE_REPEATABILITY_TEST) * M75 - Start the print job timer. * M76 - Pause the print job timer. @@ -5308,23 +5308,176 @@ inline void gcode_M42() { #include "pinsDebug.h" + + inline void toggle_pins() { + int pin, j, start = 0, I_flag = 0, end = NUM_DIGITAL_PINS - 1, wait = 500, repeat = 1; + + if (code_seen('R')) + repeat = code_value_int(); + + if (code_seen('S')) + start = code_value_int(); + + if (code_seen('E')) + end = code_value_int(); + + if (code_seen('I') ) + I_flag++; + + if (code_seen('W')) + wait = code_value_int(); + + for(pin = start; pin <= end; pin++) { + if ( I_flag == 0 && pin_is_protected(pin)) { + SERIAL_ECHOPAIR("Sensitive Pin: ", pin); + SERIAL_ECHOPGM(" untouched.\n"); + } + else { + SERIAL_ECHOPAIR("Pulsing Pin: ", pin); + pinMode(pin, OUTPUT); + for(j = 0; j < repeat; j++) { + digitalWrite(pin, 0); + idle(); + delay(wait); + digitalWrite(pin, 1); + idle(); + delay(wait); + digitalWrite(pin, 0); + idle(); + delay(wait); + } + } + SERIAL_ECHOPGM("\n"); + } + SERIAL_ECHOPGM("Done\n"); + return; + } // toggle pin(s) + + + inline void servo_probe_test(){ + #if !(NUM_SERVOS >= 1 && HAS_SERVO_0) + SERIAL_ERROR_START; + SERIAL_ERRORLNPGM("SERVO not setup"); + #else + + #if !defined(z_servo_angle) + const int z_servo_angle[2] = Z_SERVO_ANGLES; + #endif + uint8_t probe_index = code_seen('P') ? code_value_byte() : 0; + SERIAL_PROTOCOLLNPGM("Servo probe test"); + SERIAL_PROTOCOLLNPAIR(". using index: ", probe_index); + SERIAL_PROTOCOLLNPAIR(". deploy angle: ", z_servo_angle[0]); + SERIAL_PROTOCOLLNPAIR(". stow angle: ", z_servo_angle[1]); + bool probe_inverting; + #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) + #define PROBE_TEST_PIN Z_MIN_PIN + SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN pin: ", PROBE_TEST_PIN); + SERIAL_PROTOCOLLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)"); + SERIAL_PROTOCOLPGM(". Z_MIN_ENDSTOP_INVERTING: "); + if (Z_MIN_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true"); + else SERIAL_PROTOCOLLNPGM("false"); + probe_inverting = Z_MIN_ENDSTOP_INVERTING; + #elif ENABLED(Z_MIN_PROBE_ENDSTOP) + #define PROBE_TEST_PIN Z_MIN_PROBE_PIN + + SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN); + SERIAL_PROTOCOLLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)"); + SERIAL_PROTOCOLPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: "); + if (Z_MIN_PROBE_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true"); + else SERIAL_PROTOCOLLNPGM("false"); + probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING; + #else + #error "ERROR - probe pin not defined - strange, SANITY_CHECK should have caught this" + #endif + SERIAL_PROTOCOLLNPGM(". deploy & stow 4 times"); + pinMode(PROBE_TEST_PIN, INPUT_PULLUP); + bool deploy_state; + bool stow_state; + for (uint8_t i = 0; i < 4; i++) { + servo[probe_index].move(z_servo_angle[0]); //deploy + safe_delay(500); + deploy_state = digitalRead(PROBE_TEST_PIN); + servo[probe_index].move(z_servo_angle[1]); //stow + safe_delay(500); + stow_state = digitalRead(PROBE_TEST_PIN); + } + if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards"); + refresh_cmd_timeout(); + if (deploy_state != stow_state) { + SERIAL_PROTOCOLLNPGM("TLTouch detected"); // BLTouch clone? + if (deploy_state) { + SERIAL_PROTOCOLLNPGM(". DEPLOYED state: HIGH (logic 1)"); + SERIAL_PROTOCOLLNPGM(". STOWED (triggered) state: LOW (logic 0)"); + } + else { + SERIAL_PROTOCOLLNPGM(". DEPLOYED state: LOW (logic 0)"); + SERIAL_PROTOCOLLNPGM(". STOWED (triggered) state: HIGH (logic 1)"); + } + } + else { // measure active signal length + servo[probe_index].move(z_servo_angle[0]); //deploy + safe_delay(500); + SERIAL_PROTOCOLLNPGM("please trigger probe"); + uint16_t probe_counter = 0; + for (uint16_t j = 0; j < 500*30 && probe_counter == 0 ; j++) { // allow 30 seconds max for operator to trigger probe + safe_delay(2); + if ( 0 == j%(500*1)) {refresh_cmd_timeout(); watchdog_reset();} // beat the dog every 45 seconds + if (deploy_state != digitalRead(PROBE_TEST_PIN)) { // probe triggered + for (probe_counter = 1; probe_counter < 50 && (deploy_state != digitalRead(PROBE_TEST_PIN)); probe_counter ++) { + safe_delay(2); + } + if (probe_counter == 50) { + SERIAL_PROTOCOLLNPGM("Z Servo Probe detected"); // >= 100mS active time + } + else if (probe_counter >= 2 ) { + SERIAL_PROTOCOLLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2 ); // allow 4 - 100mS pulse + } + else { + SERIAL_PROTOCOLLNPGM("noise detected - please re-run test"); // less than 2mS pulse + } + servo[probe_index].move(z_servo_angle[1]); //stow + } // pulse detected + } // for loop waiting for trigger + if (probe_counter == 0) SERIAL_PROTOCOLLNPGM("trigger not detected"); + } // measure active signal length + #endif + } // servo_probe_test + /** - * M43: Pin report and debug + * 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 to read or watch. If omitted, reads all pins. + * I Flag to ignore Marlin's pin protection. * - * E Enable / disable background endstop monitoring - * - Machine continues to operate - * - Reports changes to endstops - * - Toggles LED when an endstop changes + * M43 W - Watch pins -reporting changes- until reset, click, or M108. + * P Pin to read or watch. If omitted, read/watch all pins. + * I Flag to ignore Marlin's pin protection. * - * or + * M43 E - Enable / disable background endstop monitoring + * - Machine continues to operate + * - Reports changes to endstops + * - Toggles LED when an endstop changes + * - Can not reliably catch the 5mS pulse from BLTouch type probes * - * P Pin to read or watch. If omitted, read/watch all pins. - * W Watch pins -reporting changes- until reset, click, or M108. - * I Flag to ignore Marlin's pin protection. + * M43 T - Toggle pin(s) and report which pin is being toggled + * S - Start Pin number. If not given, will default to 0 + * L - End Pin number. If not given, will default to last pin defined for this board + * I - 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 - Probe index (optional - defaults to 0 */ + inline void gcode_M43() { + if (code_seen('T')) { // must be first ot else it's "S" and "E" parameters will execute endstop or servo test + toggle_pins(); + return; + } + // Enable or disable endstop monitoring if (code_seen('E')) { endstop_monitor_flag = code_value_bool(); @@ -5334,6 +5487,12 @@ inline void gcode_M42() { return; } + if (code_seen('S')) { + servo_probe_test(); + return; + } + + // Get the range of pins to test or watch int first_pin = 0, last_pin = NUM_DIGITAL_PINS - 1; if (code_seen('P')) { @@ -5341,10 +5500,11 @@ inline void gcode_M42() { if (first_pin > NUM_DIGITAL_PINS - 1) return; } - const bool ignore_protection = code_seen('I') ? code_value_bool() : false; + bool ignore_protection = code_seen('I'); // Watch until click, M108, or reset - if (code_seen('W') && code_value_bool()) { // watch digital pins + if (code_seen('W')) { // watch digital pins + SERIAL_PROTOCOLLNPGM("Watching pins"); byte pin_state[last_pin - first_pin + 1]; for (int8_t pin = first_pin; pin <= last_pin; pin++) { if (pin_is_protected(pin) && !ignore_protection) continue; @@ -5387,6 +5547,7 @@ inline void gcode_M42() { report_pin_state_extended(pin, ignore_protection); } + #endif // PINS_DEBUGGING #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST) diff --git a/Marlin/example_configurations/Cartesio/Configuration_adv.h b/Marlin/example_configurations/Cartesio/Configuration_adv.h index 8f4828684..4b38dedbe 100644 --- a/Marlin/example_configurations/Cartesio/Configuration_adv.h +++ b/Marlin/example_configurations/Cartesio/Configuration_adv.h @@ -1035,7 +1035,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/Felix/Configuration_adv.h b/Marlin/example_configurations/Felix/Configuration_adv.h index 3ad29213a..c3a39f7a6 100644 --- a/Marlin/example_configurations/Felix/Configuration_adv.h +++ b/Marlin/example_configurations/Felix/Configuration_adv.h @@ -1035,7 +1035,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/Hephestos/Configuration_adv.h b/Marlin/example_configurations/Hephestos/Configuration_adv.h index 6b9015bd0..b6e7713fa 100644 --- a/Marlin/example_configurations/Hephestos/Configuration_adv.h +++ b/Marlin/example_configurations/Hephestos/Configuration_adv.h @@ -1035,7 +1035,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/Hephestos_2/Configuration_adv.h b/Marlin/example_configurations/Hephestos_2/Configuration_adv.h index 74fce16af..a5ff28a75 100644 --- a/Marlin/example_configurations/Hephestos_2/Configuration_adv.h +++ b/Marlin/example_configurations/Hephestos_2/Configuration_adv.h @@ -1018,7 +1018,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/K8200/Configuration_adv.h b/Marlin/example_configurations/K8200/Configuration_adv.h index 038e19a76..683fa3a18 100644 --- a/Marlin/example_configurations/K8200/Configuration_adv.h +++ b/Marlin/example_configurations/K8200/Configuration_adv.h @@ -1048,7 +1048,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/K8400/Configuration_adv.h b/Marlin/example_configurations/K8400/Configuration_adv.h index 6c9fadb18..ae33bb693 100644 --- a/Marlin/example_configurations/K8400/Configuration_adv.h +++ b/Marlin/example_configurations/K8400/Configuration_adv.h @@ -1035,7 +1035,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/RigidBot/Configuration_adv.h b/Marlin/example_configurations/RigidBot/Configuration_adv.h index 6187556c7..220397d3c 100644 --- a/Marlin/example_configurations/RigidBot/Configuration_adv.h +++ b/Marlin/example_configurations/RigidBot/Configuration_adv.h @@ -1035,7 +1035,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/SCARA/Configuration_adv.h b/Marlin/example_configurations/SCARA/Configuration_adv.h index 293214d2a..09af8d031 100644 --- a/Marlin/example_configurations/SCARA/Configuration_adv.h +++ b/Marlin/example_configurations/SCARA/Configuration_adv.h @@ -1035,7 +1035,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/TAZ4/Configuration_adv.h b/Marlin/example_configurations/TAZ4/Configuration_adv.h index 168a398b5..942e23cc1 100644 --- a/Marlin/example_configurations/TAZ4/Configuration_adv.h +++ b/Marlin/example_configurations/TAZ4/Configuration_adv.h @@ -1043,7 +1043,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/TinyBoy2/Configuration_adv.h b/Marlin/example_configurations/TinyBoy2/Configuration_adv.h index 1365a16dd..3bc3a02c7 100644 --- a/Marlin/example_configurations/TinyBoy2/Configuration_adv.h +++ b/Marlin/example_configurations/TinyBoy2/Configuration_adv.h @@ -1044,7 +1044,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/WITBOX/Configuration_adv.h b/Marlin/example_configurations/WITBOX/Configuration_adv.h index 6b9015bd0..b6e7713fa 100644 --- a/Marlin/example_configurations/WITBOX/Configuration_adv.h +++ b/Marlin/example_configurations/WITBOX/Configuration_adv.h @@ -1035,7 +1035,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/delta/flsun_kossel_mini/Configuration_adv.h b/Marlin/example_configurations/delta/flsun_kossel_mini/Configuration_adv.h index b974eea21..030195fca 100644 --- a/Marlin/example_configurations/delta/flsun_kossel_mini/Configuration_adv.h +++ b/Marlin/example_configurations/delta/flsun_kossel_mini/Configuration_adv.h @@ -1039,7 +1039,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/delta/generic/Configuration_adv.h b/Marlin/example_configurations/delta/generic/Configuration_adv.h index f3f15070c..86e04cb84 100644 --- a/Marlin/example_configurations/delta/generic/Configuration_adv.h +++ b/Marlin/example_configurations/delta/generic/Configuration_adv.h @@ -1037,7 +1037,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h index f3f15070c..86e04cb84 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h @@ -1037,7 +1037,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h index b17c39f20..915dd93f6 100644 --- a/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h @@ -1042,7 +1042,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h index fa9cdbd9f..e7f8eeab7 100644 --- a/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h @@ -1037,7 +1037,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/makibox/Configuration_adv.h b/Marlin/example_configurations/makibox/Configuration_adv.h index 48936b316..8d4281502 100644 --- a/Marlin/example_configurations/makibox/Configuration_adv.h +++ b/Marlin/example_configurations/makibox/Configuration_adv.h @@ -1035,7 +1035,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING diff --git a/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h b/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h index 364a8a943..cf2d17527 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h @@ -1035,7 +1035,7 @@ #define I2C_SLAVE_ADDRESS 0 // Set a value from 8 to 127 to act as a slave /** - * Add M43, M44 and M45 commands for pins info and testing + * M43 - display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins */ //#define PINS_DEBUGGING