From ee9bd66a68a1335cfd65265b941acf598ce6c7a8 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 20 Apr 2016 12:19:37 -0700 Subject: [PATCH 1/4] Add comments to debug bit flags --- Marlin/Marlin.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 7c4096205..cc08d724b 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -233,12 +233,12 @@ void kill(const char*); */ enum DebugFlags { DEBUG_NONE = 0, - DEBUG_ECHO = _BV(0), - DEBUG_INFO = _BV(1), - DEBUG_ERRORS = _BV(2), - DEBUG_DRYRUN = _BV(3), - DEBUG_COMMUNICATION = _BV(4), - DEBUG_LEVELING = _BV(5) + DEBUG_ECHO = _BV(0), ///< Echo commands in order as they are processed + DEBUG_INFO = _BV(1), ///< Print messages for code that has debug output + DEBUG_ERRORS = _BV(2), ///< Not implemented + DEBUG_DRYRUN = _BV(3), ///< Ignore temperature setting and E movement commands + DEBUG_COMMUNICATION = _BV(4), ///< Not implemented + DEBUG_LEVELING = _BV(5) ///< Print detailed output for homing and leveling }; extern uint8_t marlin_debug_flags; #define DEBUGGING(F) (marlin_debug_flags & (DEBUG_## F)) From e523a0dc616550b1394c2a5edc0b2772f64ca1e1 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 20 Apr 2016 12:34:55 -0700 Subject: [PATCH 2/4] Fix bug in TWIBus ctor declaration --- Marlin/twibus.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/twibus.cpp b/Marlin/twibus.cpp index 84d69df74..d17648cec 100644 --- a/Marlin/twibus.cpp +++ b/Marlin/twibus.cpp @@ -28,7 +28,7 @@ #include -TWIBus::twibus() { +TWIBus::TWIBus() { Wire.begin(); // We use no address so we will join the BUS as the master this->reset(); } From 21a6b66807446ca2fd7e3225033045e36e3d6ee8 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 20 Apr 2016 12:35:37 -0700 Subject: [PATCH 3/4] Shrink debug code in Stopwatch and disable by default --- Marlin/stopwatch.cpp | 35 +++++++++++++++++++++++++++++------ Marlin/stopwatch.h | 21 ++++++++++++++++++--- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Marlin/stopwatch.cpp b/Marlin/stopwatch.cpp index 5bc0a280f..60d556a4f 100644 --- a/Marlin/stopwatch.cpp +++ b/Marlin/stopwatch.cpp @@ -24,11 +24,14 @@ #include "stopwatch.h" Stopwatch::Stopwatch() { - this->reset(); - } + this->reset(); +} void Stopwatch::stop() { - if (DEBUGGING(INFO)) SERIAL_ECHOLNPGM("Stopwatch::stop()"); + #if ENABLED(DEBUG_STOPWATCH) + debug(PSTR("stop")); + #endif + if (!this->isRunning()) return; this->status = STPWTCH_STOPPED; @@ -36,7 +39,10 @@ void Stopwatch::stop() { } void Stopwatch::pause() { - if (DEBUGGING(INFO)) SERIAL_ECHOLNPGM("Stopwatch::pause()"); + #if ENABLED(DEBUG_STOPWATCH) + debug(PSTR("pause")); + #endif + if (!this->isRunning()) return; this->status = STPWTCH_PAUSED; @@ -44,7 +50,10 @@ void Stopwatch::pause() { } void Stopwatch::start() { - if (DEBUGGING(INFO)) SERIAL_ECHOLNPGM("Stopwatch::start()"); + #if ENABLED(DEBUG_STOPWATCH) + debug(PSTR("start")); + #endif + if (this->isRunning()) return; if (this->isPaused()) this->accumulator = this->duration(); @@ -55,7 +64,9 @@ void Stopwatch::start() { } void Stopwatch::reset() { - if (DEBUGGING(INFO)) SERIAL_ECHOLNPGM("Stopwatch::reset()"); + #if ENABLED(DEBUG_STOPWATCH) + debug(PSTR("reset")); + #endif this->status = STPWTCH_STOPPED; this->startTimestamp = 0; @@ -75,3 +86,15 @@ uint16_t Stopwatch::duration() { return (((this->isRunning()) ? millis() : this->stopTimestamp) - this->startTimestamp) / 1000 + this->accumulator; } + +#if ENABLED(DEBUG_STOPWATCH) + + void Stopwatch::debug(const char func[]) { + if (DEBUGGING(INFO)) { + SERIAL_ECHOPGM("Stopwatch::"); + serialprintPGM(func); + SERIAL_ECHOLNPGM("()"); + } + } + +#endif diff --git a/Marlin/stopwatch.h b/Marlin/stopwatch.h index d6ef8a744..53c0f149f 100644 --- a/Marlin/stopwatch.h +++ b/Marlin/stopwatch.h @@ -23,10 +23,15 @@ #ifndef STOPWATCH_H #define STOPWATCH_H +#include "macros.h" + +// Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM) +//#define DEBUG_STOPWATCH + enum StopwatchStatus { - STPWTCH_STOPPED = 0x0, - STPWTCH_RUNNING = 0x1, - STPWTCH_PAUSED = 0x2 + STPWTCH_STOPPED, + STPWTCH_RUNNING, + STPWTCH_PAUSED }; /** @@ -94,6 +99,16 @@ class Stopwatch { * @return uint16_t */ uint16_t duration(); + + #if ENABLED(DEBUG_STOPWATCH) + + /** + * @brief Prints a debug message + * @details Prints a simple debug message "Stopwatch::function" + */ + static void debug(const char func[]); + + #endif }; #endif //STOPWATCH_H From 1addb50b6282bce364ff60da0c31dae6041580b1 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 20 Apr 2016 12:35:56 -0700 Subject: [PATCH 4/4] Shrink debug code in TWIBus and disable by default --- Marlin/twibus.cpp | 40 +++++++++++++++++++++++++++------------- Marlin/twibus.h | 15 +++++++++++++++ 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/Marlin/twibus.cpp b/Marlin/twibus.cpp index d17648cec..c1d6008dd 100644 --- a/Marlin/twibus.cpp +++ b/Marlin/twibus.cpp @@ -42,25 +42,26 @@ void TWIBus::reset() { void TWIBus::address(uint8_t addr) { this->addr = addr; - if (DEBUGGING(INFO)) { - SERIAL_ECHOPAIR("TWIBus::sendto: ", this->addr); - SERIAL_EOL; - } + #if ENABLED(DEBUG_TWIBUS) + debug(PSTR("sendto"), this->addr); + #endif } void TWIBus::addbyte(char c) { if (buffer_s >= sizeof(this->buffer)) return; this->buffer[this->buffer_s++] = c; - if (DEBUGGING(INFO)) { - SERIAL_ECHOPAIR("TWIBus::addbyte: ", this->buffer[this->buffer_s -1]); - SERIAL_EOL; - } + #if ENABLED(DEBUG_TWIBUS) + debug(PSTR("addbyte"), this->buffer[this->buffer_s - 1]); + #endif } void TWIBus::send() { if (!this->addr) return; - if (DEBUGGING(INFO)) SERIAL_ECHOLNPGM("TWIBus::send()"); + + #if ENABLED(DEBUG_TWIBUS) + debug(PSTR("send()")); + #endif Wire.beginTransmission(this->addr); Wire.write(this->buffer, this->buffer_s); @@ -72,10 +73,10 @@ void TWIBus::send() { void TWIBus::reqbytes(uint8_t bytes) { if (!this->addr) return; - if (DEBUGGING(INFO)) { - SERIAL_ECHOPAIR("TWIBus::reqbytes(): ", bytes); - SERIAL_EOL; - } + + #if ENABLED(DEBUG_TWIBUS) + debug(PSTR("reqbytes"), bytes); + #endif millis_t t = millis() + this->timeout; Wire.requestFrom(this->addr, bytes); @@ -101,4 +102,17 @@ void TWIBus::reqbytes(uint8_t bytes) { this->reset(); } +#if ENABLED(DEBUG_TWIBUS) + + void TWIBus::debug(const char func[], int32_t val/*=-1*/) { + if (DEBUGGING(INFO)) { + SERIAL_ECHOPGM("TWIBus::"); + serialprintPGM(func); + if (val >= 0) SERIAL_ECHOPAIR(": ", val); + SERIAL_EOL; + } + } + +#endif + #endif //EXPERIMENTAL_I2CBUS diff --git a/Marlin/twibus.h b/Marlin/twibus.h index 5ab725777..d0d0e0ff3 100644 --- a/Marlin/twibus.h +++ b/Marlin/twibus.h @@ -23,6 +23,11 @@ #ifndef TWIBUS_H #define TWIBUS_H +#include "macros.h" + +// Print debug messages with M111 S2 (Uses 236 bytes of PROGMEM) +//#define DEBUG_TWIBUS + /** * TWIBUS class * @@ -117,6 +122,16 @@ class TWIBus { * @param bytes the number of bytes to request */ void reqbytes(uint8_t bytes); + + #if ENABLED(DEBUG_TWIBUS) + + /** + * @brief Prints a debug message + * @details Prints a simple debug message "TWIBus::function: value" + */ + static void debug(const char func[], int32_t val = -1); + + #endif }; #endif //TWIBUS_H