Skip to content

Commit fc53df9

Browse files
authored
Merge pull request #4 from arduino-libraries/add-support-flash-strings
Add support for strings stored in flash
2 parents eb3238b + eee2fce commit fc53df9

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

Diff for: .travis.yml

-19
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,6 @@ matrix:
1010
- BOARD="arduino:samd:mkrwifi1010"
1111
- env:
1212
- BOARD="arduino:samd:mkrgsm1400"
13-
- env:
14-
- NAME=Code Formatting Check
15-
# must define an empty before_install phase, otherwise the default one is used
16-
before_install: true
17-
install:
18-
# install Artistic Style code formatter tool: http://astyle.sourceforge.net
19-
- |
20-
mkdir "${HOME}/astyle";
21-
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";
22-
tar --extract --file="${HOME}/astyle/astyle.tar.gz" --directory="${HOME}/astyle";
23-
cd "${HOME}/astyle/astyle/build/gcc";
24-
make;
25-
export PATH=$PWD/bin:$PATH;
26-
cd "$TRAVIS_BUILD_DIR"
27-
# download Arduino's Artistic Style configuration file
28-
- wget --directory-prefix="${HOME}/astyle" https://raw.githubusercontent.com/arduino/Arduino/master/build/shared/examples_formatter.conf
29-
script:
30-
# check code formatting
31-
- 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'
3213
- env:
3314
- NAME=Spell Check
3415
language: python

Diff for: src/Arduino_DebugUtils.cpp

+40-15
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,34 @@ void Arduino_DebugUtils::timestampOff() {
5858
_timestamp_on = false;
5959
}
6060

61-
void Arduino_DebugUtils::print(int const debug_level, const char * fmt, ...) {
62-
if (debug_level >= DBG_ERROR &&
63-
debug_level <= DBG_VERBOSE &&
64-
debug_level <= _debug_level) {
65-
if (_timestamp_on) {
66-
char timestamp[20];
67-
snprintf(timestamp, 20, "[ %lu ] ", millis());
68-
_debug_output_stream->print(timestamp);
69-
}
70-
71-
va_list args;
72-
va_start(args, fmt);
73-
vPrint(fmt, args);
74-
va_end(args);
75-
}
61+
void Arduino_DebugUtils::print(int const debug_level, const char * fmt, ...)
62+
{
63+
if (!shouldPrint(debug_level))
64+
return;
65+
66+
if (_timestamp_on)
67+
printTimestamp();
68+
69+
va_list args;
70+
va_start(args, fmt);
71+
vPrint(fmt, args);
72+
va_end(args);
73+
}
74+
75+
void Arduino_DebugUtils::print(int const debug_level, const __FlashStringHelper * fmt, ...)
76+
{
77+
if (!shouldPrint(debug_level))
78+
return;
79+
80+
if (_timestamp_on)
81+
printTimestamp();
82+
83+
String fmt_str(fmt);
84+
85+
va_list args;
86+
va_start(args, fmt_str.c_str());
87+
vPrint(fmt_str.c_str(), args);
88+
va_end(args);
7689
}
7790

7891
/******************************************************************************
@@ -88,6 +101,18 @@ void Arduino_DebugUtils::vPrint(char const * fmt, va_list args) {
88101
_debug_output_stream->println(msg_buf);
89102
}
90103

104+
void Arduino_DebugUtils::printTimestamp()
105+
{
106+
char timestamp[20];
107+
snprintf(timestamp, 20, "[ %lu ] ", millis());
108+
_debug_output_stream->print(timestamp);
109+
}
110+
111+
bool Arduino_DebugUtils::shouldPrint(int const debug_level) const
112+
{
113+
return ((debug_level >= DBG_ERROR) && (debug_level <= DBG_VERBOSE) && (debug_level <= _debug_level));
114+
}
115+
91116
/******************************************************************************
92117
CLASS INSTANTIATION
93118
******************************************************************************/

Diff for: src/Arduino_DebugUtils.h

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Arduino_DebugUtils {
5757
void timestampOff();
5858

5959
void print(int const debug_level, const char * fmt, ...);
60+
void print(int const debug_level, const __FlashStringHelper * fmt, ...);
6061

6162

6263
private:
@@ -66,6 +67,8 @@ class Arduino_DebugUtils {
6667
Stream * _debug_output_stream;
6768

6869
void vPrint(char const * fmt, va_list args);
70+
void printTimestamp();
71+
bool shouldPrint(int const debug_level) const;
6972

7073
};
7174

0 commit comments

Comments
 (0)