Skip to content
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

Improve Arduino compatibility for Print and Stream #18

Merged
merged 1 commit into from
Mar 23, 2023
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
10 changes: 9 additions & 1 deletion cores/nRF5/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Print
void setWriteError(int err = 1) { write_error = err; }
public:
Print() : write_error(0) {}
virtual ~Print() {}

int getWriteError() { return write_error; }
void clearWriteError() { setWriteError(0); }
Expand All @@ -54,6 +55,10 @@ class Print
return write((const uint8_t *)buffer, size);
}

// add availableForWrite to make compatible with Arduino Print.h
// default to zero, meaning "a single write may block"
// should be overriden by subclasses with buffering
virtual int availableForWrite() { return 0; }
size_t print(const __FlashStringHelper *);
size_t print(const String &);
size_t print(const char[]);
Expand All @@ -78,7 +83,10 @@ class Print
size_t println(double, int = 2);
size_t println(const Printable&);
size_t println(void);
int printf(const char* format, ...);
int printf(const char* format, ...) __attribute__ ((format (printf, 2, 3)));

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

};

#endif
1 change: 1 addition & 0 deletions cores/nRF5/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Stream : public Print
// parsing methods

void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
unsigned long getTimeout(void) { return _timeout; }

bool find(char *target); // reads data from the stream until the target string is found
bool find(uint8_t *target) { return find ((char *)target); }
Expand Down