Cleanup of pins testing code
This commit is contained in:
parent
e9b53ae00c
commit
e97f1284c1
@ -5806,24 +5806,21 @@ inline void gcode_M42() {
|
|||||||
#include "pinsDebug.h"
|
#include "pinsDebug.h"
|
||||||
|
|
||||||
inline void toggle_pins() {
|
inline void toggle_pins() {
|
||||||
int pin, j;
|
const bool I_flag = code_seen('I') && code_value_bool();
|
||||||
|
const int repeat = code_seen('R') ? code_value_int() : 1,
|
||||||
bool I_flag = code_seen('I') ? code_value_bool() : false;
|
|
||||||
|
|
||||||
int repeat = code_seen('R') ? code_value_int() : 1,
|
|
||||||
start = code_seen('S') ? code_value_int() : 0,
|
start = code_seen('S') ? code_value_int() : 0,
|
||||||
end = code_seen('E') ? code_value_int() : NUM_DIGITAL_PINS - 1,
|
end = code_seen('E') ? code_value_int() : NUM_DIGITAL_PINS - 1,
|
||||||
wait = code_seen('W') ? code_value_int() : 500;
|
wait = code_seen('W') ? code_value_int() : 500;
|
||||||
|
|
||||||
for (pin = start; pin <= end; pin++) {
|
for (uint8_t pin = start; pin <= end; pin++) {
|
||||||
if (!I_flag && pin_is_protected(pin)) {
|
if (!I_flag && pin_is_protected(pin)) {
|
||||||
SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
|
SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
|
||||||
SERIAL_ECHOPGM(" untouched.\n");
|
SERIAL_ECHOLNPGM(" untouched.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SERIAL_ECHOPAIR("Pulsing Pin: ", pin);
|
SERIAL_ECHOPAIR("Pulsing Pin: ", pin);
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
for(j = 0; j < repeat; j++) {
|
for (int16_t j = 0; j < repeat; j++) {
|
||||||
digitalWrite(pin, 0);
|
digitalWrite(pin, 0);
|
||||||
safe_delay(wait);
|
safe_delay(wait);
|
||||||
digitalWrite(pin, 1);
|
digitalWrite(pin, 1);
|
||||||
@ -5832,44 +5829,71 @@ inline void gcode_M42() {
|
|||||||
safe_delay(wait);
|
safe_delay(wait);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SERIAL_ECHOPGM("\n");
|
SERIAL_CHAR('\n');
|
||||||
}
|
}
|
||||||
SERIAL_ECHOPGM("Done\n");
|
SERIAL_ECHOLNPGM("Done.");
|
||||||
|
|
||||||
} // toggle_pins
|
} // toggle_pins
|
||||||
|
|
||||||
inline void servo_probe_test() {
|
inline void servo_probe_test() {
|
||||||
#if !(NUM_SERVOS >= 1 && HAS_SERVO_0)
|
#if !(NUM_SERVOS > 0 && HAS_SERVO_0)
|
||||||
|
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("SERVO not setup");
|
SERIAL_ERRORLNPGM("SERVO not setup");
|
||||||
|
|
||||||
#elif !HAS_Z_SERVO_ENDSTOP
|
#elif !HAS_Z_SERVO_ENDSTOP
|
||||||
|
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Z_ENDSTOP_SERVO_NR not setup");
|
SERIAL_ERRORLNPGM("Z_ENDSTOP_SERVO_NR not setup");
|
||||||
|
|
||||||
#else
|
#else
|
||||||
uint8_t probe_index = code_seen('P') ? code_value_byte() : Z_ENDSTOP_SERVO_NR;
|
|
||||||
|
#if !defined(z_servo_angle)
|
||||||
|
const int z_servo_angle[2] = Z_SERVO_ANGLES;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const uint8_t probe_index = code_seen('P') ? code_value_byte() : Z_ENDSTOP_SERVO_NR;
|
||||||
|
|
||||||
SERIAL_PROTOCOLLNPGM("Servo probe test");
|
SERIAL_PROTOCOLLNPGM("Servo probe test");
|
||||||
SERIAL_PROTOCOLLNPAIR(". using index: ", probe_index);
|
SERIAL_PROTOCOLLNPAIR(". using index: ", probe_index);
|
||||||
SERIAL_PROTOCOLLNPAIR(". deploy angle: ", z_servo_angle[0]);
|
SERIAL_PROTOCOLLNPAIR(". deploy angle: ", z_servo_angle[0]);
|
||||||
SERIAL_PROTOCOLLNPAIR(". stow angle: ", z_servo_angle[1]);
|
SERIAL_PROTOCOLLNPAIR(". stow angle: ", z_servo_angle[1]);
|
||||||
|
|
||||||
bool probe_inverting;
|
bool probe_inverting;
|
||||||
|
|
||||||
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
||||||
|
|
||||||
#define PROBE_TEST_PIN Z_MIN_PIN
|
#define PROBE_TEST_PIN Z_MIN_PIN
|
||||||
|
|
||||||
SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN pin: ", PROBE_TEST_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_PROTOCOLLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)");
|
||||||
SERIAL_PROTOCOLPGM(". Z_MIN_ENDSTOP_INVERTING: ");
|
SERIAL_PROTOCOLPGM(". Z_MIN_ENDSTOP_INVERTING: ");
|
||||||
if (Z_MIN_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true");
|
|
||||||
else SERIAL_PROTOCOLLNPGM("false");
|
#if Z_MIN_ENDSTOP_INVERTING
|
||||||
|
SERIAL_PROTOCOLLNPGM("true");
|
||||||
|
#else
|
||||||
|
SERIAL_PROTOCOLLNPGM("false");
|
||||||
|
#endif
|
||||||
|
|
||||||
probe_inverting = Z_MIN_ENDSTOP_INVERTING;
|
probe_inverting = Z_MIN_ENDSTOP_INVERTING;
|
||||||
|
|
||||||
#elif ENABLED(Z_MIN_PROBE_ENDSTOP)
|
#elif ENABLED(Z_MIN_PROBE_ENDSTOP)
|
||||||
|
|
||||||
#define PROBE_TEST_PIN Z_MIN_PROBE_PIN
|
#define PROBE_TEST_PIN Z_MIN_PROBE_PIN
|
||||||
SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_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_PROTOCOLLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)");
|
||||||
SERIAL_PROTOCOLPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
|
SERIAL_PROTOCOLPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
|
||||||
if (Z_MIN_PROBE_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true");
|
|
||||||
else SERIAL_PROTOCOLLNPGM("false");
|
#if Z_MIN_PROBE_ENDSTOP_INVERTING
|
||||||
probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
|
SERIAL_PROTOCOLLNPGM("true");
|
||||||
#else
|
#else
|
||||||
#error "ERROR - probe pin not defined - strange, SANITY_CHECK should have caught this"
|
SERIAL_PROTOCOLLNPGM("false");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
SERIAL_PROTOCOLLNPGM(". deploy & stow 4 times");
|
SERIAL_PROTOCOLLNPGM(". deploy & stow 4 times");
|
||||||
pinMode(PROBE_TEST_PIN, INPUT_PULLUP);
|
pinMode(PROBE_TEST_PIN, INPUT_PULLUP);
|
||||||
bool deploy_state;
|
bool deploy_state;
|
||||||
@ -5883,7 +5907,9 @@ inline void gcode_M42() {
|
|||||||
stow_state = digitalRead(PROBE_TEST_PIN);
|
stow_state = digitalRead(PROBE_TEST_PIN);
|
||||||
}
|
}
|
||||||
if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards");
|
if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards");
|
||||||
|
|
||||||
refresh_cmd_timeout();
|
refresh_cmd_timeout();
|
||||||
|
|
||||||
if (deploy_state != stow_state) {
|
if (deploy_state != stow_state) {
|
||||||
SERIAL_PROTOCOLLNPGM("BLTouch clone detected");
|
SERIAL_PROTOCOLLNPGM("BLTouch clone detected");
|
||||||
if (deploy_state) {
|
if (deploy_state) {
|
||||||
@ -5904,28 +5930,39 @@ inline void gcode_M42() {
|
|||||||
safe_delay(500);
|
safe_delay(500);
|
||||||
SERIAL_PROTOCOLLNPGM("please trigger probe");
|
SERIAL_PROTOCOLLNPGM("please trigger probe");
|
||||||
uint16_t probe_counter = 0;
|
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
|
|
||||||
|
// Allow 30 seconds max for operator to trigger probe
|
||||||
|
for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) {
|
||||||
|
|
||||||
safe_delay(2);
|
safe_delay(2);
|
||||||
if ( 0 == j%(500*1)) {refresh_cmd_timeout(); watchdog_reset();} // beat the dog every 45 seconds
|
|
||||||
|
if (0 == j % (500 * 1)) // keep cmd_timeout happy
|
||||||
|
refresh_cmd_timeout();
|
||||||
|
|
||||||
if (deploy_state != digitalRead(PROBE_TEST_PIN)) { // probe triggered
|
if (deploy_state != digitalRead(PROBE_TEST_PIN)) { // probe triggered
|
||||||
for (probe_counter = 1; probe_counter < 50 && (deploy_state != digitalRead(PROBE_TEST_PIN)); probe_counter ++) {
|
|
||||||
|
for (probe_counter = 1; probe_counter < 50 && deploy_state != digitalRead(PROBE_TEST_PIN); ++probe_counter)
|
||||||
safe_delay(2);
|
safe_delay(2);
|
||||||
}
|
|
||||||
if (probe_counter == 50) {
|
if (probe_counter == 50)
|
||||||
SERIAL_PROTOCOLLNPGM("Z Servo Probe detected"); // >= 100mS active time
|
SERIAL_PROTOCOLLNPGM("Z Servo Probe detected"); // >= 100mS active time
|
||||||
}
|
else if (probe_counter >= 2)
|
||||||
else if (probe_counter >= 2 ) {
|
|
||||||
SERIAL_PROTOCOLLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2); // allow 4 - 100mS pulse
|
SERIAL_PROTOCOLLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2); // allow 4 - 100mS pulse
|
||||||
}
|
else
|
||||||
else {
|
|
||||||
SERIAL_PROTOCOLLNPGM("noise detected - please re-run test"); // less than 2mS pulse
|
SERIAL_PROTOCOLLNPGM("noise detected - please re-run test"); // less than 2mS pulse
|
||||||
}
|
|
||||||
servo[probe_index].move(z_servo_angle[1]); //stow
|
servo[probe_index].move(z_servo_angle[1]); //stow
|
||||||
|
|
||||||
} // pulse detected
|
} // pulse detected
|
||||||
|
|
||||||
} // for loop waiting for trigger
|
} // for loop waiting for trigger
|
||||||
|
|
||||||
if (probe_counter == 0) SERIAL_PROTOCOLLNPGM("trigger not detected");
|
if (probe_counter == 0) SERIAL_PROTOCOLLNPGM("trigger not detected");
|
||||||
|
|
||||||
} // measure active signal length
|
} // measure active signal length
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // servo_probe_test
|
} // servo_probe_test
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -5977,39 +6014,43 @@ inline void gcode_M42() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the range of pins to test or watch
|
// Get the range of pins to test or watch
|
||||||
int first_pin = 0, last_pin = NUM_DIGITAL_PINS - 1;
|
const uint8_t first_pin = code_seen('P') ? code_value_byte() : 0,
|
||||||
if (code_seen('P')) {
|
last_pin = code_seen('P') ? first_pin : NUM_DIGITAL_PINS - 1;
|
||||||
first_pin = last_pin = code_value_byte();
|
|
||||||
if (first_pin > NUM_DIGITAL_PINS - 1) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ignore_protection = code_seen('I') ? code_value_bool() : false;
|
if (first_pin > last_pin) return;
|
||||||
|
|
||||||
|
const bool ignore_protection = code_seen('I') && code_value_bool();
|
||||||
|
|
||||||
// Watch until click, M108, or reset
|
// Watch until click, M108, or reset
|
||||||
if (code_seen('W') && code_value_bool()) { // watch digital pins
|
if (code_seen('W') && code_value_bool()) {
|
||||||
SERIAL_PROTOCOLLNPGM("Watching pins");
|
SERIAL_PROTOCOLLNPGM("Watching pins");
|
||||||
byte pin_state[last_pin - first_pin + 1];
|
byte pin_state[last_pin - first_pin + 1];
|
||||||
for (int8_t pin = first_pin; pin <= last_pin; pin++) {
|
for (int8_t pin = first_pin; pin <= last_pin; pin++) {
|
||||||
if (pin_is_protected(pin) && !ignore_protection) continue;
|
if (pin_is_protected(pin) && !ignore_protection) continue;
|
||||||
pinMode(pin, INPUT_PULLUP);
|
pinMode(pin, INPUT_PULLUP);
|
||||||
// if (IS_ANALOG(pin))
|
/*
|
||||||
// pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
|
if (IS_ANALOG(pin))
|
||||||
// else
|
pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
|
||||||
|
else
|
||||||
|
//*/
|
||||||
pin_state[pin - first_pin] = digitalRead(pin);
|
pin_state[pin - first_pin] = digitalRead(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAS_RESUME_CONTINUE
|
#if HAS_RESUME_CONTINUE
|
||||||
wait_for_user = true;
|
wait_for_user = true;
|
||||||
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
for (int8_t pin = first_pin; pin <= last_pin; pin++) {
|
for (int8_t pin = first_pin; pin <= last_pin; pin++) {
|
||||||
if (pin_is_protected(pin)) continue;
|
if (pin_is_protected(pin)) continue;
|
||||||
byte val;
|
const byte val =
|
||||||
// if (IS_ANALOG(pin))
|
/*
|
||||||
// val = analogRead(pin - analogInputToDigitalPin(0)); // int16_t val
|
IS_ANALOG(pin)
|
||||||
// else
|
? analogRead(pin - analogInputToDigitalPin(0)) : // int16_t val
|
||||||
val = digitalRead(pin);
|
:
|
||||||
|
//*/
|
||||||
|
digitalRead(pin);
|
||||||
if (val != pin_state[pin - first_pin]) {
|
if (val != pin_state[pin - first_pin]) {
|
||||||
report_pin_state(pin);
|
report_pin_state(pin);
|
||||||
pin_state[pin - first_pin] = val;
|
pin_state[pin - first_pin] = val;
|
||||||
@ -6017,7 +6058,10 @@ inline void gcode_M42() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if HAS_RESUME_CONTINUE
|
#if HAS_RESUME_CONTINUE
|
||||||
if (!wait_for_user) break;
|
if (!wait_for_user) {
|
||||||
|
KEEPALIVE_STATE(IN_HANDLER);
|
||||||
|
break;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
safe_delay(500);
|
safe_delay(500);
|
||||||
|
@ -260,7 +260,6 @@ static void err_is_interrupt() {
|
|||||||
static void err_prob_interrupt() {
|
static void err_prob_interrupt() {
|
||||||
SERIAL_PROTOCOLPGM(" overflow interrupt enabled");
|
SERIAL_PROTOCOLPGM(" overflow interrupt enabled");
|
||||||
}
|
}
|
||||||
static void can_be_used() { SERIAL_PROTOCOLPGM(" can be used as PWM "); }
|
|
||||||
|
|
||||||
void com_print(uint8_t N, uint8_t Z) {
|
void com_print(uint8_t N, uint8_t Z) {
|
||||||
uint8_t *TCCRA = (uint8_t*) TCCR_A(N);
|
uint8_t *TCCRA = (uint8_t*) TCCR_A(N);
|
||||||
@ -325,9 +324,6 @@ void timer_prefix(uint8_t T, char L, uint8_t N) { // T - timer L - pwm n -
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void pwm_details(uint8_t pin) {
|
static void pwm_details(uint8_t pin) {
|
||||||
char buffer[20]; // for the sprintf statements
|
|
||||||
uint8_t WGM;
|
|
||||||
|
|
||||||
switch(digitalPinToTimer(pin)) {
|
switch(digitalPinToTimer(pin)) {
|
||||||
|
|
||||||
#if defined(TCCR0A) && defined(COM0A1)
|
#if defined(TCCR0A) && defined(COM0A1)
|
||||||
|
Loading…
Reference in New Issue
Block a user