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:
DrZiplok 2011-06-12 22:26:39 +00:00
parent 7845bba097
commit 73004e45dc
4 changed files with 17 additions and 0 deletions

View File

@ -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);
}

View File

@ -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:

View File

@ -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;

View File

@ -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);