Using std::ostream with TextLCD

Dependencies:   ACM1602NI TextLCD

Dependents:   TextLCD_ostream_sample

This is class library inherited std::ostream for TextLCD
Because a large amount of memory is needed, do not work in low memory MPU

Sample program is here. And notebook page is here (sorry notebook page is only in Japanese)

Files at this revision

API Documentation at this revision

Comitter:
jk1lot
Date:
Sat Jun 18 08:57:07 2016 +0000
Child:
1:e46139d4b8ba
Commit message:
1st version

Changed in this revision

TextLCD_ostream.cpp Show annotated file Show diff for this revision Revisions of this file
TextLCD_ostream.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD_ostream.cpp	Sat Jun 18 08:57:07 2016 +0000
@@ -0,0 +1,30 @@
+#include "TextLCD_ostream.h"
+
+int lcd_streambuf::overflow(int c)
+{
+    if( c != EOF ) _lcd->putc(c);
+    return c;
+}
+
+lcd_ostream::lcd_ostream(TextLCD_Base *lcd) : std::ostream( lcd_buf )
+{
+    _lcd=lcd;
+    lcd_buf = new lcd_streambuf(lcd);
+}
+
+lcd_ostream::~lcd_ostream()
+{
+    delete lcd_buf;
+}
+
+lcd_ostream& lcd_ostream::locate(int column, int row)
+{
+    _lcd->locate(column,row);
+    return *this;
+}
+
+lcd_ostream& lcd_ostream::cls()
+{
+    _lcd->cls();
+    return *this;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD_ostream.h	Sat Jun 18 08:57:07 2016 +0000
@@ -0,0 +1,29 @@
+#ifndef TEXTLCD_OSTREAM_H
+#define TEXTLCD_OSTREAM_H
+
+#include "TextLCD.h"
+#include<iostream>
+#include<fstream>
+#include <streambuf>
+
+class lcd_streambuf : public std::streambuf {
+public:
+    lcd_streambuf(TextLCD_Base *lcd) : _lcd(lcd) {}
+    virtual int overflow( int c = EOF );
+private:
+    TextLCD_Base *_lcd;
+};
+
+class lcd_ostream : public std::ostream {
+public:
+    lcd_ostream(TextLCD_Base *lcd);
+    virtual ~lcd_ostream();
+    lcd_ostream& locate(int column, int row);
+    lcd_ostream& cls();
+private:
+    TextLCD_Base *_lcd;
+    lcd_streambuf *lcd_buf;
+};
+inline lcd_ostream& cls(lcd_ostream& s) {s.cls(); return s;}  //manipulator
+
+#endif
\ No newline at end of file