diff --git a/include/sys.hpp b/include/sys.hpp index f718b6b..f10c46b 100644 --- a/include/sys.hpp +++ b/include/sys.hpp @@ -21,6 +21,11 @@ struct Memory { uint64_t total = 0; }; +struct Disk { + std::string mountpoint; + Memory usage; +}; + struct TimeDate { std::string time; std::string date; @@ -32,7 +37,7 @@ struct Network { }; void getTimeDate(TimeDate* td); -void getDisk(Memory* disk, std::string mount); +void getDisk(Disk* disk); void getRam(Memory* mem); void getNetwork(Network* net, std::string device); void detectHwmon(sysSensors* s, std::string platform); diff --git a/main.cpp b/main.cpp index 981aa2b..157f3a2 100644 --- a/main.cpp +++ b/main.cpp @@ -32,7 +32,7 @@ struct Sensors { sys::TimeDate td; double avg[3] = {0.0f}; sys::Memory ram; - sys::Memory home; + sys::Disk home; // sys::Network net; sys::sysSensors sys; cpu::cpuSensors cpu; @@ -68,6 +68,7 @@ void sensorsThread(std::stop_token st, Sensors* s) { cpu::detectHwmon(&s->cpu, "0000:00:18.3"); gpu::detectHwmon(&s->gpu, "0000:0b:00.0"); sys::detectHwmon(&s->sys, "nct6775.656"); + s->home.mountpoint = "/home/drath"; while (!st.stop_requested()) { auto start = std::chrono::steady_clock::now(); @@ -77,7 +78,7 @@ void sensorsThread(std::stop_token st, Sensors* s) { sys::getTimeDate(&s->td); getloadavg(s->avg, 3); sys::getRam(&s->ram); - sys::getDisk(&s->home, "/home/drath"); + sys::getDisk(&s->home); // sys::getNetwork(&s->net, "enp4s0f0"); sys::updateSensors(&s->sys); cpu::update(&s->cpu); @@ -145,7 +146,7 @@ void displayThread(std::stop_token st, Sensors* s) { lcd.writeBuf(3, 0, pad(pNum(s->cpu.vcore, 2) + "V", 7, true)); lcd.writeBuf(3, 6, std::to_string(s->cpu.avg_freq) + "MHz"); - lcd.writeBuf(3, 14, lcd.cc(2) + pad(pBytes(s->home.free), 5)); + lcd.writeBuf(3, 14, lcd.cc(2) + pad(pBytes(s->home.usage.free), 5)); lcd.writeBuf(3, 21, pad(std::to_string(s->gpu.clock_core) + "/" + std::to_string(s->gpu.clock_mem) + "MHz ", 13)); lcd.writeBuf(3, 34, pad(pNum(s->gpu.vcore, 3) + "V", 5)); } diff --git a/src/sys.cpp b/src/sys.cpp index 227ca13..d1b6650 100644 --- a/src/sys.cpp +++ b/src/sys.cpp @@ -22,12 +22,12 @@ void sys::getRam(Memory* mem) { mem->used = mem->total - mem->free; } -void sys::getDisk(Memory* disk, std::string mount) { +void sys::getDisk(Disk* disk) { struct statvfs diskData; - statvfs(mount.c_str(), &diskData); - disk->free = diskData.f_bfree * diskData.f_frsize; - disk->used = (diskData.f_blocks - diskData.f_bfree) * diskData.f_frsize; - disk->total = diskData.f_blocks * diskData.f_frsize; + statvfs(disk->mountpoint.c_str(), &diskData); + disk->usage.free = diskData.f_bfree * diskData.f_frsize; + disk->usage.used = (diskData.f_blocks - diskData.f_bfree) * diskData.f_frsize; + disk->usage.total = diskData.f_blocks * diskData.f_frsize; } void sys::getNetwork(Network* net, std::string device) { @@ -56,6 +56,5 @@ void sys::detectHwmon(sysSensors* s, std::string platform) { void sys::updateSensors(sysSensors* s) { s->fan_speed[0] = std::stol(readFile(s->hwmon + "/fan2_input", 4)); s->fan_speed[1] = std::stol(readFile(s->hwmon + "/fan7_input", 4)); - ; s->t_sensor = std::stol(readFile(s->hwmon + "/temp5_input", 2)); }