Line data Source code
1 : /** 2 : * @brief [PrintStream library](https://github.com/tttapa/Arduino-PrintStream/blob/6a9e0d365be0b3d84187daa2a8a7bda8d541472e/src/PrintStream.h) 3 : */ 4 : 5 : #ifndef PrintStream_h 6 : #define PrintStream_h 7 : 8 : #include <AH/Arduino-Wrapper.h> // Print 9 : #include <AH/Settings/NamespaceSettings.hpp> 10 : 11 : BEGIN_AH_NAMESPACE 12 : 13 : /// @addtogroup AH_PrintStream 14 : /// @{ 15 : 16 : typedef Print &manipulator(Print &); 17 : 18 : Print &endl(Print &printer); 19 : Print &flush(Print &printer); 20 : Print &hex(Print &printer); 21 : Print &bin(Print &printer); 22 : Print &dec(Print &printer); 23 : /* Print &oct(Print &printer); */ 24 : Print &boolalpha(Print &printer); 25 : Print &noboolalpha(Print &printer); 26 : Print &leadingzeros(Print &printer); 27 : Print &noleadingzeros(Print &printer); 28 : Print &uppercase(Print &printer); 29 : Print &nouppercase(Print &printer); 30 : Print &showbase(Print &printer); 31 : Print &noshowbase(Print &printer); 32 : 33 : Print &operator<<(Print &printer, const __FlashStringHelper *s); 34 : #ifdef ARDUINO 35 : Print &operator<<(Print &printer, const String &s); 36 : #endif 37 : Print &operator<<(Print &printer, const char s[]); 38 : Print &operator<<(Print &printer, char c); 39 : Print &operator<<(Print &printer, unsigned char c); 40 : Print &operator<<(Print &printer, int i); 41 : Print &operator<<(Print &printer, unsigned int i); 42 : Print &operator<<(Print &printer, int8_t i); 43 : Print &operator<<(Print &printer, long i); 44 : Print &operator<<(Print &printer, unsigned long i); 45 : Print &operator<<(Print &printer, float f); 46 : Print &operator<<(Print &printer, double d); 47 : Print &operator<<(Print &printer, const Printable &p); 48 : Print &operator<<(Print &printer, bool b); 49 : 50 : Print &operator<<(Print &printer, manipulator pf); 51 : 52 : struct Setbase { 53 : uint8_t M_base; 54 : }; 55 : Setbase setbase(uint8_t base); 56 : Print &operator<<(Print &printer, Setbase f); 57 : 58 : struct Setprecision { 59 : int M_n; 60 : }; 61 : Setprecision setprecision(int n); 62 : Print &operator<<(Print &printer, Setprecision f); 63 : 64 : struct Setbytesep { 65 : char M_bytesep; 66 : }; 67 : Setbytesep setbytesep(char bytesep); 68 : Print &operator<<(Print &printer, Setbytesep f); 69 : 70 : struct HexDump { 71 2 : HexDump(const uint8_t *data, size_t length) : data(data), length(length) {} 72 : template <size_t N> 73 : explicit HexDump(const uint8_t (&data)[N]) : HexDump {data, N} {} 74 : const uint8_t *data; 75 : size_t length; 76 : }; 77 : 78 : Print &operator<<(Print &p, HexDump h); 79 : 80 : /// @} 81 : 82 : END_AH_NAMESPACE 83 : 84 : #ifndef ARDUINO 85 : 86 : #include <iomanip> 87 : #include <iostream> 88 : 89 : BEGIN_AH_NAMESPACE 90 : 91 : // TODO: check conflicts between Arduino version and C++ STL version 92 : using std::endl; 93 : // using std::setbase; 94 : // using std::setprecision; 95 : using std::boolalpha; 96 : using std::dec; 97 : using std::flush; 98 : using std::hex; 99 : using std::noboolalpha; 100 : using std::noshowbase; 101 : using std::nouppercase; 102 : using std::showbase; 103 : using std::uppercase; 104 : 105 2 : inline std::ostream &operator<<(std::ostream &os, uint8_t u) { 106 : // I'm lazy, I should probably implement one for uint8_t to get the leading 107 : // zeros right 108 2 : return os << static_cast<unsigned short>(u); 109 : } 110 : 111 48 : inline std::ostream &operator<<(std::ostream &os, 112 : const __FlashStringHelper *s) { 113 48 : return os << reinterpret_cast<const char *>(s); 114 : } 115 : 116 : std::ostream &operator<<(std::ostream &p, HexDump h); 117 : 118 : END_AH_NAMESPACE 119 : 120 : #endif 121 : 122 : #include <Settings/NamespaceSettings.hpp> 123 : 124 : BEGIN_CS_NAMESPACE 125 : using AH::operator<<; 126 : using AH::manipulator; 127 : using AH::endl; 128 : using AH::flush; 129 : using AH::hex; 130 : using AH::bin; 131 : using AH::dec; 132 : using AH::boolalpha; 133 : using AH::noboolalpha; 134 : using AH::leadingzeros; 135 : using AH::noleadingzeros; 136 : using AH::uppercase; 137 : using AH::nouppercase; 138 : using AH::showbase; 139 : using AH::noshowbase; 140 : using AH::setbase; 141 : using AH::setprecision; 142 : using AH::setbytesep; 143 : END_CS_NAMESPACE 144 : 145 : #endif // PrintStream_h