Line data Source code
1 : #pragma once
2 :
3 : #include <AH/Arduino-Wrapper.h> // Stream
4 : #include <Settings/NamespaceSettings.hpp>
5 :
6 : BEGIN_CS_NAMESPACE
7 :
8 : /**
9 : * @brief Helper that pulls bytes out of an Arduino stream.
10 : *
11 : * @ingroup MIDIParsers
12 : */
13 : class StreamPuller {
14 : public:
15 31 : StreamPuller(Stream &stream) : stream(stream) {}
16 :
17 : /// Pull a byte out of the stream.
18 : /// @param[out] c
19 : /// A new character from the stream (if available).
20 : /// @return True if a character was available, false otherwise.
21 351 : bool pull(uint8_t &c) {
22 351 : int read = stream.read();
23 351 : if (read >= 0)
24 346 : c = read;
25 351 : return read >= 0;
26 : }
27 :
28 : Stream &stream;
29 : };
30 :
31 : END_CS_NAMESPACE
|