diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/arch/esp8266/driver/stdout.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/arch/esp8266/driver/stdout.cc b/src/arch/esp8266/driver/stdout.cc index 9638a81..2064b38 100644 --- a/src/arch/esp8266/driver/stdout.cc +++ b/src/arch/esp8266/driver/stdout.cc @@ -141,6 +141,41 @@ void StandardOutput::setBase(uint8_t b) } } +static inline char format_hex_nibble(uint8_t num) +{ + if (num > 9) { + return 'a' + num - 10; + } + return '0' + num; +} + +void StandardOutput::printf_uint8(uint8_t num) +{ + put(format_hex_nibble(num / 16)); + put(format_hex_nibble(num % 16)); +} + +void StandardOutput::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 StandardOutput & flush(StandardOutput & os) { |