Add a method to BetterStream and FastSerial that can be used to report
the amount of data that can be written without blocking. git-svn-id: https://arducopter.googlecode.com/svn/trunk@2549 f9c3cf11-9bcb-44bc-f272-b75c42450872
This commit is contained in:
parent
7845bba097
commit
73004e45dc
@ -12,6 +12,7 @@
|
||||
// Enhancements to the Arduino Stream class.
|
||||
//
|
||||
|
||||
#include <limits.h>
|
||||
#include "BetterStream.h"
|
||||
|
||||
// Stream extensions////////////////////////////////////////////////////////////
|
||||
@ -52,3 +53,9 @@ BetterStream::_printf_P(const prog_char *fmt, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
int
|
||||
BetterStream::space(void)
|
||||
{
|
||||
// by default claim that there is always space
|
||||
return(INT_MAX);
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ public:
|
||||
void _printf_P(const prog_char *, ...);
|
||||
__attribute__ ((format(__printf__, 2, 3)));
|
||||
|
||||
virtual int space(void);
|
||||
|
||||
#define printf_P(fmt, ...) _printf_P((const prog_char *)fmt, ## __VA_ARGS__)
|
||||
|
||||
private:
|
||||
|
@ -142,6 +142,13 @@ int FastSerial::available(void)
|
||||
return ((_rxBuffer->head - _rxBuffer->tail) & _rxBuffer->mask);
|
||||
}
|
||||
|
||||
int FastSerial::space(void)
|
||||
{
|
||||
if (!_open)
|
||||
return (-1);
|
||||
return (((_rxBuffer->tail - _rxBuffer->head) & _rxBuffer->mask) - 1);
|
||||
}
|
||||
|
||||
int FastSerial::read(void)
|
||||
{
|
||||
uint8_t c;
|
||||
|
@ -110,6 +110,7 @@ public:
|
||||
virtual void begin(long baud);
|
||||
virtual void end(void);
|
||||
virtual int available(void);
|
||||
virtual int space(void);
|
||||
virtual int read(void);
|
||||
virtual int peek(void);
|
||||
virtual void flush(void);
|
||||
|
Loading…
Reference in New Issue
Block a user