Skip to content

Commit ef16cce

Browse files
committed
Add printf method with FlashStringHelper argument
1 parent b4f5e65 commit ef16cce

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

Diff for: cores/esp32/Print.cpp

+20-3
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ size_t Print::write(const uint8_t *buffer, size_t size)
4444
return n;
4545
}
4646

47-
size_t Print::printf(const char *format, ...)
47+
size_t Print::vprintf(const char *format, va_list arg)
4848
{
4949
char loc_buf[64];
5050
char * temp = loc_buf;
51-
va_list arg;
5251
va_list copy;
53-
va_start(arg, format);
5452
va_copy(copy, arg);
5553
int len = vsnprintf(temp, sizeof(loc_buf), format, copy);
5654
va_end(copy);
@@ -74,6 +72,25 @@ size_t Print::printf(const char *format, ...)
7472
return len;
7573
}
7674

75+
size_t Print::printf(const __FlashStringHelper *ifsh, ...)
76+
{
77+
va_list arg;
78+
va_start(arg, ifsh);
79+
const char * format = (reinterpret_cast<const char *>(ifsh));
80+
size_t ret = vprintf(format, arg);
81+
va_end(arg);
82+
return ret;
83+
}
84+
85+
size_t Print::printf(const char *format, ...)
86+
{
87+
va_list arg;
88+
va_start(arg, format);
89+
size_t ret = vprintf(format, arg);
90+
va_end(arg);
91+
return ret;
92+
}
93+
7794
size_t Print::print(const String &s)
7895
{
7996
return write(s.c_str(), s.length());

Diff for: cores/esp32/Print.h

+3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ class Print
7272
return write((const uint8_t *) buffer, size);
7373
}
7474

75+
size_t vprintf(const char *format, va_list arg);
76+
7577
size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));
78+
size_t printf(const __FlashStringHelper *ifsh, ...);
7679

7780
// add availableForWrite to make compatible with Arduino Print.h
7881
// default to zero, meaning "a single write may block"

0 commit comments

Comments
 (0)