lil cleanup
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
class LCDDisplay {
|
||||
private:
|
||||
uint8_t _lcd;
|
||||
char linebuf[4][41]{};
|
||||
void writeStr(std::string str); // do not use
|
||||
void writeLines(std::array<std::string, 4> lines); // do not use
|
||||
char linebuf[4][40];
|
||||
void writeStr(std::string str); // do not use
|
||||
void writeLines(std::array<std::string, 4> lines); // do not use
|
||||
|
||||
public:
|
||||
LCDDisplay(std::string dev, uint32_t baud = 0010002); // from termios-baud.h, B115200
|
||||
@@ -21,14 +21,16 @@ class LCDDisplay {
|
||||
char cc[8] = {'\0', '\1', '\2', '\3', '\4', '\5', '\6', '\7'};
|
||||
|
||||
void clear();
|
||||
|
||||
void setContrast(uint8_t contrast);
|
||||
void setBacklight(bool enabled);
|
||||
void setCursor(uint8_t row, uint8_t col);
|
||||
void setCustomChar(uint8_t index, std::array<uint8_t, 8> cchar);
|
||||
|
||||
void writeBuf(uint8_t row, uint8_t col, std::string str);
|
||||
void clearBuf();
|
||||
void flushBuf();
|
||||
void writeSStream(std::stringstream& ss);
|
||||
void setCustomChar(uint8_t index, std::array<uint8_t, 8> cchar);
|
||||
|
||||
char bar(uint8_t char_id, double value);
|
||||
};
|
||||
|
||||
|
||||
@@ -58,6 +58,17 @@ void LCDDisplay::setCursor(uint8_t row, uint8_t col) {
|
||||
write(_lcd, &cmdbuf, 4);
|
||||
}
|
||||
|
||||
void LCDDisplay::setCustomChar(uint8_t index, std::array<uint8_t, 8> cchar) {
|
||||
uint8_t cmdbuf[11];
|
||||
cmdbuf[0] = 254;
|
||||
cmdbuf[1] = 78;
|
||||
cmdbuf[2] = index;
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
cmdbuf[i + 3] = cchar[i];
|
||||
write(_lcd, &cmdbuf, 11);
|
||||
}
|
||||
|
||||
|
||||
void LCDDisplay::writeStr(std::string str) {
|
||||
write(_lcd, str.c_str(), str.size());
|
||||
}
|
||||
@@ -90,7 +101,7 @@ void LCDDisplay::clearBuf() {
|
||||
/* hyper optimized buffer flush command, writes whole disp with a single write */
|
||||
void LCDDisplay::flushBuf() {
|
||||
uint8_t writebuf[168]; // 4x40 chars + 2x4 setcursor commands
|
||||
uint8_t setDisp[] = {254, 71, 1, 1}; // setr cursor to char 1, line 1
|
||||
uint8_t setDisp[] = {254, 71, 1, 1}; // set cursor to char 1, line 1
|
||||
|
||||
std::memcpy(&writebuf[0], setDisp, 4); // copy set cursor command
|
||||
std::memcpy(&writebuf[4], linebuf[0], 40); // copy 1st line
|
||||
@@ -103,25 +114,6 @@ void LCDDisplay::flushBuf() {
|
||||
write(_lcd, writebuf, 168);
|
||||
}
|
||||
|
||||
void LCDDisplay::writeSStream(std::stringstream& ss) {
|
||||
std::string s = ss.str();
|
||||
if (s.size() != 160)
|
||||
std::println("[LCDDisplay::writeSStream] stringstream wrong ({} chars too short)", 160 - s.size()); // err
|
||||
setCursor(0, 0);
|
||||
writeStr(s.substr(0, 80));
|
||||
setCursor(2, 0);
|
||||
writeStr(s.substr(80, 159));
|
||||
}
|
||||
|
||||
void LCDDisplay::setCustomChar(uint8_t index, std::array<uint8_t, 8> cchar) {
|
||||
uint8_t cmdbuf[11];
|
||||
cmdbuf[0] = 254;
|
||||
cmdbuf[1] = 78;
|
||||
cmdbuf[2] = index;
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
cmdbuf[i + 3] = cchar[i];
|
||||
write(_lcd, &cmdbuf, 11);
|
||||
}
|
||||
|
||||
char LCDDisplay::bar(uint8_t char_id, double value) {
|
||||
std::array<uint8_t, 8> b;
|
||||
|
||||
Reference in New Issue
Block a user