Linear Algebra  arduino
Accessible implementations of linear algebra algorithms
ArduinoCout.hpp
Go to the documentation of this file.
1 #pragma once
2 
14 #include "ArduinoConfig.hpp"
15 
16 #ifndef NO_IOSTREAM_SUPPORT
17 
18 #ifdef ARDUINO_HAS_WORKING_COUT
19 
20 #include <iostream> // std::cout
21 
22 namespace arduino {
23 std::ostream &cout = std::cout;
24 } // namespace arduino
25 
26 #else
27 
28 #include <ostream> // std::ostream
29 #include <streambuf> // std::streambuf
30 
31 namespace arduino {
33 struct SerialBuf : std::streambuf {
34  std::streamsize xsputn(const std::streambuf::char_type *s,
35  std::streamsize n) override {
36  return Serial.write(s, n);
37  }
38  std::streambuf::int_type overflow(std::streambuf::int_type c) override {
39  Serial.write(char(c));
40  return 0; // TODO
41  }
42 } sbuf;
44 std::ostream cout(&sbuf);
45 } // namespace arduino
46 
47 #endif // ARDUINO_HAS_WORKING_COUT
48 
49 #endif // NO_IOSTREAM_SUPPORT
Preprocessor logic for configuring the library to make it compatible with the Arduino environment.
arduino::SerialBuf sbuf
Output stream that prints to the Serial monitor.
Definition: ArduinoCout.hpp:44
"Buffer" custom std::ostream that wraps the Serial output of the Arduino.
Definition: ArduinoCout.hpp:33
std::streambuf::int_type overflow(std::streambuf::int_type c) override
Definition: ArduinoCout.hpp:38
std::streamsize xsputn(const std::streambuf::char_type *s, std::streamsize n) override
Definition: ArduinoCout.hpp:34