make it a class
This commit is contained in:
@@ -1,14 +1,36 @@
|
||||
#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};
|
||||
@@ -22,29 +44,21 @@ class Application {
|
||||
std::mutex mtx; // making sure the struct isnt accessed by multiple threads at once
|
||||
};
|
||||
|
||||
struct Semaphores {
|
||||
inline static std::binary_semaphore display{0};
|
||||
inline static std::binary_semaphore main{0};
|
||||
struct Control {
|
||||
std::binary_semaphore display{0};
|
||||
std::binary_semaphore main{0};
|
||||
std::atomic_bool quit{false};
|
||||
std::stop_source stop;
|
||||
};
|
||||
|
||||
std::string lcd_port;
|
||||
uint16_t lcd_interval_ms = 500;
|
||||
uint8_t lcd_contrast = 215;
|
||||
|
||||
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";
|
||||
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);
|
||||
static void sensorsThread(const std::stop_token& st, Sensors& s);
|
||||
static void displayThread(const std::stop_token& st, Sensors& s);
|
||||
|
||||
public:
|
||||
explicit Application(const std::string& display_port);
|
||||
void Run();
|
||||
void sensorsThread(const std::stop_token& st, Sensors& s);
|
||||
void displayThread(const std::stop_token& st, Sensors& s);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user