yuge overhaul, threads, hass, rewrote display, hwmons, bunc of shit

This commit is contained in:
Drath
2025-09-11 17:56:40 +02:00
parent 3153b1dc1b
commit 7b4791395e
12 changed files with 411 additions and 255 deletions

View File

@@ -4,6 +4,8 @@
#include <termios.h>
#include <unistd.h>
#include <cstring>
#include <iostream>
#include <print>
#include <string>
@@ -27,6 +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
}
LCDDisplay::~LCDDisplay() {
@@ -46,7 +49,7 @@ void LCDDisplay::setContrast(uint8_t contrast) {
}
void LCDDisplay::setBacklight(bool enabled) {
std::println("[LCDDisplay] Set brightness to {}", enabled);
std::println("[LCDDisplay] Set backlight to {}", enabled);
uint8_t cmdbuf[] = {254, (uint8_t)(enabled ? 66 : 70), 255};
write(_lcd, &cmdbuf, enabled ? 3 : 2);
}
@@ -75,6 +78,29 @@ void LCDDisplay::writeLines(std::array<std::string, 4> lines) {
writeStr(lines[2] + lines[3]);
}
/* writes string to line buffer at given pos*/
void LCDDisplay::writeBuf(uint8_t row, uint8_t col, std::string str) {
// size_t max_copy = std::min(str.size(), sizeof(linebuf[row]) - col - 1);
std::memcpy(&linebuf[row][col], str.c_str(), str.size()); // will overflow
}
/* hyper optimized buffer flush command, writes whole disp with a single write */
void LCDDisplay::flushBuffer() {
char writebuf[168]; // 4x40 chars + 2x4 setcursor commands + 1 null terminator
uint8_t setDisp[] = {254, 71, 1}; // skeleton set cursor command
std::memcpy(&writebuf[0], setDisp, 3); // copy template set cursor command
writebuf[3] = 1; // actual set cursor param, set to 1st row
std::memcpy(&writebuf[4], linebuf[0], 40); // copy 1st line
std::memcpy(&writebuf[44], linebuf[1], 40); // copy 2nd line
std::memcpy(&writebuf[84], setDisp, 3); // copy template set cursor command
writebuf[87] = 3; // set cursor to 3rd line
std::memcpy(&writebuf[88], linebuf[2], 40); // copy 3rd line
std::memcpy(&writebuf[128], linebuf[3], 40); // copy 4th line
write(_lcd, writebuf, 168);
}
void LCDDisplay::writeSStream(std::stringstream& ss) {
std::string s = ss.str();
if (s.size() != 160)