Skip to content

Support both char* and uint8* in Stream and Print #1762

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 3 commits into from
Dec 30, 2013
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
2 changes: 1 addition & 1 deletion hardware/arduino/avr/cores/arduino/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ size_t Print::print(const __FlashStringHelper *ifsh)

size_t Print::print(const String &s)
{
return write(reinterpret_cast<const uint8_t*>(s.c_str()), s.length());
return write(s.c_str(), s.length());
}

size_t Print::print(const char str[])
Expand Down
3 changes: 3 additions & 0 deletions hardware/arduino/avr/cores/arduino/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class Print
return write((const uint8_t *)str, strlen(str));
}
virtual size_t write(const uint8_t *buffer, size_t size);
size_t write(const char *buffer, size_t size) {
return write((const uint8_t *)buffer, size);
}

size_t print(const __FlashStringHelper *);
size_t print(const String &);
Expand Down
6 changes: 6 additions & 0 deletions hardware/arduino/avr/cores/arduino/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ class Stream : public Print
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second

bool find(char *target); // reads data from the stream until the target string is found
bool find(uint8_t *target) { return find ((char *)target); }
// returns true if target string is found, false if timed out (see setTimeout)

bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
bool find(uint8_t *target, size_t length) { return find ((char *)target, length); }
// returns true if target string is found, false if timed out

bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); }

bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }


long parseInt(); // returns the first valid (long) integer value from the current position.
Expand All @@ -74,10 +78,12 @@ class Stream : public Print
float parseFloat(); // float version of parseInt

size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
// terminates if length characters have been read or timeout (see setTimeout)
// returns the number of characters placed in the buffer (0 means no valid data found)

size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
// terminates if length characters have been read, timeout, or if the terminator character detected
// returns the number of characters placed in the buffer (0 means no valid data found)

Expand Down
2 changes: 1 addition & 1 deletion hardware/arduino/sam/cores/arduino/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ size_t Print::print(const __FlashStringHelper *ifsh)

size_t Print::print(const String &s)
{
return write(reinterpret_cast<const uint8_t*>(s.c_str()), s.length());
return write(s.c_str(), s.length());
}

size_t Print::print(const char str[])
Expand Down
3 changes: 3 additions & 0 deletions hardware/arduino/sam/cores/arduino/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class Print
return write((const uint8_t *)str, strlen(str));
}
virtual size_t write(const uint8_t *buffer, size_t size);
size_t write(const char *buffer, size_t size) {
return write((const uint8_t *)buffer, size);
}

size_t print(const __FlashStringHelper *);
size_t print(const String &);
Expand Down
6 changes: 6 additions & 0 deletions hardware/arduino/sam/cores/arduino/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ class Stream : public Print
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second

bool find(char *target); // reads data from the stream until the target string is found
bool find(uint8_t *target) { return find ((char *)target); }
// returns true if target string is found, false if timed out (see setTimeout)

bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
bool find(uint8_t *target, size_t length) { return find ((char *)target, length); }
// returns true if target string is found, false if timed out

bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); }

bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }


long parseInt(); // returns the first valid (long) integer value from the current position.
Expand All @@ -74,10 +78,12 @@ class Stream : public Print
float parseFloat(); // float version of parseInt

size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
// terminates if length characters have been read or timeout (see setTimeout)
// returns the number of characters placed in the buffer (0 means no valid data found)

size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
// terminates if length characters have been read, timeout, or if the terminator character detected
// returns the number of characters placed in the buffer (0 means no valid data found)

Expand Down