From dcf84169ae75b11c1656d45dbc6c626d93da6a10 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 8 Dec 2017 15:07:52 +0100 Subject: Add output support (broken on esp8266) --- include/esp8266/driver/stdout.h | 20 +++++++++++ include/msp430fr5969lp/driver/stdout.h | 19 ++++++++++ include/object/outputstream.h | 65 ++++++++++++++++++++++++++++++++++ include/posix/driver/stdout.h | 20 +++++++++++ 4 files changed, 124 insertions(+) create mode 100644 include/esp8266/driver/stdout.h create mode 100644 include/msp430fr5969lp/driver/stdout.h create mode 100644 include/object/outputstream.h create mode 100644 include/posix/driver/stdout.h (limited to 'include') diff --git a/include/esp8266/driver/stdout.h b/include/esp8266/driver/stdout.h new file mode 100644 index 0000000..9114501 --- /dev/null +++ b/include/esp8266/driver/stdout.h @@ -0,0 +1,20 @@ +#ifndef STANDARDOUTPUT_H +#define STANDANDOUTPUT_H + +#include "object/outputstream.h" + +class StandardOutput : public OutputStream { + private: + StandardOutput(const StandardOutput ©); + + public: + StandardOutput () {} + void setup(); + + virtual void put(char c) override; + virtual void write(const char *s) override; +}; + +extern StandardOutput kout; + +#endif diff --git a/include/msp430fr5969lp/driver/stdout.h b/include/msp430fr5969lp/driver/stdout.h new file mode 100644 index 0000000..d6cb2b0 --- /dev/null +++ b/include/msp430fr5969lp/driver/stdout.h @@ -0,0 +1,19 @@ +#ifndef STANDARDOUTPUT_H +#define STANDANDOUTPUT_H + +#include "object/outputstream.h" + +class StandardOutput : public OutputStream { + private: + StandardOutput(const StandardOutput ©); + + public: + StandardOutput () {} + void setup(); + + virtual void put(char c) override; +}; + +extern StandardOutput kout; + +#endif diff --git a/include/object/outputstream.h b/include/object/outputstream.h new file mode 100644 index 0000000..43e61f3 --- /dev/null +++ b/include/object/outputstream.h @@ -0,0 +1,65 @@ +#ifndef OUTPUTSTREAM_H +#define OUTPUTSTREAM_H + +#include + +class OutputStream { + private: + OutputStream(const OutputStream& copy); + + char digit_buffer[sizeof(long long) * 8]; + uint8_t base; + + public: + OutputStream(); + + virtual void put(char c) = 0; + + virtual void write(const char *s) { + while (*s) { + put(*s++); + } + } + + virtual void flush() {} + + OutputStream & operator<<(char c); + OutputStream & operator<<(unsigned char c); + OutputStream & operator<<(unsigned short number); + OutputStream & operator<<(short number); + OutputStream & operator<<(unsigned int number); + OutputStream & operator<<(int number); + OutputStream & operator<<(unsigned long number); + OutputStream & operator<<(long number); + OutputStream & operator<<(unsigned long long number); + OutputStream & operator<<(long long number); + OutputStream & operator<<(void *pointer); + OutputStream & operator<<(const char *text); + OutputStream & operator<<(OutputStream & (*fun) (OutputStream &)); + + void setBase(uint8_t b); +}; + + +// ENDL: new line character (and flush) +OutputStream & endl(OutputStream & os); + +// BIN: print numbers in binary form. +OutputStream & bin(OutputStream & os); + +// OCT: print numbers in octal form. +OutputStream & oct(OutputStream & os); + +// DEC: print numbers in decimal form. +OutputStream & dec(OutputStream & os); + +// HEX: print numbers in hexadecimal form. +OutputStream & hex(OutputStream & os); + +// FLUSH: flush OutputStream buffer +OutputStream & flush(OutputStream & os); + +// TERM: zero-termination +OutputStream & term(OutputStream & os); + +#endif //OUTPUTSTREAM_H diff --git a/include/posix/driver/stdout.h b/include/posix/driver/stdout.h new file mode 100644 index 0000000..cf8d881 --- /dev/null +++ b/include/posix/driver/stdout.h @@ -0,0 +1,20 @@ +#ifndef STANDARDOUTPUT_H +#define STANDANDOUTPUT_H + +#include "object/outputstream.h" + +class StandardOutput : public OutputStream { + private: + StandardOutput(const StandardOutput ©); + + public: + StandardOutput () {} + void setup() {} + + virtual void put(char c) override; + virtual void flush() override; +}; + +extern StandardOutput kout; + +#endif -- cgit v1.2.3