Files
linuxSmartie/include/app.hpp
2026-01-03 01:55:40 +01:00

64 lines
1.6 KiB
C++

#ifndef APP_HPP
#define APP_HPP
#include <atomic>
#include <cpu.hpp>
#include <gpu.hpp>
#include <mutex>
#include <semaphore>
#include <stop_token>
#include <sys.hpp>
#include <vector>
#include <thread>
class Application {
public:
struct Config {
uint16_t lcd_interval_ms = 500;
uint8_t lcd_contrast = 215;
std::string lcd_port;
std::string cpu_pciaddr = "0000:00:18.3";
std::string gpu_pciaddr = "0000:0b:00.0";
std::string sys_sensor = "nct6775.656";
std::string sys_ifname = "enp4s0f0";
std::string home_dir = "/home/drath";
};
explicit Application(const Config& config);
~Application();
void Run();
private:
struct Sensors {
sys::TimeDate td;
double avg[3] = {0.0f};
sys::Memory ram;
sys::Disk home;
sys::Network net;
sys::sysSensors sys;
cpu::cpuSensors cpu;
gpu::gpuSensors gpu;
double hass_state = 0.0f;
std::mutex mtx; // making sure the struct isnt accessed by multiple threads at once
};
struct Control {
std::binary_semaphore display{0};
std::binary_semaphore main{0};
std::atomic_bool quit{false};
std::stop_source stop;
};
Config m_config; // m_ is member variable
Control m_control;
static Application* s_instance;
static void signalHandler(int);
static void hassThread(const std::stop_token& st, Sensors& s);
void sensorsThread(const std::stop_token& st, Sensors& s);
void displayThread(const std::stop_token& st, Sensors& s);
};
#endif