diff options
| author | Daniel Friesel <derf@finalrewind.org> | 2017-12-14 15:51:11 +0100 | 
|---|---|---|
| committer | Daniel Friesel <derf@finalrewind.org> | 2017-12-14 15:51:11 +0100 | 
| commit | 51a00f59ea9ecb49471b30921f36821fdfa75bc4 (patch) | |
| tree | 4c237974cf044d5a7067aba48070ad7f6e3c7d11 /src/os | |
| parent | 693afffd7b89507916ecd759767b0b7e947dca60 (diff) | |
Add I2C and LM75 drivers
Diffstat (limited to 'src/os')
| -rw-r--r-- | src/os/object/outputstream.cc | 37 | 
1 files changed, 36 insertions, 1 deletions
| 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)  { | 
