init
Dependencies: mbed C12832 EthernetInterface MQTT mbed-rtos picojson
LCD.cpp
00001 /* 00002 * Marc Le Labourier 00003 * 16/02/2016 00004 */ 00005 00006 #include "LCD.h" 00007 00008 LCD::LCD() : _host(D11, D13, D12, D7, D10) 00009 { 00010 _line = 0; 00011 _pos = 0; 00012 _it = _buffer.begin(); 00013 } 00014 00015 LCD::~LCD() 00016 { 00017 _buffer.clear(); 00018 } 00019 00020 C12832& LCD::Host() 00021 { 00022 return _host; 00023 } 00024 00025 /* Clear process: 00026 * The screen buffer is full... 00027 * We need to extract one line and to redisplay the content from the start of the buffer. 00028 * If we do not wait during the process, the screen will not be readable. 00029 * The wait_ms is responsible of the 'scrolling effect'. 00030 */ 00031 void LCD::clear() 00032 { 00033 wait_ms(1000); 00034 if (_buffer.size() > SCREEN_SIZE) 00035 _buffer.pop_front(); 00036 _host.cls(); 00037 } 00038 00039 /* Push a string to be rendered on the LCD screen: 00040 * Long string are split in many other and added to the buffer. 00041 */ 00042 void LCD::print(const std::string& s) 00043 { 00044 if (s.size() > SCREEN_CHAR) 00045 { 00046 for (size_t i = 0; i < s.size(); i += SCREEN_CHAR) 00047 { 00048 std::string tmp = s.substr(i, SCREEN_CHAR); 00049 _buffer.push_back(tmp); 00050 } 00051 } 00052 else 00053 _buffer.push_back(s); 00054 printAll(); 00055 } 00056 00057 /* Update the screen process 00058 * Update the screen with the new input from the print() method. 00059 * All the magic is done here. 00060 */ 00061 void LCD::printAll() 00062 { 00063 if (_it == _buffer.end()) 00064 { 00065 _it = _buffer.begin(); 00066 for (int i = 0; i < _line; ++i) 00067 ++_it; 00068 } 00069 for (; _it != _buffer.end(); ++_it) 00070 { 00071 if (_line > SCREEN_SIZE) 00072 { 00073 _line = 0; 00074 _pos = 0; 00075 clear(); 00076 _it = _buffer.begin(); 00077 } 00078 std::string s = *_it; 00079 printOne(s, _pos); 00080 _pos += SCREEN_PADDING; 00081 ++_line; 00082 } 00083 } 00084 00085 /* Render a string on the screen */ 00086 void LCD::printOne(const std::string& s, int index) 00087 { 00088 _host.locate(0, index); 00089 _host.printf("%s", s.c_str()); 00090 }
Generated on Tue Jul 26 2022 08:32:45 by 1.7.2