Skip to content

Some updates on Stream and Print class. #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2017
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
4 changes: 2 additions & 2 deletions cores/arduino/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ size_t Print::printFloat(double number, uint8_t digits)

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

// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
unsigned int toPrint = (unsigned int)remainder;
unsigned int toPrint = (unsigned int)(remainder);
n += print(toPrint);
remainder -= toPrint;
}
Expand Down
9 changes: 9 additions & 0 deletions cores/arduino/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#define DEC 10
#define HEX 16
#define OCT 8
#ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar
#undef BIN
#endif
#define BIN 2

class Print
Expand All @@ -54,6 +57,10 @@ class Print
return write((const uint8_t *)buffer, size);
}

// default to zero, meaning "a single write may block"
// should be overriden by subclasses with buffering
virtual int availableForWrite() { return 0; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make Uart:: availableForWrite() virtual as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes... good point...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for I2S, those are the only two spots in the repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on testing, adding the virtual doesn't seem to make a difference, we just needed to change the size_t to int in I2S.


size_t print(const __FlashStringHelper *);
size_t print(const String &);
size_t print(const char[]);
Expand All @@ -78,6 +85,8 @@ class Print
size_t println(double, int = 2);
size_t println(const Printable&);
size_t println(void);

virtual void flush() { /* Empty implementation for backward compatibility */ }
};

#endif
1 change: 0 additions & 1 deletion cores/arduino/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class Stream : public Print
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;
virtual void flush() = 0;

Stream() {_timeout=1000;}

Expand Down
2 changes: 1 addition & 1 deletion libraries/I2S/src/I2S.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ size_t I2SClass::write(const uint8_t *buffer, size_t size)
return write((const void*)buffer, size);
}

size_t I2SClass::availableForWrite()
int I2SClass::availableForWrite()
{
if (_state != I2S_STATE_TRANSMITTER) {
enableTransmitter();
Expand Down
2 changes: 1 addition & 1 deletion libraries/I2S/src/I2S.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class I2SClass : public Stream
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buffer, size_t size);

virtual size_t availableForWrite();
virtual int availableForWrite();

int read(void* buffer, size_t size);

Expand Down