Shrink debug code in Stopwatch and disable by default

master
Scott Lahteine 9 years ago
parent e523a0dc61
commit 21a6b66807

@ -28,7 +28,10 @@ Stopwatch::Stopwatch() {
}
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

@ -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

Loading…
Cancel
Save