Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 40 additions & 15 deletions src/Arduino_DebugUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/******************************************************************************
Expand All @@ -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
******************************************************************************/
Expand Down
3 changes: 3 additions & 0 deletions src/Arduino_DebugUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;

};

Expand Down