lil cleanup

This commit is contained in:
Drath
2025-09-18 22:19:18 +02:00
parent 275bf721e4
commit 3da583e7eb
2 changed files with 19 additions and 25 deletions

View File

@@ -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;