Skip to content
Snippets Groups Projects
Commit 17a7c6d3 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

esp8266 stdout: add printf_uint8 and printf_float

parent 7b8c37d2
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,8 @@ class StandardOutput { ...@@ -14,6 +14,8 @@ class StandardOutput {
void put(char c); void put(char c);
void write(const char *s); void write(const char *s);
void flush() {} void flush() {}
void printf_uint8(unsigned char num);
void printf_float(float num);
StandardOutput & operator<<(char c); StandardOutput & operator<<(char c);
StandardOutput & operator<<(unsigned char c); StandardOutput & operator<<(unsigned char c);
......
...@@ -141,6 +141,41 @@ void StandardOutput::setBase(uint8_t b) ...@@ -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 // FLUSH
StandardOutput & flush(StandardOutput & os) StandardOutput & flush(StandardOutput & os)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment