Skip to content

Commit 0b72c88

Browse files
committed
Merge pull request #1762 from matthijskooijman/ide-1.5.x-write-char
Support both char* and uint8* in Stream and Print
2 parents dd7e0ee + 2ea12d0 commit 0b72c88

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

hardware/arduino/avr/cores/arduino/Print.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ size_t Print::print(const __FlashStringHelper *ifsh)
5353

5454
size_t Print::print(const String &s)
5555
{
56-
return write(reinterpret_cast<const uint8_t*>(s.c_str()), s.length());
56+
return write(s.c_str(), s.length());
5757
}
5858

5959
size_t Print::print(const char str[])

hardware/arduino/avr/cores/arduino/Print.h

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class Print
5151
return write((const uint8_t *)str, strlen(str));
5252
}
5353
virtual size_t write(const uint8_t *buffer, size_t size);
54+
size_t write(const char *buffer, size_t size) {
55+
return write((const uint8_t *)buffer, size);
56+
}
5457

5558
size_t print(const __FlashStringHelper *);
5659
size_t print(const String &);

hardware/arduino/avr/cores/arduino/Stream.h

+6
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ class Stream : public Print
5757
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
5858

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

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

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

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

6973

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

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

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

hardware/arduino/sam/cores/arduino/Print.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ size_t Print::print(const __FlashStringHelper *ifsh)
4646

4747
size_t Print::print(const String &s)
4848
{
49-
return write(reinterpret_cast<const uint8_t*>(s.c_str()), s.length());
49+
return write(s.c_str(), s.length());
5050
}
5151

5252
size_t Print::print(const char str[])

hardware/arduino/sam/cores/arduino/Print.h

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class Print
5151
return write((const uint8_t *)str, strlen(str));
5252
}
5353
virtual size_t write(const uint8_t *buffer, size_t size);
54+
size_t write(const char *buffer, size_t size) {
55+
return write((const uint8_t *)buffer, size);
56+
}
5457

5558
size_t print(const __FlashStringHelper *);
5659
size_t print(const String &);

hardware/arduino/sam/cores/arduino/Stream.h

+6
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ class Stream : public Print
5757
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
5858

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

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

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

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

6973

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

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

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

0 commit comments

Comments
 (0)