From 51a00f59ea9ecb49471b30921f36821fdfa75bc4 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 14 Dec 2017 15:51:11 +0100 Subject: Add I2C and LM75 drivers --- src/os/object/outputstream.cc | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/os') diff --git a/src/os/object/outputstream.cc b/src/os/object/outputstream.cc index f308b56..31b0da4 100644 --- a/src/os/object/outputstream.cc +++ b/src/os/object/outputstream.cc @@ -2,7 +2,7 @@ OutputStream & OutputStream::operator<<(unsigned char c) { - put(c); + *this << (unsigned long long)c; return *this; } @@ -134,6 +134,41 @@ void OutputStream::setBase(uint8_t b) } } +static inline char format_hex_nibble(uint8_t num) +{ + if (num > 9) { + return 'a' + num - 10; + } + return '0' + num; +} + +void OutputStream::printf_uint8(uint8_t num) +{ + put(format_hex_nibble(num / 16)); + put(format_hex_nibble(num % 16)); +} + +void OutputStream::printf_float(float num) +{ + if (num < 0) { + put('-'); + num *= -1; + } + if (num > 1000) { + put('0' + (((int)num % 10000) / 1000)); + } + if (num > 100) { + put('0' + (((int)num % 1000) / 100)); + } + if (num > 10) { + put('0' + (((int)num % 100) / 10)); + } + put('0' + ((int)num % 10)); + put('.'); + put('0' + ((int)(num * 10) % 10)); + put('0' + ((int)(num * 100) % 10)); +} + // FLUSH OutputStream & flush(OutputStream & os) { -- cgit v1.2.3