|
@@ -5806,70 +5806,94 @@ inline void gcode_M42() {
|
5806
|
5806
|
#include "pinsDebug.h"
|
5807
|
5807
|
|
5808
|
5808
|
inline void toggle_pins() {
|
5809
|
|
- int pin, j;
|
|
5809
|
+ const bool I_flag = code_seen('I') && code_value_bool();
|
|
5810
|
+ const int repeat = code_seen('R') ? code_value_int() : 1,
|
|
5811
|
+ start = code_seen('S') ? code_value_int() : 0,
|
|
5812
|
+ end = code_seen('E') ? code_value_int() : NUM_DIGITAL_PINS - 1,
|
|
5813
|
+ wait = code_seen('W') ? code_value_int() : 500;
|
5810
|
5814
|
|
5811
|
|
- bool I_flag = code_seen('I') ? code_value_bool() : false;
|
5812
|
|
-
|
5813
|
|
- int repeat = code_seen('R') ? code_value_int() : 1,
|
5814
|
|
- start = code_seen('S') ? code_value_int() : 0,
|
5815
|
|
- end = code_seen('E') ? code_value_int() : NUM_DIGITAL_PINS - 1,
|
5816
|
|
- wait = code_seen('W') ? code_value_int() : 500;
|
5817
|
|
-
|
5818
|
|
- for (pin = start; pin <= end; pin++) {
|
5819
|
|
- if (!I_flag && pin_is_protected(pin)) {
|
5820
|
|
- SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
|
5821
|
|
- SERIAL_ECHOPGM(" untouched.\n");
|
5822
|
|
- }
|
5823
|
|
- else {
|
5824
|
|
- SERIAL_ECHOPAIR("Pulsing Pin: ", pin);
|
5825
|
|
- pinMode(pin, OUTPUT);
|
5826
|
|
- for(j = 0; j < repeat; j++) {
|
5827
|
|
- digitalWrite(pin, 0);
|
5828
|
|
- safe_delay(wait);
|
5829
|
|
- digitalWrite(pin, 1);
|
5830
|
|
- safe_delay(wait);
|
5831
|
|
- digitalWrite(pin, 0);
|
5832
|
|
- safe_delay(wait);
|
5833
|
|
- }
|
|
5815
|
+ for (uint8_t pin = start; pin <= end; pin++) {
|
|
5816
|
+ if (!I_flag && pin_is_protected(pin)) {
|
|
5817
|
+ SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
|
|
5818
|
+ SERIAL_ECHOLNPGM(" untouched.");
|
|
5819
|
+ }
|
|
5820
|
+ else {
|
|
5821
|
+ SERIAL_ECHOPAIR("Pulsing Pin: ", pin);
|
|
5822
|
+ pinMode(pin, OUTPUT);
|
|
5823
|
+ for (int16_t j = 0; j < repeat; j++) {
|
|
5824
|
+ digitalWrite(pin, 0);
|
|
5825
|
+ safe_delay(wait);
|
|
5826
|
+ digitalWrite(pin, 1);
|
|
5827
|
+ safe_delay(wait);
|
|
5828
|
+ digitalWrite(pin, 0);
|
|
5829
|
+ safe_delay(wait);
|
5834
|
5830
|
}
|
5835
|
|
- SERIAL_ECHOPGM("\n");
|
|
5831
|
+ }
|
|
5832
|
+ SERIAL_CHAR('\n');
|
5836
|
5833
|
}
|
5837
|
|
- SERIAL_ECHOPGM("Done\n");
|
|
5834
|
+ SERIAL_ECHOLNPGM("Done.");
|
|
5835
|
+
|
5838
|
5836
|
} // toggle_pins
|
5839
|
5837
|
|
5840
|
|
- inline void servo_probe_test(){
|
5841
|
|
- #if !(NUM_SERVOS >= 1 && HAS_SERVO_0)
|
|
5838
|
+ inline void servo_probe_test() {
|
|
5839
|
+ #if !(NUM_SERVOS > 0 && HAS_SERVO_0)
|
|
5840
|
+
|
5842
|
5841
|
SERIAL_ERROR_START;
|
5843
|
5842
|
SERIAL_ERRORLNPGM("SERVO not setup");
|
|
5843
|
+
|
5844
|
5844
|
#elif !HAS_Z_SERVO_ENDSTOP
|
|
5845
|
+
|
5845
|
5846
|
SERIAL_ERROR_START;
|
5846
|
5847
|
SERIAL_ERRORLNPGM("Z_ENDSTOP_SERVO_NR not setup");
|
|
5848
|
+
|
5847
|
5849
|
#else
|
5848
|
|
- uint8_t probe_index = code_seen('P') ? code_value_byte() : Z_ENDSTOP_SERVO_NR;
|
|
5850
|
+
|
|
5851
|
+ #if !defined(z_servo_angle)
|
|
5852
|
+ const int z_servo_angle[2] = Z_SERVO_ANGLES;
|
|
5853
|
+ #endif
|
|
5854
|
+
|
|
5855
|
+ const uint8_t probe_index = code_seen('P') ? code_value_byte() : Z_ENDSTOP_SERVO_NR;
|
|
5856
|
+
|
5849
|
5857
|
SERIAL_PROTOCOLLNPGM("Servo probe test");
|
5850
|
5858
|
SERIAL_PROTOCOLLNPAIR(". using index: ", probe_index);
|
5851
|
5859
|
SERIAL_PROTOCOLLNPAIR(". deploy angle: ", z_servo_angle[0]);
|
5852
|
5860
|
SERIAL_PROTOCOLLNPAIR(". stow angle: ", z_servo_angle[1]);
|
|
5861
|
+
|
5853
|
5862
|
bool probe_inverting;
|
|
5863
|
+
|
5854
|
5864
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
|
5865
|
+
|
5855
|
5866
|
#define PROBE_TEST_PIN Z_MIN_PIN
|
|
5867
|
+
|
5856
|
5868
|
SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN pin: ", PROBE_TEST_PIN);
|
5857
|
5869
|
SERIAL_PROTOCOLLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)");
|
5858
|
5870
|
SERIAL_PROTOCOLPGM(". Z_MIN_ENDSTOP_INVERTING: ");
|
5859
|
|
- if (Z_MIN_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true");
|
5860
|
|
- else SERIAL_PROTOCOLLNPGM("false");
|
|
5871
|
+
|
|
5872
|
+ #if Z_MIN_ENDSTOP_INVERTING
|
|
5873
|
+ SERIAL_PROTOCOLLNPGM("true");
|
|
5874
|
+ #else
|
|
5875
|
+ SERIAL_PROTOCOLLNPGM("false");
|
|
5876
|
+ #endif
|
|
5877
|
+
|
5861
|
5878
|
probe_inverting = Z_MIN_ENDSTOP_INVERTING;
|
|
5879
|
+
|
5862
|
5880
|
#elif ENABLED(Z_MIN_PROBE_ENDSTOP)
|
|
5881
|
+
|
5863
|
5882
|
#define PROBE_TEST_PIN Z_MIN_PROBE_PIN
|
5864
|
5883
|
SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN);
|
5865
|
5884
|
SERIAL_PROTOCOLLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)");
|
5866
|
5885
|
SERIAL_PROTOCOLPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
|
5867
|
|
- if (Z_MIN_PROBE_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true");
|
5868
|
|
- else SERIAL_PROTOCOLLNPGM("false");
|
|
5886
|
+
|
|
5887
|
+ #if Z_MIN_PROBE_ENDSTOP_INVERTING
|
|
5888
|
+ SERIAL_PROTOCOLLNPGM("true");
|
|
5889
|
+ #else
|
|
5890
|
+ SERIAL_PROTOCOLLNPGM("false");
|
|
5891
|
+ #endif
|
|
5892
|
+
|
5869
|
5893
|
probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
|
5870
|
|
- #else
|
5871
|
|
- #error "ERROR - probe pin not defined - strange, SANITY_CHECK should have caught this"
|
|
5894
|
+
|
5872
|
5895
|
#endif
|
|
5896
|
+
|
5873
|
5897
|
SERIAL_PROTOCOLLNPGM(". deploy & stow 4 times");
|
5874
|
5898
|
pinMode(PROBE_TEST_PIN, INPUT_PULLUP);
|
5875
|
5899
|
bool deploy_state;
|
|
@@ -5883,7 +5907,9 @@ inline void gcode_M42() {
|
5883
|
5907
|
stow_state = digitalRead(PROBE_TEST_PIN);
|
5884
|
5908
|
}
|
5885
|
5909
|
if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards");
|
|
5910
|
+
|
5886
|
5911
|
refresh_cmd_timeout();
|
|
5912
|
+
|
5887
|
5913
|
if (deploy_state != stow_state) {
|
5888
|
5914
|
SERIAL_PROTOCOLLNPGM("BLTouch clone detected");
|
5889
|
5915
|
if (deploy_state) {
|
|
@@ -5900,32 +5926,43 @@ inline void gcode_M42() {
|
5900
|
5926
|
|
5901
|
5927
|
}
|
5902
|
5928
|
else { // measure active signal length
|
5903
|
|
- servo[probe_index].move(z_servo_angle[0]); //deploy
|
|
5929
|
+ servo[probe_index].move(z_servo_angle[0]); // deploy
|
5904
|
5930
|
safe_delay(500);
|
5905
|
5931
|
SERIAL_PROTOCOLLNPGM("please trigger probe");
|
5906
|
5932
|
uint16_t probe_counter = 0;
|
5907
|
|
- for (uint16_t j = 0; j < 500*30 && probe_counter == 0 ; j++) { // allow 30 seconds max for operator to trigger probe
|
|
5933
|
+
|
|
5934
|
+ // Allow 30 seconds max for operator to trigger probe
|
|
5935
|
+ for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) {
|
|
5936
|
+
|
5908
|
5937
|
safe_delay(2);
|
5909
|
|
- if ( 0 == j%(500*1)) {refresh_cmd_timeout(); watchdog_reset();} // beat the dog every 45 seconds
|
5910
|
|
- if (deploy_state != digitalRead(PROBE_TEST_PIN)) { // probe triggered
|
5911
|
|
- for (probe_counter = 1; probe_counter < 50 && (deploy_state != digitalRead(PROBE_TEST_PIN)); probe_counter ++) {
|
|
5938
|
+
|
|
5939
|
+ if (0 == j % (500 * 1)) // keep cmd_timeout happy
|
|
5940
|
+ refresh_cmd_timeout();
|
|
5941
|
+
|
|
5942
|
+ if (deploy_state != digitalRead(PROBE_TEST_PIN)) { // probe triggered
|
|
5943
|
+
|
|
5944
|
+ for (probe_counter = 1; probe_counter < 50 && deploy_state != digitalRead(PROBE_TEST_PIN); ++probe_counter)
|
5912
|
5945
|
safe_delay(2);
|
5913
|
|
- }
|
5914
|
|
- if (probe_counter == 50) {
|
5915
|
|
- SERIAL_PROTOCOLLNPGM("Z Servo Probe detected"); // >= 100mS active time
|
5916
|
|
- }
|
5917
|
|
- else if (probe_counter >= 2 ) {
|
5918
|
|
- SERIAL_PROTOCOLLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2 ); // allow 4 - 100mS pulse
|
5919
|
|
- }
|
5920
|
|
- else {
|
5921
|
|
- SERIAL_PROTOCOLLNPGM("noise detected - please re-run test"); // less than 2mS pulse
|
5922
|
|
- }
|
|
5946
|
+
|
|
5947
|
+ if (probe_counter == 50)
|
|
5948
|
+ SERIAL_PROTOCOLLNPGM("Z Servo Probe detected"); // >= 100mS active time
|
|
5949
|
+ else if (probe_counter >= 2)
|
|
5950
|
+ SERIAL_PROTOCOLLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2); // allow 4 - 100mS pulse
|
|
5951
|
+ else
|
|
5952
|
+ SERIAL_PROTOCOLLNPGM("noise detected - please re-run test"); // less than 2mS pulse
|
|
5953
|
+
|
5923
|
5954
|
servo[probe_index].move(z_servo_angle[1]); //stow
|
|
5955
|
+
|
5924
|
5956
|
} // pulse detected
|
5925
|
|
- } // for loop waiting for trigger
|
|
5957
|
+
|
|
5958
|
+ } // for loop waiting for trigger
|
|
5959
|
+
|
5926
|
5960
|
if (probe_counter == 0) SERIAL_PROTOCOLLNPGM("trigger not detected");
|
5927
|
|
- } // measure active signal length
|
|
5961
|
+
|
|
5962
|
+ } // measure active signal length
|
|
5963
|
+
|
5928
|
5964
|
#endif
|
|
5965
|
+
|
5929
|
5966
|
} // servo_probe_test
|
5930
|
5967
|
|
5931
|
5968
|
/**
|
|
@@ -5977,39 +6014,43 @@ inline void gcode_M42() {
|
5977
|
6014
|
}
|
5978
|
6015
|
|
5979
|
6016
|
// Get the range of pins to test or watch
|
5980
|
|
- int first_pin = 0, last_pin = NUM_DIGITAL_PINS - 1;
|
5981
|
|
- if (code_seen('P')) {
|
5982
|
|
- first_pin = last_pin = code_value_byte();
|
5983
|
|
- if (first_pin > NUM_DIGITAL_PINS - 1) return;
|
5984
|
|
- }
|
|
6017
|
+ const uint8_t first_pin = code_seen('P') ? code_value_byte() : 0,
|
|
6018
|
+ last_pin = code_seen('P') ? first_pin : NUM_DIGITAL_PINS - 1;
|
5985
|
6019
|
|
5986
|
|
- bool ignore_protection = code_seen('I') ? code_value_bool() : false;
|
|
6020
|
+ if (first_pin > last_pin) return;
|
|
6021
|
+
|
|
6022
|
+ const bool ignore_protection = code_seen('I') && code_value_bool();
|
5987
|
6023
|
|
5988
|
6024
|
// Watch until click, M108, or reset
|
5989
|
|
- if (code_seen('W') && code_value_bool()) { // watch digital pins
|
|
6025
|
+ if (code_seen('W') && code_value_bool()) {
|
5990
|
6026
|
SERIAL_PROTOCOLLNPGM("Watching pins");
|
5991
|
6027
|
byte pin_state[last_pin - first_pin + 1];
|
5992
|
6028
|
for (int8_t pin = first_pin; pin <= last_pin; pin++) {
|
5993
|
6029
|
if (pin_is_protected(pin) && !ignore_protection) continue;
|
5994
|
6030
|
pinMode(pin, INPUT_PULLUP);
|
5995
|
|
- // if (IS_ANALOG(pin))
|
5996
|
|
- // pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
|
5997
|
|
- // else
|
5998
|
|
- pin_state[pin - first_pin] = digitalRead(pin);
|
|
6031
|
+ /*
|
|
6032
|
+ if (IS_ANALOG(pin))
|
|
6033
|
+ pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
|
|
6034
|
+ else
|
|
6035
|
+ //*/
|
|
6036
|
+ pin_state[pin - first_pin] = digitalRead(pin);
|
5999
|
6037
|
}
|
6000
|
6038
|
|
6001
|
6039
|
#if HAS_RESUME_CONTINUE
|
6002
|
6040
|
wait_for_user = true;
|
|
6041
|
+ KEEPALIVE_STATE(PAUSED_FOR_USER);
|
6003
|
6042
|
#endif
|
6004
|
6043
|
|
6005
|
|
- for(;;) {
|
|
6044
|
+ for (;;) {
|
6006
|
6045
|
for (int8_t pin = first_pin; pin <= last_pin; pin++) {
|
6007
|
6046
|
if (pin_is_protected(pin)) continue;
|
6008
|
|
- byte val;
|
6009
|
|
- // if (IS_ANALOG(pin))
|
6010
|
|
- // val = analogRead(pin - analogInputToDigitalPin(0)); // int16_t val
|
6011
|
|
- // else
|
6012
|
|
- val = digitalRead(pin);
|
|
6047
|
+ const byte val =
|
|
6048
|
+ /*
|
|
6049
|
+ IS_ANALOG(pin)
|
|
6050
|
+ ? analogRead(pin - analogInputToDigitalPin(0)) : // int16_t val
|
|
6051
|
+ :
|
|
6052
|
+ //*/
|
|
6053
|
+ digitalRead(pin);
|
6013
|
6054
|
if (val != pin_state[pin - first_pin]) {
|
6014
|
6055
|
report_pin_state(pin);
|
6015
|
6056
|
pin_state[pin - first_pin] = val;
|
|
@@ -6017,7 +6058,10 @@ inline void gcode_M42() {
|
6017
|
6058
|
}
|
6018
|
6059
|
|
6019
|
6060
|
#if HAS_RESUME_CONTINUE
|
6020
|
|
- if (!wait_for_user) break;
|
|
6061
|
+ if (!wait_for_user) {
|
|
6062
|
+ KEEPALIVE_STATE(IN_HANDLER);
|
|
6063
|
+ break;
|
|
6064
|
+ }
|
6021
|
6065
|
#endif
|
6022
|
6066
|
|
6023
|
6067
|
safe_delay(500);
|