From 3da583e7eb45bdf611cb7bdc390240e05fd90af3 Mon Sep 17 00:00:00 2001 From: Drath Date: Thu, 18 Sep 2025 22:19:18 +0200 Subject: [PATCH] lil cleanup --- include/LCDDisplay.hpp | 12 +++++++----- src/LCDDisplay.cpp | 32 ++++++++++++-------------------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/include/LCDDisplay.hpp b/include/LCDDisplay.hpp index 9f83256..e5c85f8 100644 --- a/include/LCDDisplay.hpp +++ b/include/LCDDisplay.hpp @@ -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 lines); // do not use + char linebuf[4][40]; + void writeStr(std::string str); // do not use + void writeLines(std::array 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 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 cchar); + char bar(uint8_t char_id, double value); }; diff --git a/src/LCDDisplay.cpp b/src/LCDDisplay.cpp index c028b63..8ad41b4 100644 --- a/src/LCDDisplay.cpp +++ b/src/LCDDisplay.cpp @@ -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 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 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 b;