move from iostream to print

This commit is contained in:
Drath
2025-07-27 01:16:56 +02:00
parent 3008ab4d06
commit b0fef327e1

View File

@@ -8,7 +8,8 @@
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
// #include <iostream>
#include <print>
#include <sstream>
#include <string>
#include <thread>
@@ -17,8 +18,8 @@
#include "include/gpu.hpp"
#include "include/utils.hpp"
#define LCD_PORT "/dev/serial/by-id/usb-Raspberry_Pi_Pico_E6616407E37AA12F-if00" // tis a symlink, can also be just /dev/ttyACM0
#define LCD_INTERVAL_MS 500
#define LCD_PORT "/dev/serial/by-id/usb-Raspberry_Pi_Pico_E6616407E37AA12F-if00" // tis a symlink, can also be just /dev/ttyACM0
#define LCD_INTERVAL_MS 1000
#define LCD_CONTRAST 215
#define FILL_CHAR ' '
#define N_CPU 16
@@ -39,12 +40,11 @@ std::string pNum(auto num, uint8_t decs = 0) {
return ret.str();
}
// converts large number in (k)bytes to human readable numer with suffix and sane decimal
std::string pBytes(double bytes, bool isKbytes = false) {
std::array suffix_list = {'K', 'M', 'G', 'T', 'P', 'E', 'Z'};
for (auto &suffix : suffix_list) {
if (suffix == 'K' && isKbytes) continue; // skip first loop if already in Kbytes
if (suffix == 'K' && isKbytes) continue; // skip first loop if already in Kbytes
bytes /= 1024.0;
if (bytes < 1024) {
uint8_t decs = 2;
@@ -75,7 +75,7 @@ std::string getAvgs() {
getloadavg(avgs, 3);
for (uint8_t i = 0; i < 3; i++)
ret += pNum(avgs[i], avgs[i] > 10 ? 1 : 2) + " ";
ret.pop_back(); // remove trailing space
ret.pop_back(); // remove trailing space
return ret;
}
@@ -147,7 +147,7 @@ auto getCpuTemp(std::string hw) {
}
// lots of reads but still faster than reading /proc/cpuinfo
for(uint8_t i = 0; i < N_CPU; i++)
for (uint8_t i = 0; i < N_CPU; i++)
cpu.avg_freq += (long)(std::stol(readFile("/sys/devices/system/cpu/cpu" + std::to_string(i) + "/cpufreq/cpuinfo_avg_freq", 3)));
cpu.avg_freq /= N_CPU;
@@ -156,7 +156,7 @@ auto getCpuTemp(std::string hw) {
void sighandler(int s) {
daemon_mode = false;
std::cout << "[Signal] deamon_mode = false, exiting on next loop" << std::endl;
std::println("[Signal] deamon_mode = false, exiting on next loop");
}
int main(int argc, char *argv[]) {
@@ -171,7 +171,7 @@ int main(int argc, char *argv[]) {
/* find correct cpu module */
auto cpu_hwmon = findHwmonPath("k10temp");
if (cpu_hwmon.size() == 0) {
std::cout << "[Hwmon] k10temp not found, trying zenpower" << std::endl;
std::println("[Hwmon] k10temp not found, trying zenpower");
cpu_hwmon = findHwmonPath("zenpower");
}
@@ -189,7 +189,7 @@ int main(int argc, char *argv[]) {
std::chrono::milliseconds interval(LCD_INTERVAL_MS);
auto start = std::chrono::steady_clock::now();
if (daemon_mode) {
std::cout << "[Chrono] Running in daemon mode, " << LCD_INTERVAL_MS << "ms interval" << std::endl;
std::println("[Chrono] Running in daemon mode, {} ms interval", LCD_INTERVAL_MS);
lcd.setContrast(LCD_CONTRAST);
lcd.setBacklight(true);
}
@@ -229,7 +229,7 @@ int main(int argc, char *argv[]) {
std::this_thread::sleep_until(start + interval);
start += interval;
} else {
std::cout << "[Chrono] took " << std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start).count() / 1000.0 << "ms" << std::endl;
std::println("[Chrono] took {}ms", std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start).count() / 1000.0);
return 0;
}
}