Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ACM1602NI TextLCD
Dependents: TextLCD_ostream_sample
TextLCD_ostream.h
- Committer:
- jk1lot
- Date:
- 2016-06-22
- Revision:
- 3:183bcab4951b
- Parent:
- 2:eaa44bec9b96
- Child:
- 4:3a1291526e04
File content as of revision 3:183bcab4951b:
#ifndef TEXTLCD_OSTREAM_H #define TEXTLCD_OSTREAM_H #include "TextLCD.h" #include<iostream> #include <streambuf> class lcd_streambuf : public std::streambuf { public: lcd_streambuf(TextLCD_Base *p) : lcd(p) {} TextLCD_Base *getlcd() {return lcd;} virtual int_type overflow( int_type c = EOF ); private: TextLCD_Base *lcd; }; /** ostream wrapper 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: /// @param p pointer to object of TextLCD_Base and derived from it lcd_ostream(TextLCD_Base *p) : std::ostream(&lcd_buf),lcd(p),lcd_buf(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: lcd_streambuf lcd_buf; }; #endif