File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,24 @@ int HardwareSerial::read(void)
131
131
return -1 ;
132
132
}
133
133
134
+ // read characters into buffer
135
+ // terminates if size characters have been read, or no further are pending
136
+ // returns the number of characters placed in the buffer
137
+ // the buffer is NOT null terminated.
138
+ size_t HardwareSerial::read (uint8_t *buffer, size_t size)
139
+ {
140
+ size_t count = 0 ;
141
+ while (count < size) {
142
+ int c = read ();
143
+ if (c < 0 ) {
144
+ break ;
145
+ }
146
+ *buffer++ = (char ) c;
147
+ count++;
148
+ }
149
+ return count;
150
+ }
151
+
134
152
void HardwareSerial::flush (void )
135
153
{
136
154
uartFlush (_uart);
Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ class HardwareSerial: public Stream
62
62
int availableForWrite (void );
63
63
int peek (void );
64
64
int read (void );
65
+ size_t read (uint8_t *buffer, size_t size);
66
+ inline size_t read (char * buffer, size_t size)
67
+ {
68
+ return read ((uint8_t *) buffer, size);
69
+ }
65
70
void flush (void );
66
71
void flush ( bool txOnly);
67
72
size_t write (uint8_t );
@@ -70,7 +75,6 @@ class HardwareSerial: public Stream
70
75
{
71
76
return write ((uint8_t *) buffer, size);
72
77
}
73
-
74
78
inline size_t write (const char * s)
75
79
{
76
80
return write ((uint8_t *) s, strlen (s));
You can’t perform that action at this time.
0 commit comments