logging lib

This commit is contained in:
Drath
2025-10-03 16:57:38 +02:00
parent 31f2c8bf7c
commit 7e7d8d2aa1
12 changed files with 80 additions and 48 deletions

View File

@@ -1,22 +1,13 @@
#include "LCDDisplay.hpp"
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <cstring>
#include <iostream>
#include <print>
#include <string>
/* lcd size hardcoded to 4x40 idgaf */
LCDDisplay::LCDDisplay(std::string dev, uint32_t baud) {
std::println("[LCDDisplay] Opening LCD at \"{}\"", dev);
log(LOG::INF, "LCDDisplay", "Opening LCD at \"{}\"", dev);
struct termios term;
int lcd = open(dev.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
if (lcd < 0) {
std::println("[LCDDisplay] Error opening serial port \"{}\"", dev); // err
log(LOG::ERR, "LCDDisplay", "Error opening serial port \"{}\"", dev); // err
exit(lcd);
}
@@ -42,7 +33,7 @@ LCDDisplay::LCDDisplay(std::string dev, uint32_t baud) {
LCDDisplay::~LCDDisplay() {
close(_lcd);
std::println("[LCDDisplay] LCD port closed");
log(LOG::INF, "LCDDisplay", "LCD port closed");
}
void LCDDisplay::clear() {
@@ -51,21 +42,21 @@ void LCDDisplay::clear() {
}
void LCDDisplay::setContrast(uint8_t contrast) {
std::println("[LCDDisplay::setContrast] Set contrast to {}", contrast);
log(LOG::INF, "LCDDisplay::setContrast", "Set contrast to {}", contrast);
uint8_t cmdbuf[] = {254, 80, contrast};
write(_lcd, &cmdbuf, 3);
}
void LCDDisplay::setBacklight(bool enabled) {
std::println("[LCDDisplay::setBacklight] Set backlight to {}", enabled);
log(LOG::INF, "LCDDisplay::setBacklight", "Set backlight to {}", enabled);
uint8_t cmdbuf[] = {254, (uint8_t)(enabled ? 66 : 70), 255};
write(_lcd, &cmdbuf, enabled ? 3 : 2);
}
/* still doesnt work? */
void LCDDisplay::setBacklight(uint8_t brightness) {
std::println("[LCDDisplay::setBacklight] Set backlight brightness to {}", brightness);
uint8_t cmdbuf[] = {254, (uint8_t)(brightness ? 66 : 70), 255, brightness}; // 3rd char is timer, 4th is brightness
log(LOG::INF, "LCDDisplay::setBacklight", "Set backlight brightness to {}", brightness);
uint8_t cmdbuf[] = {254, (uint8_t)(brightness ? 66 : 70), 255, brightness}; // 3rd char is timer, 4th is brightness
write(_lcd, &cmdbuf, brightness ? 4 : 2);
}
@@ -95,7 +86,7 @@ void LCDDisplay::writeStr(uint8_t row, uint8_t col, std::string str) {
void LCDDisplay::writeLines(std::array<std::string, 4> lines) {
for (auto& line : lines) {
if (line.size() > LCD_COLS) {
std::println("[LCDDisplay::writeLines] Line {} too long! ({} chars)", line, line.size());
log(LOG::WRN, "LCDDisplay::writeLines", "Line {} too long! ({} chars)", line, line.size());
continue;
}
line.insert(line.end(), LCD_COLS - line.size(), ' ');