|
|
@ -78,13 +78,22 @@ struct SerialBase { |
|
|
|
FORCE_INLINE void write(const char* str) { while (*str) write(*str++); } |
|
|
|
FORCE_INLINE void write(const uint8_t* buffer, size_t size) { while (size--) write(*buffer++); } |
|
|
|
FORCE_INLINE void print(const char* str) { write(str); } |
|
|
|
NO_INLINE void print(char c, int base = 0) { print((long)c, base); } |
|
|
|
NO_INLINE void print(unsigned char c, int base = 0) { print((unsigned long)c, base); } |
|
|
|
NO_INLINE void print(int c, int base = DEC) { print((long)c, base); } |
|
|
|
NO_INLINE void print(unsigned int c, int base = DEC) { print((unsigned long)c, base); } |
|
|
|
void print(long c, int base = DEC) { if (!base) write(c); write((const uint8_t*)"-", c < 0); printNumber(c < 0 ? -c : c, base); } |
|
|
|
void print(unsigned long c, int base = DEC) { printNumber(c, base); } |
|
|
|
void print(double c, int digits = 2) { printFloat(c, digits); } |
|
|
|
NO_INLINE void print(char c, int base = 0) { print((long)c, base); } |
|
|
|
NO_INLINE void print(unsigned char c, int base = 0) { print((unsigned long)c, base); } |
|
|
|
NO_INLINE void print(int c, int base = DEC) { print((long)c, base); } |
|
|
|
NO_INLINE void print(unsigned int c, int base = DEC) { print((unsigned long)c, base); } |
|
|
|
void print(unsigned long c, int base = DEC) { printNumber(c, base); } |
|
|
|
void print(double c, int digits = 2) { printFloat(c, digits); } |
|
|
|
void print(long c, int base = DEC) { |
|
|
|
if (!base) { |
|
|
|
write(c); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (base == DEC && c < 0) { |
|
|
|
write((uint8_t)'-'); c = -c; |
|
|
|
} |
|
|
|
printNumber(c, base); |
|
|
|
} |
|
|
|
|
|
|
|
NO_INLINE void println(const char s[]) { print(s); println(); } |
|
|
|
NO_INLINE void println(char c, int base = 0) { print(c, base); println(); } |
|
|
@ -98,6 +107,10 @@ struct SerialBase { |
|
|
|
|
|
|
|
// Print a number with the given base
|
|
|
|
void printNumber(unsigned long n, const uint8_t base) { |
|
|
|
if (!base) { |
|
|
|
write((uint8_t)n); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (n) { |
|
|
|
unsigned char buf[8 * sizeof(long)]; // Enough space for base 2
|
|
|
|
int8_t i = 0; |
|
|
|