67 lines
1.5 KiB
C++
67 lines
1.5 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 <thread>
|
|
|
|
class Application {
|
|
public:
|
|
struct Config {
|
|
struct Lcd {
|
|
uint16_t refresh_interval_ms;
|
|
uint8_t contrast;
|
|
std::string port;
|
|
};
|
|
struct HomeAssistant {
|
|
std::string url;
|
|
std::string entity;
|
|
std::string token;
|
|
};
|
|
Lcd lcd;
|
|
HomeAssistant hass;
|
|
std::string cpu_pciaddr;
|
|
std::string gpu_pciaddr;
|
|
std::string sys_sensor;
|
|
std::string sys_ifname;
|
|
std::string home_dir;
|
|
};
|
|
|
|
explicit Application(Config config);
|
|
~Application();
|
|
void Run();
|
|
|
|
private:
|
|
struct Sensors {
|
|
sys::TimeDate td;
|
|
double loadavg[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;
|
|
};
|
|
|
|
struct Control {
|
|
std::binary_semaphore display{0};
|
|
std::mutex sensors; // making sure the sensors struct isnt accessed by multiple threads at once
|
|
sigset_t sigset;
|
|
};
|
|
|
|
Config m_config{}; // m_ is prefix for member variable
|
|
Control m_control{};
|
|
Sensors m_sensors{};
|
|
|
|
void hassThread(const std::stop_token& st);
|
|
void sensorsThread(const std::stop_token& st);
|
|
void displayThread(const std::stop_token& st);
|
|
};
|
|
|
|
#endif |