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,11 +1,8 @@
// #include <array>
#include <chrono>
#include <csignal>
// #include <cstdint> // this is incorrect, we need to either use stdint.h, use std::uint8_t or put using std::uint_8
#include <functional>
#include <mutex>
#include <print>
#include <semaphore>
#include <stop_token>
#include <string>
@@ -16,6 +13,7 @@
#include <cpu.hpp>
#include <gpu.hpp>
#include <hass.hpp>
#include <log.hpp>
#include <sys.hpp>
#include <utils.hpp>
@@ -42,13 +40,12 @@ struct Sensors {
};
void sighandler(int s) { // can i remove int s
std::println("[Signal] got SIGINT/SIGTERM, exiting...");
log(LOG::WRN, "Signal", "got SIGINT/SIGTERM, exiting...");
sem::main.release();
sem::display.release();
}
void hassThread(std::stop_token st, Sensors* s) {
// std::println("[Thread] Starting hass_thread, pid {}", gettid());
HomeAssistant pc_power("home.drath.win", "sensor.gniazdko_komputer_moc");
pc_power.connect();
@@ -64,7 +61,7 @@ void hassThread(std::stop_token st, Sensors* s) {
}
void sensorsThread(std::stop_token st, Sensors* s) {
std::println("[Thread] Starting sensors_thread, pid {}, poll interval {} ms", gettid(), LCD_INTERVAL_MS);
log(LOG::INF, "Thread", "Starting sensors_thread, pid {}, poll interval {} ms", gettid(), LCD_INTERVAL_MS);
cpu::detectHwmon(&s->cpu, "0000:00:18.3");
gpu::detectHwmon(&s->gpu, "0000:0a:00.0");
@@ -89,7 +86,7 @@ void sensorsThread(std::stop_token st, Sensors* s) {
}
void displayThread(std::stop_token st, Sensors* s) {
std::println("[Thread] Starting display_thread, pid {}", gettid());
log(LOG::INF, "Thread", "Starting display_thread, pid {}", gettid());
LCDDisplay lcd(LCD_PORT);
lcd.setContrast(LCD_CONTRAST);
@@ -144,7 +141,7 @@ int main(int argc, char* argv[]) {
std::signal(SIGTERM, sighandler);
Sensors* pSensors = new Sensors;
std::println("[main] size of sensor struct is {} bytes", sizeof(Sensors));
log(LOG::DBG, "main", "size of sensor struct is {} bytes", sizeof(Sensors));
std::function<void(std::stop_token st, Sensors * s)> funcs[] = {displayThread, hassThread, sensorsThread}; // array of functions