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