From b1ea1f2c99501fe0a837abf13bc82263a848f2ce Mon Sep 17 00:00:00 2001 From: Drath Date: Fri, 12 Sep 2025 23:36:35 +0200 Subject: [PATCH] refactor a little, add function for clearing buffer --- include/LCDDisplay.hpp | 3 ++- src/LCDDisplay.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/LCDDisplay.hpp b/include/LCDDisplay.hpp index 2a3a08a..9f83256 100644 --- a/include/LCDDisplay.hpp +++ b/include/LCDDisplay.hpp @@ -25,7 +25,8 @@ class LCDDisplay { void setBacklight(bool enabled); void setCursor(uint8_t row, uint8_t col); void writeBuf(uint8_t row, uint8_t col, std::string str); - void flushBuffer(); + 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 86db08b..f91b755 100644 --- a/src/LCDDisplay.cpp +++ b/src/LCDDisplay.cpp @@ -29,7 +29,7 @@ LCDDisplay::LCDDisplay(std::string dev, uint32_t baud) { tcflush(lcd, TCIFLUSH); tcsetattr(lcd, TCSANOW, &term); _lcd = lcd; - std::memset(linebuf, ' ', sizeof(linebuf)); // init linebuf to spaces + clearBuf(); // init linebuf to spaces } LCDDisplay::~LCDDisplay() { @@ -84,8 +84,12 @@ void LCDDisplay::writeBuf(uint8_t row, uint8_t col, std::string str) { std::memcpy(&linebuf[row][col], str.c_str(), len); // will overflow } +void LCDDisplay::clearBuf() { + std::memset(linebuf, ' ', sizeof(linebuf)); +} + /* hyper optimized buffer flush command, writes whole disp with a single write */ -void LCDDisplay::flushBuffer() { +void LCDDisplay::flushBuf() { char writebuf[168]; // 4x40 chars + 2x4 setcursor commands uint8_t setDisp[] = {254, 71, 1}; // skeleton set cursor command