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)

Revision:
1:e46139d4b8ba
Parent:
0:4ba062d3d524
Child:
2:eaa44bec9b96
--- a/TextLCD_ostream.h	Sat Jun 18 08:57:07 2016 +0000
+++ b/TextLCD_ostream.h	Sat Jun 18 14:20:29 2016 +0000
@@ -3,27 +3,49 @@
 
 #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 );
+    lcd_streambuf() : lcd(NULL) {}
+    lcd_streambuf(TextLCD_Base *p) : lcd(p) {}
+    void setlcd(TextLCD_Base *p) {lcd=p;}
+    TextLCD_Base *getlcd() {return lcd;}
+
+    virtual int_type overflow( int_type c = EOF );
 private:
-    TextLCD_Base *_lcd;
+    TextLCD_Base *lcd;
 };
 
+/** ostream rapper for TextLCD
+@code
+#include "mbed.h"
+#include "TextLCD_ostream.h"
+ 
+I2C i2c(p28,p27); // SDA, SCL
+TextLCD_I2C_N lcd(&i2c, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3);
+lcd_ostream lcdstream(&lcd);
+
+int main() {
+    using namespace std;
+    lcd.setContrast(32);
+    lcdstream.cls() << "Hello world" << endl << "LCD ostream";
+}
+@endcode
+ */
 class lcd_ostream : public std::ostream {
 public:
-    lcd_ostream(TextLCD_Base *lcd);
-    virtual ~lcd_ostream();
+    /// @param p pointer to object of TextLCD_Base and derived from it
+    lcd_ostream(TextLCD_Base *p);
+    /// set cursor position.
+    /// same as TextLCD::locate(), except return value type
     lcd_ostream& locate(int column, int row);
+    /// clear screen
+    /// same as TextLCD::cls(), except return value type
     lcd_ostream& cls();
+protected:
+    TextLCD_Base *lcd;
 private:
-    TextLCD_Base *_lcd;
-    lcd_streambuf *lcd_buf;
+    lcd_streambuf lcd_buf;
 };
-inline lcd_ostream& cls(lcd_ostream& s) {s.cls(); return s;}  //manipulator
-
 #endif
\ No newline at end of file