Skip to content

Commit 3d51b54

Browse files
committed
Some updates on Stream and Print class.
1 parent 0ee6248 commit 3d51b54

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

cores/arduino/Print.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ size_t Print::printFloat(double number, uint8_t digits)
238238

239239
// Print the decimal point, but only if there are digits beyond
240240
if (digits > 0) {
241-
n += print(".");
241+
n += print('.');
242242
}
243243

244244
// Extract digits from the remainder one at a time
245245
while (digits-- > 0)
246246
{
247247
remainder *= 10.0;
248-
unsigned int toPrint = (unsigned int)remainder;
248+
unsigned int toPrint = (unsigned int)(remainder);
249249
n += print(toPrint);
250250
remainder -= toPrint;
251251
}

cores/arduino/Print.h

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#define DEC 10
2929
#define HEX 16
3030
#define OCT 8
31+
#ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar
32+
#undef BIN
33+
#endif
3134
#define BIN 2
3235

3336
class Print
@@ -54,6 +57,10 @@ class Print
5457
return write((const uint8_t *)buffer, size);
5558
}
5659

60+
// default to zero, meaning "a single write may block"
61+
// should be overriden by subclasses with buffering
62+
virtual int availableForWrite() { return 0; }
63+
5764
size_t print(const __FlashStringHelper *);
5865
size_t print(const String &);
5966
size_t print(const char[]);
@@ -78,6 +85,8 @@ class Print
7885
size_t println(double, int = 2);
7986
size_t println(const Printable&);
8087
size_t println(void);
88+
89+
virtual void flush() { /* Empty implementation for backward compatibility */ }
8190
};
8291

8392
#endif

cores/arduino/Stream.h

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class Stream : public Print
5959
virtual int available() = 0;
6060
virtual int read() = 0;
6161
virtual int peek() = 0;
62-
virtual void flush() = 0;
6362

6463
Stream() {_timeout=1000;}
6564

0 commit comments

Comments
 (0)