diff --git a/.travis.yml b/.travis.yml index 17a2d81..8c6cbef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,25 +10,6 @@ matrix: - BOARD="arduino:samd:mkrwifi1010" - env: - BOARD="arduino:samd:mkrgsm1400" - - env: - - NAME=Code Formatting Check - # must define an empty before_install phase, otherwise the default one is used - before_install: true - install: - # install Artistic Style code formatter tool: http://astyle.sourceforge.net - - | - mkdir "${HOME}/astyle"; - wget --no-verbose --output-document="${HOME}/astyle/astyle.tar.gz" "https://iweb.dl.sourceforge.net/project/astyle/astyle/astyle%203.1/astyle_3.1_linux.tar.gz"; - tar --extract --file="${HOME}/astyle/astyle.tar.gz" --directory="${HOME}/astyle"; - cd "${HOME}/astyle/astyle/build/gcc"; - make; - export PATH=$PWD/bin:$PATH; - cd "$TRAVIS_BUILD_DIR" - # download Arduino's Artistic Style configuration file - - wget --directory-prefix="${HOME}/astyle" https://raw.githubusercontent.com/arduino/Arduino/master/build/shared/examples_formatter.conf - script: - # check code formatting - - find . -regextype posix-extended -path './.git' -prune -or \( -iregex '.*\.((ino)|(h)|(hpp)|(hh)|(hxx)|(h\+\+)|(cpp)|(cc)|(cxx)|(c\+\+)|(cp)|(c)|(ipp)|(ii)|(ixx)|(inl)|(tpp)|(txx)|(tpl))$' -and -type f \) -print0 | xargs -0 -L1 bash -c 'if ! diff "$0" <(astyle --options=${HOME}/astyle/examples_formatter.conf --dry-run < "$0"); then echo "Non-compliant code formatting in $0"; false; fi' - env: - NAME=Spell Check language: python diff --git a/src/Arduino_DebugUtils.cpp b/src/Arduino_DebugUtils.cpp index 09c2c37..63c9444 100644 --- a/src/Arduino_DebugUtils.cpp +++ b/src/Arduino_DebugUtils.cpp @@ -58,21 +58,34 @@ void Arduino_DebugUtils::timestampOff() { _timestamp_on = false; } -void Arduino_DebugUtils::print(int const debug_level, const char * fmt, ...) { - if (debug_level >= DBG_ERROR && - debug_level <= DBG_VERBOSE && - debug_level <= _debug_level) { - if (_timestamp_on) { - char timestamp[20]; - snprintf(timestamp, 20, "[ %lu ] ", millis()); - _debug_output_stream->print(timestamp); - } - - va_list args; - va_start(args, fmt); - vPrint(fmt, args); - va_end(args); - } +void Arduino_DebugUtils::print(int const debug_level, const char * fmt, ...) +{ + if (!shouldPrint(debug_level)) + return; + + if (_timestamp_on) + printTimestamp(); + + va_list args; + va_start(args, fmt); + vPrint(fmt, args); + va_end(args); +} + +void Arduino_DebugUtils::print(int const debug_level, const __FlashStringHelper * fmt, ...) +{ + if (!shouldPrint(debug_level)) + return; + + if (_timestamp_on) + printTimestamp(); + + String fmt_str(fmt); + + va_list args; + va_start(args, fmt_str.c_str()); + vPrint(fmt_str.c_str(), args); + va_end(args); } /****************************************************************************** @@ -88,6 +101,18 @@ void Arduino_DebugUtils::vPrint(char const * fmt, va_list args) { _debug_output_stream->println(msg_buf); } +void Arduino_DebugUtils::printTimestamp() +{ + char timestamp[20]; + snprintf(timestamp, 20, "[ %lu ] ", millis()); + _debug_output_stream->print(timestamp); +} + +bool Arduino_DebugUtils::shouldPrint(int const debug_level) const +{ + return ((debug_level >= DBG_ERROR) && (debug_level <= DBG_VERBOSE) && (debug_level <= _debug_level)); +} + /****************************************************************************** CLASS INSTANTIATION ******************************************************************************/ diff --git a/src/Arduino_DebugUtils.h b/src/Arduino_DebugUtils.h index 77bfe45..bfbb41d 100644 --- a/src/Arduino_DebugUtils.h +++ b/src/Arduino_DebugUtils.h @@ -57,6 +57,7 @@ class Arduino_DebugUtils { void timestampOff(); void print(int const debug_level, const char * fmt, ...); + void print(int const debug_level, const __FlashStringHelper * fmt, ...); private: @@ -66,6 +67,8 @@ class Arduino_DebugUtils { Stream * _debug_output_stream; void vPrint(char const * fmt, va_list args); + void printTimestamp(); + bool shouldPrint(int const debug_level) const; };