aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cores/arduino/HardwareSerial.cpp15
-rw-r--r--cores/arduino/HardwareSerial.h1
-rw-r--r--cores/arduino/Stream.cpp2
3 files changed, 17 insertions, 1 deletions
diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp
index ed29641..29a3366 100644
--- a/cores/arduino/HardwareSerial.cpp
+++ b/cores/arduino/HardwareSerial.cpp
@@ -176,6 +176,21 @@ int HardwareSerial::read(void)
}
}
+int HardwareSerial::availableForWrite(void)
+{
+#if (SERIAL_TX_BUFFER_SIZE>256)
+ uint8_t oldSREG = SREG;
+ cli();
+#endif
+ tx_buffer_index_t head = _tx_buffer_head;
+ tx_buffer_index_t tail = _tx_buffer_tail;
+#if (SERIAL_TX_BUFFER_SIZE>256)
+ SREG = oldSREG;
+#endif
+ if (head >= tail) return SERIAL_TX_BUFFER_SIZE - 1 - head + tail;
+ return tail - head - 1;
+}
+
void HardwareSerial::flush()
{
// If we have never written a byte, no need to flush. This special
diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h
index b96e5d0..935934b 100644
--- a/cores/arduino/HardwareSerial.h
+++ b/cores/arduino/HardwareSerial.h
@@ -112,6 +112,7 @@ class HardwareSerial : public Stream
virtual int available(void);
virtual int peek(void);
virtual int read(void);
+ int availableForWrite(void);
virtual void flush(void);
virtual size_t write(uint8_t);
inline size_t write(unsigned long n) { return write((uint8_t)n); }
diff --git a/cores/arduino/Stream.cpp b/cores/arduino/Stream.cpp
index 39873aa..9c581be 100644
--- a/cores/arduino/Stream.cpp
+++ b/cores/arduino/Stream.cpp
@@ -75,7 +75,7 @@ void Stream::setTimeout(unsigned long timeout) // sets the maximum number of mi
// find returns true if the target string is found
bool Stream::find(char *target)
{
- return findUntil(target, "");
+ return findUntil(target, (char*)"");
}
// reads data from the stream until the target string of given length is found