From 3015d8f972aa6eec210c4165f050c74049a8cdf7 Mon Sep 17 00:00:00 2001 From: drath Date: Wed, 1 Oct 2025 22:50:32 +0200 Subject: [PATCH] try to move away from hardcoded values, see if i can make it support different displays --- include/LCDDisplay.hpp | 2 +- src/LCDDisplay.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/LCDDisplay.hpp b/include/LCDDisplay.hpp index 2f3a45c..b93973f 100644 --- a/include/LCDDisplay.hpp +++ b/include/LCDDisplay.hpp @@ -9,7 +9,7 @@ class LCDDisplay { private: uint8_t _lcd; - char writebuf[168]; // 4x40 chars + 2x4 setcursor commands + char writebuf[4 * 40 + 8]; // 4x40 chars + 2x4 setcursor commands void writeStr(std::string str); // do not use void writeLines(std::array lines); // do not use diff --git a/src/LCDDisplay.cpp b/src/LCDDisplay.cpp index 6f89200..537d76e 100644 --- a/src/LCDDisplay.cpp +++ b/src/LCDDisplay.cpp @@ -106,12 +106,12 @@ void LCDDisplay::clearBuf() { /* hyper optimized buffer flush command, writes whole disp with a single write */ void LCDDisplay::flushBuf() { // we could skip all of this and set it in constructor if we were extra sure the lines wont ever exceed 40 chars - uint8_t setDisp[] = {254, 71, 1, 1}; // set cursor to char 1, line 1 + constexpr uint8_t setDisp[] = {254, 71, 1, 1}; // set cursor to char 1, line 1 std::memcpy(&writebuf[0], setDisp, 4); std::memcpy(&writebuf[84], setDisp, 4); writebuf[87] = 3; // overwrite set cursor c1 l1 to c1 l3 - write(_lcd, writebuf, 168); + write(_lcd, writebuf, sizeof(writebuf)); } char LCDDisplay::bar(uint8_t char_id, double value) {