From 2e20c53c9d3f1ef29a51db9030dd10b2be8c65fb Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 18 Sep 2017 05:55:09 -0500 Subject: [PATCH] Move endstop debug to Endstops --- Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h | 2 - Marlin/src/core/enum.h | 12 --- Marlin/src/gcode/config/M43.cpp | 4 +- Marlin/src/module/endstops.cpp | 87 ++++++++++++++++++++ Marlin/src/module/endstops.h | 43 ++++++++-- Marlin/src/module/temperature.cpp | 92 +--------------------- Marlin/src/pins/pinsDebug.h | 2 - 7 files changed, 126 insertions(+), 116 deletions(-) diff --git a/Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h b/Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h index 92e4f48ea..0e430beea 100644 --- a/Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h +++ b/Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h @@ -30,8 +30,6 @@ void HAL_analog_pin_state(char buffer[], int8_t pin) { sprintf(buffer, "Analog in =% 5d", analogRead(pin - analogInputToDigitalPin(0))); } -bool endstop_monitor_flag = false; - #define NAME_FORMAT "%-35s" // one place to specify the format of all the sources of names // "-" left justify, "28" minimum width of name, pad with blanks diff --git a/Marlin/src/core/enum.h b/Marlin/src/core/enum.h index 9170fd037..f70e0ac1e 100644 --- a/Marlin/src/core/enum.h +++ b/Marlin/src/core/enum.h @@ -69,18 +69,6 @@ typedef enum { TEMPUNIT_F } TempUnit; -enum EndstopEnum { - X_MIN, - Y_MIN, - Z_MIN, - Z_MIN_PROBE, - X_MAX, - Y_MAX, - Z_MAX, - Z2_MIN, - Z2_MAX -}; - #if ENABLED(EMERGENCY_PARSER) enum e_parser_state { state_RESET, diff --git a/Marlin/src/gcode/config/M43.cpp b/Marlin/src/gcode/config/M43.cpp index fd0d1c9c7..e64062e9e 100644 --- a/Marlin/src/gcode/config/M43.cpp +++ b/Marlin/src/gcode/config/M43.cpp @@ -245,9 +245,9 @@ void GcodeSuite::M43() { // Enable or disable endstop monitoring if (parser.seen('E')) { - endstop_monitor_flag = parser.value_bool(); + endstops.monitor_flag = parser.value_bool(); SERIAL_PROTOCOLPGM("endstop monitor "); - serialprintPGM(endstop_monitor_flag ? PSTR("en") : PSTR("dis")); + serialprintPGM(endstops.monitor_flag ? PSTR("en") : PSTR("dis")); SERIAL_PROTOCOLLNPGM("abled"); return; } diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index a7e4b7342..510f13df4 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -450,3 +450,90 @@ void Endstops::update() { old_endstop_bits = current_endstop_bits; } // Endstops::update() + +#if ENABLED(PINS_DEBUGGING) + + bool Endstops::monitor_flag = false; + + /** + * monitors endstops & Z probe for changes + * + * If a change is detected then the LED is toggled and + * a message is sent out the serial port + * + * Yes, we could miss a rapid back & forth change but + * that won't matter because this is all manual. + * + */ + void Endstops::monitor() { + + static uint16_t old_endstop_bits_local = 0; + static uint8_t local_LED_status = 0; + uint16_t current_endstop_bits_local = 0; + + #if HAS_X_MIN + if (READ(X_MIN_PIN)) SBI(current_endstop_bits_local, X_MIN); + #endif + #if HAS_X_MAX + if (READ(X_MAX_PIN)) SBI(current_endstop_bits_local, X_MAX); + #endif + #if HAS_Y_MIN + if (READ(Y_MIN_PIN)) SBI(current_endstop_bits_local, Y_MIN); + #endif + #if HAS_Y_MAX + if (READ(Y_MAX_PIN)) SBI(current_endstop_bits_local, Y_MAX); + #endif + #if HAS_Z_MIN + if (READ(Z_MIN_PIN)) SBI(current_endstop_bits_local, Z_MIN); + #endif + #if HAS_Z_MAX + if (READ(Z_MAX_PIN)) SBI(current_endstop_bits_local, Z_MAX); + #endif + #if HAS_Z_MIN_PROBE_PIN + if (READ(Z_MIN_PROBE_PIN)) SBI(current_endstop_bits_local, Z_MIN_PROBE); + #endif + #if HAS_Z2_MIN + if (READ(Z2_MIN_PIN)) SBI(current_endstop_bits_local, Z2_MIN); + #endif + #if HAS_Z2_MAX + if (READ(Z2_MAX_PIN)) SBI(current_endstop_bits_local, Z2_MAX); + #endif + + uint16_t endstop_change = current_endstop_bits_local ^ old_endstop_bits_local; + + if (endstop_change) { + #if HAS_X_MIN + if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", !!TEST(current_endstop_bits_local, X_MIN)); + #endif + #if HAS_X_MAX + if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", !!TEST(current_endstop_bits_local, X_MAX)); + #endif + #if HAS_Y_MIN + if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", !!TEST(current_endstop_bits_local, Y_MIN)); + #endif + #if HAS_Y_MAX + if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", !!TEST(current_endstop_bits_local, Y_MAX)); + #endif + #if HAS_Z_MIN + if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", !!TEST(current_endstop_bits_local, Z_MIN)); + #endif + #if HAS_Z_MAX + if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", !!TEST(current_endstop_bits_local, Z_MAX)); + #endif + #if HAS_Z_MIN_PROBE_PIN + if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", !!TEST(current_endstop_bits_local, Z_MIN_PROBE)); + #endif + #if HAS_Z2_MIN + if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", !!TEST(current_endstop_bits_local, Z2_MIN)); + #endif + #if HAS_Z2_MAX + if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", !!TEST(current_endstop_bits_local, Z2_MAX)); + #endif + SERIAL_PROTOCOLPGM("\n\n"); + analogWrite(LED_PIN, local_LED_status); + local_LED_status ^= 255; + old_endstop_bits_local = current_endstop_bits_local; + } + } + +#endif // PINS_DEBUGGING diff --git a/Marlin/src/module/endstops.h b/Marlin/src/module/endstops.h index d442eed0a..ddce06360 100644 --- a/Marlin/src/module/endstops.h +++ b/Marlin/src/module/endstops.h @@ -24,10 +24,23 @@ * endstops.h - manages endstops */ -#ifndef ENDSTOPS_H -#define ENDSTOPS_H - -#include "../core/enum.h" +#ifndef __ENDSTOPS_H__ +#define __ENDSTOPS_H__ + +#include "../inc/MarlinConfig.h" +#include + +enum EndstopEnum { + X_MIN, + Y_MIN, + Z_MIN, + Z_MIN_PROBE, + X_MAX, + Y_MAX, + Z_MAX, + Z2_MIN, + Z2_MAX +}; class Endstops { @@ -37,11 +50,12 @@ class Endstops { static volatile char endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value #if ENABLED(Z_DUAL_ENDSTOPS) - static uint16_t + typedef uint16_t esbits_t; #else - static byte + typedef byte esbits_t; #endif - current_endstop_bits, old_endstop_bits; + + static esbits_t current_endstop_bits, old_endstop_bits; Endstops() {}; @@ -83,6 +97,19 @@ class Endstops { static void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; } #endif + // Debugging of endstops + #if ENABLED(PINS_DEBUGGING) + static bool monitor_flag; + static void monitor(); + FORCE_INLINE static void run_monitor() { + if (!monitor_flag) return; + static uint8_t monitor_count = 16; // offset this check from the others + monitor_count += _BV(1); // 15 Hz + monitor_count &= 0x7F; + if (!monitor_count) monitor(); // report changes in endstop status + } + #endif + private: #if ENABLED(Z_DUAL_ENDSTOPS) @@ -99,4 +126,4 @@ extern Endstops endstops; #endif -#endif // ENDSTOPS_H +#endif // __ENDSTOPS_H__ diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 7ff161950..97f582461 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -39,7 +39,7 @@ #include "stepper.h" #endif -#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) +#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) || ENABLED(PINS_DEBUGGING) #include "endstops.h" #endif @@ -1561,87 +1561,6 @@ void Temperature::set_current_temp_raw() { temp_meas_ready = true; } -#if ENABLED(PINS_DEBUGGING) - /** - * monitors endstops & Z probe for changes - * - * If a change is detected then the LED is toggled and - * a message is sent out the serial port - * - * Yes, we could miss a rapid back & forth change but - * that won't matter because this is all manual. - * - */ - void endstop_monitor() { - static uint16_t old_endstop_bits_local = 0; - static uint8_t local_LED_status = 0; - uint16_t current_endstop_bits_local = 0; - #if HAS_X_MIN - if (READ(X_MIN_PIN)) SBI(current_endstop_bits_local, X_MIN); - #endif - #if HAS_X_MAX - if (READ(X_MAX_PIN)) SBI(current_endstop_bits_local, X_MAX); - #endif - #if HAS_Y_MIN - if (READ(Y_MIN_PIN)) SBI(current_endstop_bits_local, Y_MIN); - #endif - #if HAS_Y_MAX - if (READ(Y_MAX_PIN)) SBI(current_endstop_bits_local, Y_MAX); - #endif - #if HAS_Z_MIN - if (READ(Z_MIN_PIN)) SBI(current_endstop_bits_local, Z_MIN); - #endif - #if HAS_Z_MAX - if (READ(Z_MAX_PIN)) SBI(current_endstop_bits_local, Z_MAX); - #endif - #if HAS_Z_MIN_PROBE_PIN - if (READ(Z_MIN_PROBE_PIN)) SBI(current_endstop_bits_local, Z_MIN_PROBE); - #endif - #if HAS_Z2_MIN - if (READ(Z2_MIN_PIN)) SBI(current_endstop_bits_local, Z2_MIN); - #endif - #if HAS_Z2_MAX - if (READ(Z2_MAX_PIN)) SBI(current_endstop_bits_local, Z2_MAX); - #endif - - uint16_t endstop_change = current_endstop_bits_local ^ old_endstop_bits_local; - - if (endstop_change) { - #if HAS_X_MIN - if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", !!TEST(current_endstop_bits_local, X_MIN)); - #endif - #if HAS_X_MAX - if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", !!TEST(current_endstop_bits_local, X_MAX)); - #endif - #if HAS_Y_MIN - if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", !!TEST(current_endstop_bits_local, Y_MIN)); - #endif - #if HAS_Y_MAX - if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", !!TEST(current_endstop_bits_local, Y_MAX)); - #endif - #if HAS_Z_MIN - if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", !!TEST(current_endstop_bits_local, Z_MIN)); - #endif - #if HAS_Z_MAX - if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", !!TEST(current_endstop_bits_local, Z_MAX)); - #endif - #if HAS_Z_MIN_PROBE_PIN - if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", !!TEST(current_endstop_bits_local, Z_MIN_PROBE)); - #endif - #if HAS_Z2_MIN - if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", !!TEST(current_endstop_bits_local, Z2_MIN)); - #endif - #if HAS_Z2_MAX - if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", !!TEST(current_endstop_bits_local, Z2_MAX)); - #endif - SERIAL_PROTOCOLPGM("\n\n"); - analogWrite(LED_PIN, local_LED_status); - local_LED_status ^= 255; - old_endstop_bits_local = current_endstop_bits_local; - } - } -#endif // PINS_DEBUGGING - /** * Timer 0 is shared with millies so don't change the prescaler. * @@ -2157,14 +2076,7 @@ void Temperature::isr() { #endif // BABYSTEPPING #if ENABLED(PINS_DEBUGGING) - extern bool endstop_monitor_flag; - // run the endstop monitor at 15Hz - static uint8_t endstop_monitor_count = 16; // offset this check from the others - if (endstop_monitor_flag) { - endstop_monitor_count += _BV(1); // 15 Hz - endstop_monitor_count &= 0x7F; - if (!endstop_monitor_count) endstop_monitor(); // report changes in endstop status - } + endstops.run_monitor(); // report changes in endstop status #endif #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) diff --git a/Marlin/src/pins/pinsDebug.h b/Marlin/src/pins/pinsDebug.h index a061fc31b..895707790 100644 --- a/Marlin/src/pins/pinsDebug.h +++ b/Marlin/src/pins/pinsDebug.h @@ -20,8 +20,6 @@ * */ -bool endstop_monitor_flag = false; - #define MAX_NAME_LENGTH 35 // one place to specify the format of all the sources of names // "-" left justify, "35" minimum width of name, pad with blanks