-
Notifications
You must be signed in to change notification settings - Fork 4
/
NeoTeeStream.h
57 lines (44 loc) · 1.28 KB
/
NeoTeeStream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef _NEOTEESTREAM_H_
#define _NEOTEESTREAM_H_
#include <NeoTee.h>
class NeoTeeStream : public Stream
{
NeoTee Prints;
public:
NeoTeeStream( Stream **streams, uint8_t numStreams )
: Prints( (Print **) streams, numStreams )
{};
Stream **Streams() const { return (Stream **) Prints.Streams(); };
uint8_t NumStreams() const { return Prints.NumStreams(); };
void NumStreams( uint8_t numStreams ) { Prints.NumStreams( numStreams ); };
// CAUTION: do not set numStreams longer than the original array!
virtual size_t write(uint8_t c) { return Prints.write( c ); };
using Stream::write; // make the other overloads visible
virtual void flush()
{
for (uint8_t i=0; i<NumStreams(); i++)
Streams()[ i ]->flush();
}
virtual int available()
{
int total = 0;
for (uint8_t i=0; i<NumStreams(); i++)
total += Streams()[ i ]->available();
return total;
}
virtual int read()
{
for (uint8_t i=0; i<NumStreams(); i++)
if (Streams()[ i ]->available())
return Streams()[ i ]->read();
return -1;
}
virtual int peek()
{
for (uint8_t i=0; i<NumStreams(); i++)
if (Streams()[ i ]->available())
return Streams()[ i ]->peek();
return -1;
}
};
#endif