diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 44e3e3d30a..63195197cb 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1046,7 +1046,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 1c610e0b52..db35dedee0 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 63ab14e943..ac41fd233c 100644 --- a/Marlin/example_configurations/Cartesio/Configuration_adv.h +++ b/Marlin/example_configurations/Cartesio/Configuration_adv.h @@ -1036,7 +1036,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 653c1b4486..e035aade9d 100644 --- a/Marlin/example_configurations/Felix/Configuration_adv.h +++ b/Marlin/example_configurations/Felix/Configuration_adv.h @@ -1036,7 +1036,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 b85e925de4..6056802b02 100644 --- a/Marlin/example_configurations/Hephestos/Configuration_adv.h +++ b/Marlin/example_configurations/Hephestos/Configuration_adv.h @@ -1036,7 +1036,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 9dd44e7c46..5fbcec07e8 100644 --- a/Marlin/example_configurations/Hephestos_2/Configuration_adv.h +++ b/Marlin/example_configurations/Hephestos_2/Configuration_adv.h @@ -1019,7 +1019,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 68af644264..7e1b990fba 100644 --- a/Marlin/example_configurations/K8200/Configuration_adv.h +++ b/Marlin/example_configurations/K8200/Configuration_adv.h @@ -1049,7 +1049,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 4f21df5bd4..8adc59dd6b 100644 --- a/Marlin/example_configurations/K8400/Configuration_adv.h +++ b/Marlin/example_configurations/K8400/Configuration_adv.h @@ -1036,7 +1036,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 78d542d70a..e3b02b9171 100644 --- a/Marlin/example_configurations/RigidBot/Configuration_adv.h +++ b/Marlin/example_configurations/RigidBot/Configuration_adv.h @@ -1036,7 +1036,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 ded7a7cc7b..a575352aad 100644 --- a/Marlin/example_configurations/SCARA/Configuration_adv.h +++ b/Marlin/example_configurations/SCARA/Configuration_adv.h @@ -1036,7 +1036,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 02d4287386..96a649d037 100644 --- a/Marlin/example_configurations/TAZ4/Configuration_adv.h +++ b/Marlin/example_configurations/TAZ4/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/TinyBoy2/Configuration_adv.h b/Marlin/example_configurations/TinyBoy2/Configuration_adv.h index 1365a16dd6..3bc3a02c79 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 b85e925de4..6056802b02 100644 --- a/Marlin/example_configurations/WITBOX/Configuration_adv.h +++ b/Marlin/example_configurations/WITBOX/Configuration_adv.h @@ -1036,7 +1036,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 da605cadf2..e31808d24e 100644 --- a/Marlin/example_configurations/delta/flsun_kossel_mini/Configuration_adv.h +++ b/Marlin/example_configurations/delta/flsun_kossel_mini/Configuration_adv.h @@ -1040,7 +1040,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 9631948e3e..93db3e47c2 100644 --- a/Marlin/example_configurations/delta/generic/Configuration_adv.h +++ b/Marlin/example_configurations/delta/generic/Configuration_adv.h @@ -1038,7 +1038,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 9631948e3e..93db3e47c2 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h @@ -1038,7 +1038,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 37d185b58d..55c2e846eb 100644 --- a/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_pro/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/delta/kossel_xl/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h index 01edfc19cb..df369a39ab 100644 --- a/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h @@ -1038,7 +1038,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 ae793ed755..2e61d9ff1c 100644 --- a/Marlin/example_configurations/makibox/Configuration_adv.h +++ b/Marlin/example_configurations/makibox/Configuration_adv.h @@ -1036,7 +1036,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 1c47f8560f..1d44ca359a 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h @@ -1036,7 +1036,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