move from iostream to print

This commit is contained in:
Drath
2025-07-27 01:16:23 +02:00
parent ada9d22713
commit 3008ab4d06
3 changed files with 16 additions and 18 deletions

View File

@@ -4,18 +4,18 @@
#include <termios.h>
#include <unistd.h>
#include <iostream>
#include <print>
#include <string>
/* lcd size hardcoded to 4x40 idgaf */
LCDDisplay::LCDDisplay(std::string dev, uint32_t baud) {
std::cout << "[LCDDisplay] Opening LCD at " << dev << std::endl;
std::println("[LCDDisplay] Opening LCD at {}", dev);
struct termios term;
int lcd = open(dev.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
// handle errors
if (lcd < 0) {
std::cerr << "[LCDDisplay] Error opening serial port " << dev << std::endl;
std::println("[LCDDisplay] Error opening serial port {}", dev); // err
exit(lcd);
}
@@ -30,7 +30,7 @@ LCDDisplay::LCDDisplay(std::string dev, uint32_t baud) {
}
LCDDisplay::~LCDDisplay() {
std::cout << "[LCDDisplay] Closing LCD port" << std::endl;
std::println("[LCDDisplay] Closing LCD port");
close(_lcd);
}
@@ -40,13 +40,13 @@ void LCDDisplay::clear() {
}
void LCDDisplay::setContrast(uint8_t contrast) {
std::cout << "[LCDDisplay] Set contrast to " << std::to_string(contrast) << std::endl;
std::println("[LCDDisplay] Set contrast to {}", contrast);
uint8_t cmdbuf[] = {254, 80, contrast};
write(_lcd, &cmdbuf, 3);
}
void LCDDisplay::setBacklight(bool enabled) {
std::cout << "[LCDDisplay] Backlight set to " << std::to_string(enabled) << std::endl;
std::println("[LCDDisplay] Set brightness to {}", enabled);
uint8_t cmdbuf[] = {254, (uint8_t)(enabled ? 66 : 70), 255};
write(_lcd, &cmdbuf, enabled ? 3 : 2);
}
@@ -63,7 +63,7 @@ void LCDDisplay::writeStr(std::string str) {
void LCDDisplay::writeLines(std::array<std::string, 4> lines) {
for (auto& line : lines) {
if (line.size() > 40) {
std::cerr << "Line " << line << " too long! (" << line.size() << " chars)" << std::endl;
std::println("Line {} too long! ({} chars)", line, line.size());
continue;
}
line.insert(line.end(), 40 - line.size(), ' ');
@@ -78,14 +78,13 @@ void LCDDisplay::writeLines(std::array<std::string, 4> lines) {
void LCDDisplay::writeSStream(std::stringstream& ss) {
std::string s = ss.str();
if (s.size() != 160)
std::cerr << "[LCDDisplay] stringstream wrong (" + std::to_string((int)(160 - s.size())) + " chars too short)" << std::endl;
std::println("[LCDDisplay] 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;
@@ -99,7 +98,7 @@ void LCDDisplay::setCustomChar(uint8_t index, std::array<uint8_t, 8> cchar) {
char LCDDisplay::bar(uint8_t char_id, double value) {
std::array<uint8_t, 8> b;
b.fill(0b01110);
for(uint8_t i = 0; i < (1.0 - value) * 8; i++)
for (uint8_t i = 0; i < (1.0 - value) * 8; i++)
b[i] = 0;
setCustomChar(char_id, b);
return cc[char_id];